1_Module 5 (2)
1_Module 5 (2)
MODULE 5
SYLLABUS
Macro Preprocessor:
Macro Instruction Definition and Expansion, One pass Macro processor Algorithm and data
structures, Machine Independent Macro Processor Features, Macro processor design options
Device drivers:
Anatomy of a device driver, Character and block device drivers, General design of devicedrivers
Text Editors:
Overview of Editing, User Interface, Editor Structure
Debuggers:
Debugging Functions and Capabilities, Relationship with other parts of the system,Debugging
Methods- By Induction, Deduction and Backtracking.
Macro
• A macro (or macro instruction)
– It is simply a notational convenience for the programmer.
– It allows the programmer to write shorthand version of a program
– It represents a commonly used group of statements in the source program.
• For example:
• Suppose a program needs to add two numbers frequently. This requires a sequence
of instructions. We can define and use a macro called SUM, to represent this
sequence of instructions.
Macro Preprocessor
• The macro pre-processor(or macro processor) is a system software which replaces each
macro instruction with the corresponding group of source language statements. This
operation is called expanding the macro.
• It does not concern the meaning of the involved statements during macro expansion.
• The design of a macro processor generally is machine independent.
The fundamental functions common to all macro processors are: ( Code to remember - DIE )
o Macro Definition
o Macro Invocation
o Macro Expansion
Macro Definition
• Macro definitions are typically located at the start of a program.
• A macro definition is enclosed between a macro header statement(MACRO) and a
macro end statement(MEND)
• Format of macro definition
macroname MACRO parameters
:
body
:
MEND
where macroname indicates the name of macro, MACRO indicates the beginning of
macro definition and parameters indicates the list of formal parameters. parameters is
of the form ¶meter1, ¶meter2,…Each parameter begins with ‘&’. Whenever
we use the term macro prototype it simply means the macro name along with its
parameters.
• Body of macro consist of statements that will generated as the expansion of macro.
• Consider the following macro definition:
SUM MACRO &X,&Y
LDA &X
MOV B
LDA &Y
ADD B
MEND
Here, the macro named SUM is used to find the sum of two variables passed to it.
Macro Expansion
• Each macro invocation statement will be expanded into the statements that form the
body of the macro.
• Arguments from the macro invocation are substituted for the parameters in the macro
prototype.
• The arguments and parameters are associated with one another according to their
positions. The first argument in the macro invocation corresponds to the first parameter
in the macro prototype, etc.
• Comment lines within the macro body have been deleted, but comments on individual
statements have been retained. Macro invocation statement itself has been included as
a comment line.
• Consider the example for macro expansion on next page:
T
CST305 System Software Module 5
In this example, the macro named SUM is defined at the start of the program. This
macro is invoked with the macro call SUM P,Q and the macro is expanded as
LDA &P
MOV B
LDA &Q
ADD B
MEND
Again the same macro is invoked with the macro call SUM M,N and the macro is expanded
as
LDA &M
MOV B
LDA &N
ADD B
MEND
Figure: Example for macro expansion
statements of the subroutine appear only once, regardless of how many times the
subroutine is called.
MOV B
LDA &Y
ADD B
MEND
START
LDA 4500
ADD B
SUM P,Q
LDA 3000
………….
END
• When the macro definition for SUM is encountered, the macro name SUM along with
its parameters X and Y are entered into DEFTAB. Then the statements in the body of
macro is also entered into DEFTAB. The positional notation is used for the parameters.
The parameter &X has been converted to ?1, &Y has been converted to
?2.
• The macro name SUM is entered into NAMTAB and the beginning and end pointers
are also marked.
• On processing the input code, opcode in each statement is compared with the
NAMTAB, to check whether it is a macro call. When the macro call SUM P,Q is
recognized, the arguments P and Q will entered into ARGTAB. The macro is expanded
by taking the statements from DEFTAB using the beginning and end pointers of
NAMTAB.
• When the ?n notation is recognized in a line from DEFTAB, the corresponding
argument is taken from ARGTAB.
Explanation of algorithm
• The algorithm uses 5 procedures
o MACROPROCESSOR (main function)
o DEFINE
o EXPAND
o PROCESSLINE
o GETLINE
PROCESSLINE
• This procedure checks
o If the opcode of current statement is present in NAMTAB. If so it is a macro
invocation statement and calls the procedure EXPAND
o Else if opcode =MACRO, then it indicates the beginning of a macro definition
and calls the procedure DEFINE
o Else it is identified as a normal statement(not a macro definition or macro
call) and write it to the output file.
DEFINE
• The control will reach in this procedure if and only if it is identified as a macro
definition statement.Then:
o Macro name is entered into NAMTAB
o Then the macro name along with its parameters are entered into DEFTAB.
o The statements in body of macro is also enterd into DEFTAB. References to
the macro instruction parameters are converted to a positional notation for
efficiency in substituting arguments.
o Comment lines from macro definition are not entered into DEFTAB because
they will not be a part of macro expansion.
o Store in NAMTAB the pointers to beginning and end of definition in DEFTAB.
• To deal with Nested macro definitions DEFINE procedure maintains a counter named
LEVEL.
o When the assembler directive MACRO is read, the value of LEVEL is
incremented by 1
o When MEND directive is read, the value of LEVEL is decremented by 1
o That is, whenever a new macro definition is encountered within the current
definition, the value of LEVEL will be incremented and the while loop which
is used to process the macro definition will terminate only after the value of
LEVEL =0. With this we can ensure the nested macro definitions are properly
handled.
EXPAND
• The control will reach in this procedure if and only if it is identified as a macro call.
T
CST305 System Software Module 5
• In this procedure, the variable EXPANDING is set to true. It actually indicates the
GETLINE procedure that it is going to expand the macro call. So that GETLINE
procedure will read the next line from DEFTAB instead of reading from input file.
• The arguments of macro call are entered into ARGTAB.
• The macro call is expanded with the lines from the DEFTAB. When the ?n notation is
recognized in a line from DEFTAB, the corresponding argument is taken from
ARGTAB.
GETLINE
• This procedure is used to get the next line.
• If EXPANDING = TRUE, the next line is fetched from DEFTAB. (It means we are
expanding the macro call)
• If EXPANDING = False, the next line is read from input file.
• For example, suppose that the parameter to such a macro instruction is named &ID.
The body of the macro definition contain a statement like LDA X&ID1, which means
&ID is concatenated after the string “X” and before the string “1”
TOTAL MACRO &ID
LDA X&ID1
ADD X&ID2
STA X&ID3
MEND
• Ambiguity Problem: In the statement LDA X&ID1, & is the starting character of
the macro parameter; but the end of the parameter is not marked.
• So X&ID1 may mean
X + &ID + 1 or X +&ID1
• Most of the macro processors deal with this problem by providing a special
concatenation operator to specify the end of parameter.
• Thus LDA X&ID1 can be rewritten as . So that end of the parameter
&ID is clearly defined.
• Example:
• The example given above shows a macro definition that uses the concatenationoperator
as previously described. The statement TOTAL A and TOTAL BETA shows the
invocation statements and the corresponding macro expansion.
• The macroprocessor deletes all occurrences of the concatenation operator immediately
after performing parameter substitution, so the symbol will not
appear in the macro expansion.
• To avoid this we can use the technique of generating unique labels for every macro
invocation and expansion.
• During macro expansion each $ will be replaced with $XX, where XX is a two
character alphanumeric counter of the number of macro instructions expansion.
• For the first macro expansion in a program, XX will have the value AA. For succeeding
macro expansions XX will be set to AB,AC etc. This allows 1296 macro expansions in
a single program
• Consider the following program:
SAMPLE START 0
COPY MACRO &A,&B
LDA &A
.........
$LOOP ADD &B
..........
JLE $LOOP
STA &B
MEND
.............
COPY X,Y
LDA M
COPY P,Q
...........
END
LDA M
LDA &P
.........
$ABLOOP ADD &P
.......... Expansion of COPY P,Q
JLE $ABLOOP
STA &Q
...........
END
In the example, for the first invocation of COPY X,Y the label generated is $AALOOP and for
the second invocation COPY P,Q the label generated is $ABLOOP. Thus for eachinvocation
of macro unique label is generated.
EVAL 2 ,3 ,4
STA Q
...............
END
After expansion the above code becomes:
COPY START 0
STA P
...................
LDA 3
ADD 4
STA Q
.........................
END
a) Positional Parameters
• Parameters and arguments are associated according to their positions in the macro
prototype and invocation. The programmer must specify the arguments in proper
order.
• Syntax : In macro definition,
macroname MACRO ¶meter1, ¶meter2,……
In macro invocation,
macroname argument1, argument2,….
Example: In macro definition,
EVAL MACRO &X, &Y
In macro invocation,
EVAL P,Q
Here &X recieves the value of P and &Y recieves the value of Q
• If an argument is to be omitted, a null argument should be used to maintain the
proper order in macro invocation statement.
• For example: Suppose a macro named EVAL has 5 possible parameters, but in a
particular invocation of the macro only the 1st and 4th parameters are to be specified.
Then the macro call will be EVAL P,,,S,
T
CST305 System Software Module 5
• This specification overrides the default value of the parameter for the duration of that
macro call.
• Consider the example:
Here the default value R is
specified for the parameter Z
INCR MACRO &X=, &Y=, &Z=R
MOV &Z, &X
ADD &Z, &Y
MOV &Z, &X
MEND
• Then the macro call INCR X=A, Y=B will take the values A for parameter X, B for
parameter Y and R for the parameter Z.
• The macro call INCR X=A, Y=B, Z=C will take the values A for parameter X, B for
parameter Y and C for the parameter Z.
Here the macro named INPUT is calling another macro named SUM. This is called as
recursive macro.
• The macro processor design algorithm discussed previously cannot handle recursive
macro invocation and expansion.
• Reasons are:
o The procedure EXPAND would be called recursively, thus the invocation arguments
in the ARGTAB will be overwritten.
o The Boolean variable EXPANDING would be set to FALSE when the “inner”
macro expansion is finished, that is, the macro process would forget that it had been
in the middle of expanding an “outer” macro.
o A similar problem would occur with PROCESSLINE since this procedure too would
be called recursively.
• Solutions:
o Write the macro processor in a programming language that allows recursive calls, thus
local variables will be retained.
o If we are writing in a language without recursion support, use a stack to take care of
pushing and popping local variables and return addresses. So the recursive calls can
be handled.
• The general purpose macro processor do not dependent on any particular programming
language, but can be used with a variety of different languages.
• Example for a general purpose macro processor is ELENA Macro processor
Advantages
• Programmers do not need to learn many macro languages, so much of the time and
expense involved in training are eliminated.
• Although its development costs are somewhat greater than those for a specific language
macro processor, this expense does not need to be repeated for each language, thus save
substantial overall cost.
Disadvantages
In spite of the advantages noted, there are still relatively few general purpose macro
processors. The reasons are:
• Large number of details must be dealt with in a real programming language.
• There are several situations in which normal macro parameter substitution or normal
macro expansion should not occur.
o For example, comments are usually ignored by the macro processor. But each
programming languages uses its own method for specifying comments. So a
general purpose macro processor should be designed with the capability for
identifying the comments in any programming languages.
• Another problem is with the facilities for grouping together terms, expressions, or
statements.
o Some languages use keywords such as begin and end for grouping statements
while some other languages uses special characters like { }. A general purpose
macro processor may need to take these groupings into account in scanning the
source statements.
• Another problem is with the identification of tokens of the programming languages. The
tokens means the identifiers, constants, operators and keywords in the programming
language. Different languages uses different rules for the formation of tokens. So the
design of a general purpose macro processor must take this into consideration.
• Another problem is with the syntax used for macro definitions and macro invocation
statements.
T
CST305 System Software Module 5
• Some of the data structures required by the macro processor and the language translator
can be combined (e.g., OPTAB and NAMTAB)
• Many utility subroutines can be used by both macro processor and the language
translator. This involves scanning input lines, searching tables , converting numeric
values to internal representation etc.
• It is easier to give diagnostic messages related to the source statements.
2. Nested Macros
• Nested macros are macros in which definition of one macro contains definition of other
macros.Consider the macro definition example given below, which is used to swap two
numbers. The macro named SWAP defines another macro named STORE inside it.
These type of macro are called nested macros.
3. Recursive Macro
• Invocation of one macro by another macro is called recursive macro.Example for
recursive macro:
SUM MACRO &X,&Y
STA &X
ADD &Y
MEND
INPUT MACRO &A,&B
SUM &A,&B .i n v o k i n g the macro SUM MEND
Here the macro named INPUT is calling another macro named SUM. This is called as
recursive macro.
CST305 System Software Module 5
When you buy an operating system, many device drivers are built into the product. However, if
you later buy a new type of device that the operating system didn't anticipate, you'll have to install the
new device driver.
Device drivers simplifies the design of OS. Without the device drivers the operating system
would be responsible for talking directly to the hardware. This would require the OS designer to include
support for all the devices that the users might want to connect to thecomputer. It would also
mean adding support to a new device would require modifying the OS.By separating device driver's
functions from OS, the designer can concentrate on the issues related to the operation of the system as
a whole. Thus device driver designer does not have to worry about the general issues related to I/O
management which is handled by the OS. The device driver writer can connect any I/O device to the
system without having to modify the OS.
OS / Driver Communication
• Deals with the issues related to the exchange of information (commands and data)
between DD and OS.
• It also includes the support functions that the kernel provides for the benefit of DD
Driver / Hardware Communication
• Deals with exchange information ie command and data between device driver and the
device it controls.
• Deals with how the software talks to the hardware
• Deals with how the hardware talks to the software
Driver Operations
• It deals with the issues related to the actual internal operations of the driver itself.
• It includes:
o Interpretting commands recieved from OS
o Scheduling multiple requests for service.
o Managing transfer of data
36
CST305 System Software Module 5
1. Block Drivers
Block drivers are used for block devices. For example, hard disk is a block device and hard disk
drives are commonly implemented as block drivers. Block drivers communicate with OS through a
collection of fixed-sized buffers. For example, disk drives are commonly implemented as block devices.
The OS manages a cache of these buffers and attempts to satisfy user requests for data by accessing
buffers in the cache. The driver is invoked only when the requested data is not in the cache or when
buffers in the cache have been changed and must be written out.
36
CST305 System Software Module 5
buffer cache has following advantage. It allows user processes to perform I/O without regard to the
fundamental block structure of the device and it significantly improves the performance of the system.
All of the management of the buffer cache is handled within the kernel. The device driver merely has to
fill or empty buffers as requested. The rest is handled automatically. Each buffer in the buffer cache is
represented by a buffer header.
2.Character Drivers
Character drivers can handle I/O requests of arbitary size and can be used to support almost any
type of device. Mostly used devices are Printers. Usually character drivers are used for devices that either
deal with data a byte at a time or work best with data in chunks smaller or larger than the fixed sized
buffers used by block drivers (eg tape drives).
Major difference between block and character device driver is that the user processes interact
with block drivers indirectly through the buffer cache but the user process interact with with character
drivers directly. From figure we can see that the I/O request is passed unchanged from the process to the
driver and the driver is responsible for transferring the data directly to and from the user process's
memory.
3. Terminal Drivers
Same as character drivers but specialized to deal with communication terminals that connect
users to OS. Terminal drivers are not only responsible for transferring data to and from user terminals
but also for handling line editing, tab expansion and many other terminal functions
36
CST305 System Software Module 5
that are part of the standard UNIX terminal interface. Because of this additional processing thatterminal
drivers must perform it is useful to consider terminal drivers as a separate type of driver.
4. Stream Drivers
Stream Drivers are used for network devices.It can handle high speed communication devices
such as networking adapters that deal with unusual sized chunks of data and that need to handle protocol.
It is also known as Network Device Drivers.
36
CST305 System Software Module 5
36
CST305 System Software Module 5
• The initial part of the driver is sometimes called prologue. The prologue is everything
before first routine.Prologue contains:
– #include directives referencing header files which define various kernel data types
and structures
– #define directives that provide mnemonic names for various constants used in the
driver
– Declaration of variables and data structures
• Entry points
– This section includes functions which are referenced by operating system.
• Private Routines
– This section includes functions which are private to the driver, which are used for
the internal operation of the driver.
(NOTE:
If the question is to explain anatomy of device driver write upto here and then just mention
the device driver design issues(6.2) and explain block and character drivers with their figure)
36
CST305 System Software Module 5
• Prologue
The initial part of the driver is sometimes called prologue. The prologue is everything
before first routine. Prologue contains:
o #include directives referencing header files which define various kernel data types
and structures
o #define directives that provide mnemonic names for various constants used in the
driver
o Declaration of variables and data structures
#include directives
o Used as Reference to the header files which define various kernel data types and
structures.
o Some header files used by the character device driver are:
#include <sys/types.h> - this header file contains various data types
#include <sys/signal.h> - this header file contains the definition related to signals
needed by sys/user.h
All the above header files are found in the directory /usr/include/sys.
#define directives
o This provide mnemonic names for various constants used in the driver
Declaration of variables and data structures
o This section includes the declaration of different variables and data structures used
by the device driver.
• Entry points
How does the Os tell the driver what it wants to do? This is done in two steps:
36
CST305 System Software Module 5
o Firstly, the OS calls one of the entry points of the device driver. This helps to pass
the control to device driver
o Secondly, the device driver examines the parameters passed and the kernel data
structures for getting information on exactly what to do and performs the required
operation to satisfy users request.
A character driver uses following entry points:
init( ):
– The init( ) entry point is called by the kernel immediately after the system
is booted. It provides the driver with an oppurtunity to initialize the driver
and the hardware. It also display messages anouncing the precesence of
device and the hardware.
start( ):
– This is called by the kernel late in the bootstap sequence when more system
services are available.
open(dev, flag, id):
– This entry point is called by the kernel whenever a user process wants to
open a file that is related to the driver. It provides the driver an oppurtunity
to perform initialization that need to handle read write system calls.
close(dev, flag, id):
– This entry point is called by the kernel when some files need to be closed.
read(dev):
– This entry point is called by the kernel whenever the user process performs
a read system call on a special file related to this driver.
write(dev):
– This entry point is called by the kernel whenever the user process performs
a write system call on a special file related to this driver.
poll( ):
– This entry point is called by the kernel 25 to 100 times a second which
helps the driver to check the status of the device on a regular basis.
halt( ):
– This entry point is called by the kernel before the system is shutdown
intr(vector):
– This entry point is called by the kernel whenever an interrupt is recievd.
36
CST305 System Software Module 5
ioctl():
– This entry point is called by the kernel for processing special requets.
• Private Routines
– This section includes functions which are private to the driver, which are used for the internal
operation of the driver.
• The overall process
Now let us trace the detailed flow of control and data when a user process first opens and then
reads data from device driver. When the operating system receives the open call, it starts by accessing
the file referenced in the open call and determines that it is a special device file. It also sets up a series
of data structures that connect the user's process with the driver.
A table called character driver table is maintained in kernel which contains the information
regarding different character drivers used in the system. The operating system uses the device number
to index into this table to obtain a pointer to the driver's open entry point which is called.
An inode is a data structure containing information about files. The information that was
obtained from the file's inode is placed in a free entry in the inode table. If the file was already open
and in use by another process, then the same inode table entry will be shared among all processes that
have opened the file.
Next, the system allocates a new entry in the kernel's file table that points to the inode table.
Finally, a free entry in the user process's file table is located and set to point to the new entry in the
kerne1's file table. The index to this entry in the process's file table is the value returned by the open
system call. The relationship between these different tables is shown in the following figure.
CST305 System Software Module 5
When the user process executes a read system call, the OS follows the same sequence
of pointers to obtain a pointer to drivers read entry point. The kernel then calls the drivers read
entry point by passing the parameters.
• Prologue
o Same explanation as that of character drivers.
o Add only two more header file
#include <sys/buf.h> - this header file contains the definition of buffer header that
are used to coordinate the transfer of data to and from block drivers.
#include <sys/cmn-err.h> - this header file contains the definition used by the
error reporting routines.
• Entry points
o Block devices uses the following entry points:
init ( ) - same as that of character driver
open( ) - same as that of character driver
close( ) - same as that of character driver
strategy( ) –
This entry point is responsible for handling requests for data. Block device
drivers doesn’t use read and write entry points, instead of that strategy () entry point
is used.
print( ) -
This entry point is used by the kernel to report the problems related to the
driver. It calls the kernel routine cmn_err() to display the error message.
CST305 System Software Module 5
A text editor is a computer program that allows a user to create and revise a target document. The
term document includes objects such as computer programs, texts, equations, tables, diagrams,
photographs etc. The primary elements being editing in a text editor are character strings of the target
text.
An interactive text editor has become an important part of almost any computing environment.
Normally, the common editing features associated with text editors are moving the cursor, inserting,
deleting, replacing, pasting, searching, searching and replacing, saving andloading, quitting etc. The
example for text editors on Windows OS are Notepad, WordPad, Microsoft Word and text editors on
UNIX OS are gedit, vi, emacs , jed, pico.
The document editing process is an interactive user-computer dialogue designed to accomplish
four tasks:
1. Select the part of the target document to be viewed and manipulated
CST305 System Software Module 5
2. Determine how to format this view on-line and how to display it.
3. Specify and execute operations that modify the target document.
4. Update the view appropriately.
The above operations can be explained using the technical terms travelling, filtering, formatting, editing
as follows:
• Traveling: It means the selection of the part of the document to be viewed and edited. It
involves first traveling through the document to locate the area of interest.
• Filtering: It means the selection of what is to be viewed and manipulated is controlled by
filtering. Filtering extracts the relevant subset of the target document at the point of interest
such as next screenful of text or next statement.
• Formatting: It determines how the result of filtering will be seen as a visible representation
(the view) on a display screen or other device.
• Editing: In the actual editing phase, the target document is created or altered with a set of
operations such as insert, delete, replace, move or copy
Alternatively, buttons can be simulated in software by displaying text strings or symbols on the screen.
Locator devices:
These are two-dimensional analog-to-digital converters that position a cursor symbol on the
screen by observing the user's movement of the device. The most common such device is mouse and
tablet.
(The data tablet is a flat, rectangular, electromagnetically sensitive panel. Either the
ballpoint pen like stylus or a puck, a small device similar to a mouse is moved over the
surface. The tablet returns to a system program the co-ordinates of the position on the data
tablet at which the stylus or puck is currently located. The program can then map these data-
tablet coordinates to screen coordinates and move the cursor to the corresponding screen
position. Text devices with arrow (Cursor) keys can be used to simulate locator devices.
Each of these keys shows an arrow that point up, down, left or right. Pressing an arrow key
typically generates an appropriate character sequence; the program interprets this sequence
and moves the cursor in the direction of the arrow on the key pressed.)
Voice-Input Devices:
These devices translate spoken words to their textual equivalents. Voice recognizers arecurrently
available for command input on some systems.
b) Output Devices
The output devices let the user view the elements being edited and the result of the editing
operations.
• The first output devices were teletypewriters and other character-printing terminals that
generated output on paper.
• Next are "glass teletypes" based on Cathode Ray Tube (CRT) technology which uses CRT
screen essentially to simulate the hard-copy teletypewriter.
• Today's advanced CRT terminals use hardware assistance for such features as moving the
cursor, inserting and deleting characters and lines, and scrolling lines and pages.
• The modern professional workstations are based on personal computers with high
resolution displays.
c) Interaction Language
The interaction language of the text editor can be of following types:
CST305 System Software Module 5
Most text editors have a structure similar to that shown in figure on next page.
maintained by the editing component, which is the collection of modules dealing with editing tasks. The
current editing pointer can be set or reset explicitly by the user using travelling commands, such as next
paragraph and next screen, or implicitly as a side effect of the previous editing operation such as delete
paragraph.
Traveling Component
Travelling component is actually used to travel through the document and locate the area of
interest. The traveling component of the editor performs the setting of the current editing and viewing
pointers, and thus determines the point at which the viewing and /or editing filtering begins.
Viewing Component
The start of the area to be viewed is determined by the current viewing pointer. This pointer is
maintained by the viewing component of the editor, which is a collection of modules responsible for
determining the next view. The current viewing pointer can be set or resetexplicitly by the user or
implicitly by system as a result of previous editing operation. This view
CST305 System Software Module 5
may be a very simple one consisting of a window's worth of text arranged so that lines are not broken in
the middle of the words.
Display Component
It takes the idealized view from the viewing component and maps it to a physical output device
in the most efficient manner. The display component produces a display by mapping the buffer to a
rectangular subset of the screen, usually a window
Editing Filter
Filtering consists of the selection of contiguous characters beginning at the current point. The
editing filter filters the document to generate a new editing buffer based on the current editingpointer as
well as on the editing filter parameters.
Editing Buffer
It contains the subset of the document filtered by the editing filter based on the editing pointer
and editing filter parameters.
Viewing Filter
When the display needs to be updated, the viewing component invokes the viewing filter. This
component filters the document to generate a new viewing buffer based on the current viewing pointer
as well as on the viewing filter parameters.
Viewing Buffer
It contains the subset of the document filtered by the viewing filter based on the viewing pointer
and viewing filter parameters. E.g. The user of a certain editor might travel to line 75,and after viewing
it, decide to change all occurrences of "sad" to "happy" in lines 1 through 50 of the file by using a change
command such as [ 1 , 5 0 ] c / sad /happy.
As a part of the editing command there is implicit travel to the first line of the file. Lines 1 through
50 are then filtered from the document to become the editing buffer. Successive substitutions take place
in this editing buffer without corresponding updates of the view.
This viewing buffer is then passed to the display component of the editor, which produces a
display by mapping the buffer to a rectangular subset of the screen, usually called a window.
Relation between Editing and Viewing Buffers
The editing and viewing buffers can be related in many ways.
o Identical
o Disjoint
o Overlapped
CST305 System Software Module 5
In a simplest case, if the user edits the material directly on the screen, editing and viewing buffer
are said to be identical. On the other hand, if the user is editing the material which is not display on the
screen the editing and viewing buffers are said to be disjoint. If the user edits some portion of the
materials displayed on the screen and some portions not displayed on the screen then editing and viewing
buffers are said to be overlapped.
The mapping of the viewing buffer to a window is accomplished by two components of the system.
First, the viewing component formulates an ideal view often expressed in a device independent
inter-mediate representation. This view may be a very simple one consisting of a windows worth of text
arranged so that lines are not broken in the middle of words.
Second the display component takes these idealized views from the viewing component and maps
it to a physical output device in the most efficient manner possible.
Windows typically cover the entire screen or rectangular portion of it (part of screen)
The content of viewing buffer is passed to the display component of the editor, which produces
a display by mapping the buffer to a rectangular subset of the screen, usually called a window. This
window can be Entire screen which means window is of same size as screen or Part of the screen
which means window cover only part of the screen. Mapping viewing buffers to windows that cover
only part of the screen is especially useful for editors on modern graphics based workstations. Such
systems can support multiple windows, simultaneously showing
CST305 System Software Module 5
different portions of the same file or portions of different file. This approach allows the user to perform
inter file editing operations much more effectively than with a system only a single window.
(The components of the editor deal with a user document on two levels:
• In main memory
• In the disk file system
Loading an entire document into main memory may be infeasible. However if only part of a document
is loaded and if many user specified operations require a disk read by the editor tolocate the affected
portions, editing might be unacceptably slow.
In some systems this problem is solved by the mapping the entire file into virtual memory and
letting the operating system perform efficient demand paging. An alternative is to provide is the editor
paging routines which read one or more logical portions of a document into memory as needed. Such
portions are often termed pages, although there is usually no relationship between
CST305 System Software Module 5
these pages and the hard copy document pages or virtual memory pages. These pages remain
resident in main memory until a user operation requires that another portion of the document be
loaded.)
5.4 DEBUGGERS
INTERACTIVE DEBUGGING SYSTEMS
The errors in the program are called bugs and the process of finding and correcting them is called
debugging. An interactive debugging system provides programmers with facilities that helps in
testing and debugging of programs interactively.
Traceback can show the path by which the current statement in the program was reached.
It can also show which statements have modified a given variable or parameter.
• Program display Capabilities :
It is also important for a debugging system to have good program display capabilities. Agood
debugger must display the entire program being debugged with statement number.
• Multilingual Capability:
A debugging system should consider the language in which the program being debugged is written.
Most user environments and many applications systems involve the use of different programming
languages. A single debugging tool should be capable to debug multiple languages.
• Context Effects
The context being used has many different effects on the debugging interaction. For example.
The statements are different depending on the language. For eg,
In COBOL, MOVE 6 TO X
In FORTRAN, X = 6
Both these statement assigns the value 6 to the variable X.
Likewise different programming languages use different syntax for conditional statements. Foreg,
In COBOL, IF A NOT EQUAL TO B
In FORTRAN, IF (A .NE. B)
Both these statements checks whether the value of A is not equal to B.
Similar differences exist with respect to the form of statement labels, keywords and so on.
• Display of source code:
The language translator may provide the source code tagged in some standard way so thatthe
debugger has a uniform method of navigating about it.
• Optimization:
It is also important that a debugging system be able to deal with optimized code. Many
optimizations involve the rearrangement of statements or segments of code in the program.
For eg, loop invariant code motion which means the invariant expressions can be move
outside from loop. Consider the for loop,
for( i=1; i<100; i++ )
{
CST305 System Software Module 5
a=b+c;
x=y+i;
}
Here value of the statement a=b+c doesn’t changes on the different iteration of for loop. Hence itcan be
consider as loop invariant code and can be move outside from the loop as follows:
for( i=1; i<100; i++ )
{
x=y+i;
}
a=b+c;
Other optimization strategies are separate loops can be combined into a single loop,common
sub expression may be eliminated etc.
The debugger must co-ordinate its activities with those of existing and future language compilers
and interpreters. It is assumed that debugging facilities in existing language willcontinue to exist and be
maintained.
Menus
With menus and full screen editors, the user has far less information to enter and
remember. It should be possible to go directly to the menus without having to retrace an entire hierarchy.
Command language
The command language should have a clear, logical, simple syntax. Parameters names should be
consistent across set of commands. Parameters should automatically be checked for errors for type and
range values. Defaults should be provided for parameters. It should minimize punctuations such as
parenthesis, slashes, and special characters.
On Line HELP facility
Good interactive system should have an on-line HELP facility It should provide help forall
options of menu. Help should be available from any state of the debugging system.
1. Debugging by Induction
In debugging by induction one starts from the available data which are related to the symptoms
of error, identify the relationship between them and devise some hypothesis. If the hypothesis can be
proved, fix the error using it.
Prove the hypothesis by comparing it to the original clues or data, making sure that this
hypothesis completely explains the existence of the clues. If it does not, either the hypothesis is invalid,
the hypothesis is incomplete, or multiple errors are present. If the hypothesis is not proved, repeat step
3 and 4.
5. Fix the error
If the hypothesis is proved then fix the error based on that hypothesis.
2. Debugging by Deduction
The process of debugging by deduction proceeds from some general theories or premises, using
the processes of elimination and refinement, to arrive at a conclusion.
problem. If you skip this step, you'll probably succeed in correcting only the problem symptom,
not the problem itself.
Prove the hypothesis by comparing it to the original clues or data, making sure that this
hypothesis completely explains the existence of the clues. If it does not, either the hypothesis is
invalid, the hypothesis is incomplete, or multiple errors are present. If the hypothesis is not
proved, and no more hypothesis exist collect more data and starts from step 1.
5. Fix the error
If the hypothesis is proved then fix the error based on that hypothesis.
3. Debugging by Backtracking
• This is an effective method for locating and correcting errors in a small program
• In this method:
– Start at the place in the program where an incorrect result was produced
– Go backward in the program one step at a time, mentally executing the
program inreverse order
– Derive the state (values of all variables) of the program at the previous step
– Continuing in this fashion, the error is localized between the point where the
state of the program was what was expected and the first point where the
state was not what expected.
4. Debugging by Testing
The use of additional test cases is another very powerful debugging method which is often
used in conjunction with the induction method to obtain information needed to generate a
hypothesis and/or to prove a hypothesis and with the deduction method to eliminate suspected
causes, refine the remaining hypothesis, and/or prove a hypothesis.