for an abstract t/2 macnine(u) naval postgraduate school … · 2014-09-27 · i1e(cludo securfy...

143
RD-A1B4 691 DESIGN RND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL MONTEREY CA S VICTRUM JUN 87 UNCLASSIFIED F/G 12/5 N NAEDhE h~ hh

Upload: others

Post on 09-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

RD-A1B4 691 DESIGN RND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT t/2MACNINE(U) NAVAL POSTGRADUATE SCHOOL MONTEREY CAS VICTRUM JUN 87

UNCLASSIFIED F/G 12/5 N

NAEDhE h~ hh

Page 2: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

L L

MICROCOPY RESOLUTION TEST CHART

NATIONAL BUREAU OIF STANDARVIS1963-A

V*l -*7-.V~'

X.

Page 3: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

OIFILE COPY

NAVAL POSTGRADUATE S.CHOOL* Monterey, California

0

DT iOCSEP 25 1989D

*THESIS M A

DESIGN AND IMPLEMENTATION OF ADEBUGGER FOR AN ABSTRACT MACHINE

by

Stanley Victrun

June 1987

Approved for public release; distribution is unlimited

Page 4: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

UNCLASSIFIED ,4 / - /~~IECUlIry CLASSI;ICATION OF THiS 'AEtr

REPORT DOCUMENTATION PAGEIs REPORT SECURITY CLASSIFICATION Ib RESTRICTIVE MARKINGS

Unclassified2a SECURITY CLASSIFICATION AUTHORITY 3 DISTRIBUTIONI'AVAILAIILITY OF REPORT

2b OECLASSIFICATIONIDOWNGRADING SCHEDULE Approved for public release;Distribution is unlimited

a PERFORMING ORGANIZATION REPORT NUMBER(S) S MONITORING ORGANIZATION REPORT NUMBER(S)

6a NAME OF PERFORMING ORGANIZATION r6b OFFICE SYMBOL 7 NAME OF MONITORING ORGANIZATION(if opohicabit)

'laval ?osTrgraduate Schoo Code 52 Naval Postgraduate School

6c ADDRESS City. Star. and ZIPCode) ?b ADDRESS (City. State, nd IP Code)

Monterey, California 9 3943-5000 Monterey, California 9 39 43-5000

8. NAME OF FUNDINGSPONSORING fb OFFICE SYMBOL 9 PROCUREMENT INSTRUMENT IOENr,FICArION NUMBER

O RGA NIZ ATION Itf applicable)

Sc AOORESS (Ciry. State. and ZIPCode) 10 SOURCE 0 FUNDING NUMBERS

PROGRAM PROJECT TAS< WORK JNIT

ELEMENT NO NO NO ACCESSION NO

., . I1E(cludo Securfy Cla,wicarlOn)

DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

2 ERSONA,. AUTHOR(S)

Victrum, Stanley3, r f=i OF REPORT 3b TME COVERED TO DATE OF REPORT (Yer.Monh. Day) u5 PAGE CO ,NT

Master's Thesis _ FROM TO 1987 June 138'6 SLPPLEMVENTARY NOTATION

COSATi CODES 18 SUBJECT TERMS (Continue on reverse if necessary and identfy by block number)

F ELD GROUP SUB.GROUP Interactive debugger; Software portability;-/ Resource abstraction; Formal specifications;

Abstract machine; Representation independence;9 ABSTRACT (Continue on reverie of necessary and identify by block number)

-- Conventional computer architectures do not allow us to unambiguouslyexpress our intent in a computer program. The combination of artificialdata types and resource models force ambiguity and data structure over-loading. For example, the semantics of a stack combine those of an arraystrunture ind a last-tn-_'irst-out queue, wrhile the .ntie ;taci str'1ct. , .:s .... eo menczd 4-n comrnuer nemcryr as a groun 7' ' i:>_ d .....

-ne macnine-daza type dependencies can markcedly hampe:v so;f .:eportability. To overcome these obstacles, a means of formally specifyinga computing machine's physical resources in an implementation independentway has been proposed. Creating an abstraction of the computer's physi-

cal resources in this manner lets the implementor of the specificationsclearly determine the intent of programs written for it. This abstrac-

tion has come to be known as the Abstract Machine or AM. --00 S'R,3UTON/AVAILABILITY OF ABSTRACT 21 ABSTRACT SECURITY CLASSIFICATION

...NCLASSIFIED1UNLMITED [3 SAME AS RPT 0OTIC USERS Unclassified22a %AME OF RESPONSIBLE INDIVIDUAL 22b TElEPHONE(includit Area Code) 22c OFF (E SYMBOL

Daniel Davis (408) 646-3091 1Code 52Dv

00 FORM 1473. 8 MAR 83 APR e,,,of i may bt usedimtI 0whausted %E RI .SIFI,- .AT'N ")F -' 'a..

All o,.., o.,,,. at@ oboloto UNCLASSIFIED

- -,-* ./ -. j . .~ - - --- --1

Page 5: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

UNCLASSIFIED29CUPATY CLASIFICATION OF THIS PAGIJ M11 DWa 10

#18 SUBJECT TERMS (continued)

Functional interfaces.

#19 ABSTRACT (continued)

One implementation of these resource specifications hasalready been accomplished. Several programming tools, such asa programming language compiler and a visual display device, havealso been created (in software) for use with this AM's implemen-tation. At oresent, however, there are no means for interactive-ly displaying and altering the storage resources of the AbstractMachine for debugging purposes. For the current AM implementa-tion, the bulk of the automated debugging tools consist ofassembler code tracing and listing options that can be chosen atrun time. The goal of this thesis is to build an interactivedebugger for the Abstract Machine near the assembler code level.This should expedite the process of producing relatively error-free, executable programs while using a smaller amount of timeand effort. The debugger will serve as another building blockin the creation of a complete programming environment for theAbstract Machine. This in turn will assist in the general studyof minimizing the software portability problems that arise be-cause of machine-software dependencies.

. - ' ' '(Jr

.,t f cat ioC

Availability C 48fAvail and/@

IDist Special

SN 0102-LF-014-6601

2 UNCLASSIFIEDSRCURITY CLASSlPICATIO OF THIS PAGff(Wb Da te .)

Page 6: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Approved for public release, distribution is unlimited

Design and Implementation of aDebugger for an Abstract Machine

by

Stanleg VictrumFirst Lieutenant, United States Marine Corps

B.A., The Citadel, 1982

Submitted in partial fulfillment of therequirements for the degree of

MASTER OF SCIENCE IN COMPUTER SCIENCE

from the

NAVAL POSTGRADUATE SCHOOLJun 1987

Author: '14 sti i'3Stanley Victrum

Approved by: gw .'Daniel L. Davis, Thesis Advisor

Bruce J. Ma ennn, Second Reader

" _/Vincent Y. Lure, ChairmanDipartment of Computer Science

Kneale T. Marshal ". - \Dean of Information and Policy Scie L"4

3

.,*"

Page 7: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

ABSTRACT

Conventional computer architectures do not allow us to unambiguously

express our intent in a computer program. The combination of artificial data

types and resource models force ambiguity and data structure overloading.

For example, the semantics of a stack combine those of an array structure

and a last-in-first-out queue, while the entire stack structure is

implemented in computer memory as a group of fixed length cells. This and

other machine-data type dependencies can markedly hamper software

portability. To overcome these obstac!es, a means of formally specifying a

computing machine's physical resources in an implementation independent

way has been proposed. Creating an abstraction of the computer's physical

resources in this manner lets the implementor of the specifications clearly

determine the intent of programs written for it. This abstraction has come

to be known as the Abstract Machine or AM.

One implementation of these resource specifications has already been

accomplished. Several programming tools, such as a programming language

compiler and a visual display device, have also been created (in software) for

use with this AM's implementation. At present, however, there are no means

for interactively displaying and altering the storage resources of the

Abstract Machine for debugging purposes. For the current AM

implementation, the bulk of the automated debugging tools :onsist of

assembler code tracing and listing options that can be chosen at run time.

The goal of this thesis is to build an interactive debugger for the Abstract

Machine near the assembler code level. This should expedite the process of

producing relatively error-free, executable programs while using a smaller

4

Page 8: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

amount of time and effort. The debugger will serve as another building block

in the creation of a complete programming environment for the Abstract

Machine. This in turn will assist in the general study of minimizing the

software portability problems that arise because of machine-software

dependencies.

5

Page 9: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

TABLE OF CONTENTS

1. INTRODUCTION .................................................................................... 91i. BACKGROUND ............................................ .... ................................... I I

A. THE PROBLEM ............................................................................ I I

B. A FEASIBLE SOLUTION: AM ........................................................ 1 3C. RELATED RESEARCH .................................................................. 14

I1. DESIGN .. . ................................ . ...... 15A. BASIC COMPUTER RESOURCE ORGANIZATION ............................. 15

1. Computer Resources ...................................................... 152. Computer Data Structures .............................................. 173. Instructions to the Computer ...................................... 1 9

B. DESIGN OF THE INTERACTIVE DEBUGGER ................................. 201. Philosophy ..................................................................... 202. Debugger Interface to the Physical Resources ................ 233. Debugger Interface to the User .................................. 24

IV. IMPLEMENTATION ................................. ........ ... .............................. 26A. ASSUMPTIONS ........................................................................... 26B. DEBUGGER COMMAND SYNTAX SYMBOLS .................................... 26C. INTERACTIVE DEBUGGER OPERATIONS ............. ......................... 26

1. Display Operations ......................................................... 26a. Display Memory ..................................................... 27b. Display Register ......................................... .......... 27

-c. Display StacKtop ............. .................................... 28

d. Display Breakpoints ..... ............. ...................... 28e. Display Program Counter ...................................... 29

2. Set Operations ........................................ ....................... 29a. Set Memory .......................................................... 29b. Set Register .......................................................... 30c. Set Stac ,top ......................................................... 30d. Set Breakpoint ...................................................... 3 1e. Set Program Counter ............................................. 32

3. Remove Breakpoint Operation ........................................ 324. Trace Execution Operations ............................................ 33

6

Page 10: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

a. Trace On ................................................................ 33b. Trace Off ............................................................. 33c. Trace n ................................................................. 34

5. Go Operations ...... ........................................................... 345. Go Uncontrolled .................................................... 34

b. Go n ................................... O ................................ 356. Help Operation ....................................................... .. ... 35

D. DEBUGGER CONTROL OF MACHINE EXECUTION ........................... 35I . Debugf lag ........................................................................ 36

2. De gtask ......................... S.......... ............ ......... 36

3. Left2do .......... . ............................................................... 36

4. Debgcntl ................................... ............................... . 36

5 B reakflg ....................................................................... . 38

6. Errorf g ......................... ............................................... 387. Dbgtrace .......................................................................... 30

E. ERROR HANDLING IN PROGRAM EXECUTION ................................ 3BF. MODIFICATIONS TO AM IMPLEMENTATION ................. ................ 39

V. CONCLUSIONS AND FUTURE WORK .......................... ........................... 40APPENDIX A: SAMPLE SESSIONS ......................... .. ...................................... 411APPENDIX B: DEBUGGER COMMAND SYNTAX SYMBOLS ........ ....................... "70

APPENDIX A: DEBUGGER PROGRAM FILES .................................................. 71LIST OF REFERENCES .................................................................................. 135INITIAL DISTRIBUTION LIST ....... ................................................................ 136

7

Page 11: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

LIST OF FIGURES

Figure 2.1: The Senmantic Gap ............................................................ 1 1

Figure 2.2 : Data Type Dependency on Hardware Values ..................... 12

Figure 2.3 : Narrowing the Semantic Gap ........................................ 1 4

F igure 3.1 : Computer Program in AM Implementation ....................... 17

Figure 3.2 : Data Value Structures ................................................. 1Is

F igure 3.3 Common Value Abstraction ............................................. 19

Figure 3.4 Primary Resource Structures .......................................... 20

Figure 3.5 Structure of Instruction Value ......................................... 21

Figure 4.1 Debugger Control Variaoies ............................................. 37

Page 12: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

I. INTRODUCTION

In the days when the assembly language programmer was king and

higher-level programming languages were still unimplemented concepts on

the "drawing board." crude were the tools the programmer could wield in his

programming environment to quickly conquer coding problems. During this

period, CPU time was money, thus efficient programs were a must (as well as

a source of pride and means of security for the programmer). The

programmer was expected to massage the computing machine's stack:s,

registers and memory to eke out as efficient a program as possible.

To write efficient programs, the programmer typically included in ,is

program code assumptions about his computing machine's physical

resources. These assumptions, such as the number of registers available, the

machine's representation of data types, and the physical implementation of

the stacks, were "hardwired" into the programmer's code. Of course, errors

in the program required intimate knowledge of all these assumptions. Events

such as upgrading the machine or replacing it with one of a slightly different

architecture typically caused program nightmares with previously "bug-free"

programs going haywire because the resource assumptions had changed. This

situation, unfortunately caused even more assumptions to be incorporated

'nto The :oae. upically n "ike iorm of oroarim 'atcnes.' "his :uc',.

allowed to continue, can so disfigure the original intent of the program, itV

soon becomes difficult, at best, to interpret it.

Conventional computer architectures do not allow us to unambiguously

express our intent in a computer program. The combination of artificial data

9

Page 13: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

types and artificial resource models force ambiguity and data structure

overloading. For example, the semantics of a stack combine those of an

array structure and a last-in-first-out queue, while the entire stack

structure is implemented in computer memory as a group of fixec lengtm

cells. This and other machine-data type dependencies can markedly hamper

software portability. To overcome these obstacles, a means of formally

specifying a comouting machine's physical resources in an implementation

independent way has been proposed (Davis[19841). Creating an abstraction of

the computer's physical resources in this manner lets the implementor of the

specfficatlors !early determine the intent of programs written for it. This

abstraction has come to be known as the Abstract Machine or AM.

One implementation of these resource soecific3tions has 3lready been

accomplished (Yurchak[19841). Several programming tools, such as a

programming language compiler (Ozisik[1986]) and a visual display device

(Hunter[1985]), have also been created (in software) for use with this AM's

implementation. At present, however, there are no means for interactively4'. displaying and altering the storage resources of the Abstract Machine for

debugging purposes. The current debugging tools consist of assembler code

tracing and listing options that can be chosen only at run time. This thesis'

goal is to build an interactive debugger for the Abstract Machine near the

assembler code level. This should expedite the process of producing

.7-iatveiy 2rrcr-.,r2e. 2xecutaoie )r-ar.ms ,nviie -s inQ 3mailer imount :f

-' time and effort. The debugger will serve as another building block in the

creation of a complete programming environment for the Abstract Machine.

This in turn will assist in the general study of minimizing the software

'4- portability problems that arise because of machine-software dependencies.

10

Page 14: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

11. BACKGROUND

A. THE PROBLEM

In his Masters thesis, Yurchak[19841 presented a formal specification for

an Abstract (computing) Machine which he called AM. This AM was to be used

to study and offer a way of minimizing the problem of Dorting software from

one computing machine to another.

.. ............. .. . . . . . . . .

Programming Tools

Problem S , in , .s rati,,t

PSoloing, ae .u1 1 tre a tiaon

Figure 2.1: The Semantic Gap

'.7, Yurchak[1984] noted that porting large programs between computing

" i': ,'nacnines s an exDenlsIVe ordeal :n terms of rogrammer timne ]nc .;!

'% '.This predicament is brought on because of the wide semantic gap (as shown

in Figure 2.1 above) between the programmer's problem solving abstraction

(i.e. programming languages, development tools, etc.) and the computingmachine's physical resources abstraction (i.e. addresses, registers, stacks,

mo1

. . . . . .... ... . .. . .. . .

%v. .. .

Page 15: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

etc.). In his words, this gap between the two abstractions was,

simplistically speaking, a "boundary" between the software used by the

programmer to form problem solutions and the hardware by which those

solutions are implemented.

..... characterString...........i::ii Progrqaming sta t .... ... . .

. ..........................:...............

T h [ e Si S t x t

..................... ..... ............

..... .... .:::.::'W rrtwqrP Ahnltrnict inn):

Figure 2.2: Data Type Dependency on Hardware lalues

Generally, a computing machine has but a few primitive structures on

which the rest of the problem solving abstraction is based. Typically, there

exists a strong bond between the way data types are implemented and the

manner in which they are represented in hardware. For example, a character

string is typically represented as an array of memory cells, with each cell

containing the corresponding integer representation of the corresponding

character in the character string. Figure 2.2 above depicts this relationship.

if he rextuai rvpros.mtation of the values in ComDuter memory here to N2

removed, the meaning of the values could not be determined. They could be

integers, memory addresses or numeric symbols for other artificial data

types. The context of the values must be determined before they can be given

meaning. This situation typically leads to overloading of the primitive data

12

Page 16: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

types of the machine, allowing the programmer to treat one data type as

another, thus compromising the data structure typing. This compromise

typically causes extensive program changes in the data structure definitions

when porting the program from one architecture to another.

B. A FEASIBLE SOLUTION: Al

In proposing a solution to the software portability problem. Davis(19841

formulated a methodology for formally specifying a computer's resources at

different levels of abstraction. His approach was to develop formal

specifications for the functional interfaces between the resources of the

computing machine. In this way, the user need only be concerned with the

functional interface to a particular abstraction level and not the actual

interface implementation, which could be done in hardware or software. To

ascertain the feasibility of this new methodology, Yurchak[19841 designed

and implemented a test version of the specifications for a computer

processor, which has become to be known as the Abstract Machine.

Davis[19841 and Yurchak[19841 decided to test the methodology at the

processor level of abstraction because, being the most difficult to formally

describe, it would give the most insight on the validity of the approach.

This abstract architecture treats each one of the machine's physical

resources as a black box and allows the programmer to use the resources in

oniy the Soecffiea way. in other words, the 3Decffication :ietails 2xac*tlu

what resources mean and how to use them, but does not specify how a

resource is to be implemented. With software tools being written for

implementation on one abstract machine, software portability is markedly

improved. The AM serves as a formal interface between the programming

13

Page 17: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

P ________________ ............ ____...... r. .... ...... ..... .......t. ... .....

...... g u re. . ... .....rr ........ .......n. ......

machine.The AMProgramming ools l oko n rhtcuea oga

2. abv deit the m inerac ingfbta th porm ing nvrnet

C. REAE RESEARCH. .

lesioneaP-hU an aotrc ~aaasI Rsn e simlar D-orace t c sicfil ah n

Agalsin the oal onthistei isd toh ae yianoth r eeomn tool forputheg

mahnTeAM programming vrnntol namlrko an earceeuge aslneash

aseMl spcc on level.l mpeete ntatacitcue.Fgr

2. bv eit h Mitrae nteporm igevrnet

C. RELTED RSEA14

Seea4rgamn ooshv led en-eeoe o h M

Page 18: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

III. DESIG

Before presenting the design and implementation of the ANl interactive

debugger, it is important to make clear the salient points behind the

specification of the AM. The AM is an abstraction of the physical resources

of a machine and, as Davis[19841 points out, the methodology used to

formally specify that abstraction is representation idependent The best

example of this representation independence notion is abstract data types.

The type 'integer' not only implie - a set of values, but 3 set of operations

upon those values. This "notion" can be implemented in many different

contexts, but its intuitive properties transcend implementations or physical

representations. This is the essence of and the true power behind the

Abstract Machine concept.

The actual AM implementation around which the interactive debugger was

built is another physical representation of this representation independence

notion. Therefore, although one implementation is presented in this thesis,

the formal specifications for the resource abstraction is adhered to (via the

programmer interface to the debugger).

A. BASIC COMPUTER RESOURCE ORGANIZATION

: mputer Resources

The AM incorporates the basic principles of a von Neumann computing

machine. It has a memory for program storage and instruction execution,

sets of registers and stacks for temporary storage of data values, and, of

course, a set of data values. Yurchak's[1984] AM implementation, being an

15

Page 19: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

abstraction of a computing machine's physical resources, can be easily"reconfigured" by changing the basic definitions of the resources available.

The implementation storage resources used in developing the debugger were

as follows:

* Two memory segments, each with 1024 storage cells;

* One register segment with thirty-two storage cells;

* One stack segment with 512 storage cells;

* 1022 heap segments, each with 1024 storage cells.

The memory, registers, stacks and heap storage cells, as in any computingmachine, all hold defined data values. The definition of AM data values,

however, differs slightly than the manner in which they are defined in other

computing systems. The AM's data values are typed while a regular vonNeumann machine's is not. In other words, one can determine what the Value

is inside a storage location since the value's type is stored along with it.

Figure 3.1 on page 17 shows an example of a computer program in this AM

implementation with its machine code and assembly language

statements. At memory location '00000000,' '0190' is the AM

implementation's machine code for INSTRUCTION-TYPE. It is followed in the

memory address by the instruction opcode and the operands for the opcode.

Notice that each operand value is also linked to a type. '0160' is machine

code for MEMORY-ADDRESS-TYPE and '0170' for REGISTER-ADDRESS-TYPE.

The AM Dhyslcal resources aostraction, being :mIDlementea ;n

software, is built upon data structures. The data structures used byYurchak[1984] were studied in depth so that the computer's functional

capabilities could be extended and, thus, are presented in the next section.

16

Page 20: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Memorg Machine Assembig LanguageLocation Code Statements

0190 18F000000000 0190 3831 move {addr, data), r (0:0)

0160 00000003

0170 0000000000000001 0190 382E move (int, 100), r(0:0)@

0130 000000640170 00000000

00000002 0190 1880 stop00000003 0190 18F4 data ds 10

0160 O00000000190 18FI

Figure 3.1: Computer Program in AM Implementation

2. Comouter Data Structures

In order to design a debugger that will interact unobtrusively with

the AM's basic operations, one must understand the data structures upon

which it was implemented. These structures represent the AM's data values,

memory, registers, and stacks. All the data structures used in this

Implementation were written in the 'C' programming language.

Figure 3.2 on page 18 shows the type declaration structures in

Yurchak's[1984] implementation for BOOLEAN, INTEGER and NATURAL data

'alues. They are 72Dresentative of al1 t.e .- '3 asic data /alue sruc,ures.

YurcnaKl(9841 notes that the AM storage resources are aesigned to hold any

properly defined value. In typical computing, this poses little or no problem

since all the values are based upon the overworked and overloaded bit vector.

To be able to store and operate upon a myriad of value types in the

17

Page 21: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

typedef char bool;typedef unsigned int nat;

typedef struct {short type;

bool val; ) BOOL;

typedef struct (short type;

long val; I INT:

typedef struct {short type;fnat val; }NAT;

Figure 3.2: Data Value Structures

AM's "physical resources" required the introduction of another "common"

level of abstraction, a union of all the basic value types. This abstraction

was implemented using the structure shown in Figure 3.3 on page 19.

With the structures of the data values now presented, it is now time

to examine the structures that represent this implementation's primary

physical resource abstraction for the memory, registers and stacks. The

type declarations for the structures are shown in Pigure 3.4 on DaQe 20.

nacr rascurc2 :s primarily a structure containing an array whicn :an store

U any value defined in this AM implementation. The computer's memory,

registers and stacks are actually arrays of these resource structures. Each

of these arrays equates to a storage "segment."

18

Page 22: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

typedef union value(short type;opcode opcdval;BOOL boolval,INT intval;NAT natval;CHAR charval;CSTR cstrval;MAD madval;RAO radval;,SAD sadval;FIL f ileval;INSTR instrval;MOP mopval;DOP dopval;ROP ropval;BOP bopval; )VAL;

figure 3.3: Common 111111.11E Obstrection

3. Instructions to the Computgr

Perhaps the most important of the computer values is the

INSTRUCTION. INSTRUCTION values, as in any other computing machine, drive

the computer program's execution. Its type definition and logical structure

;,n "ur!c-.ak's19841 !mPlementation 3re snown h Figure 3.5 ..n age .As

snown in thie figure, the instruction is impiemented as a structure containing

Its value type and an array of operand values. The first element of this array

Is the instruction opcode. Subsequent elements In the array are the operands

19

Page 23: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

typedef struct (int size;VAL "wval; } memseg;

typedef struct (int num;VAL *"val; } regseg;

typedef struct fint size;long sp;VAL "val; } stkseg;

Figure 3.4: Primarg Resource Structures

(AM data values) for the instructions. Yurchak[19841 implemented the

instruction value so that the first digit of the opcode indicated the number

of operands the instruction required. By his design, the opcode was also

considered as one of the operands. It is important to note that the

instruction type definition (Figure 3.5) and the common-value type

definition (Figure 3.3) are recursively defined in terms of each other. This

facilitates converting from a basic instruction value, stored in memory, to

an executable instruction at the programming level of abstraction.

1. DESIGN OF THE INTERACTIVE DEBUGGER

I. Phliosophy

As stated in Chapter 1, the computer's current debugging facility

consists of a trace option that can be specified at computer "startup." This

20

Page 24: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

typedef struct Cshort type;union value "val; ) INSTR;

Type Opcode 0

Ual Foperand i

Oran 2

erand n

Figure 3.5: Structure of Instruction Value

trace facility was, however, designed more for providing debugging

diagnostics about the computer's internal functioning than for debugging the

user's program. The trace could only be turned on at the beginning of

program execution and could only be turned off by program termination. This

facility alone clearly does not provide the AM computer programmer with an

adequate program debugging environment.

Wray[1984] notes that a microcomputer debugging environment

3rnould Mave the rollowing basic functions:

e Single-step program execution;

a Breakpoints in program execution;

a Register Display/Modification;

21

.- . '

Page 25: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

* Memory Display/Modification.

This basic suite of debugging facilities gives the programmer the capability

to "disassemble" and examine his program and the machine state in discrete,

well defined steps. This gives the programmer a means of quickly identifying

and correcting program logic errors with a minimum of time and effort. The

interactive debugger for the AM was designed to provide all of the above

facilities. To give the programmer an added degree of freedom in the

debugging environment, the following capabilities were also incorporated

into the design of the AM debugger:

* Program Execution Trac2;

@ Program Counter Display/Modification.

The program execution trace, unlike the old trace facility, shows just the

instruction about to be executed. Allowing the programmer to see and

change the program counter allows the testing of different program

execution paths without having to terminate program execution, changing its

textual representation, and recompiling the program for execution. This is in

accord with the philosophy of providing a debugging environment that

facilitates quick detection and correction of coding (logic) errors.

Yurchak's[19841 AM implementation is designed to be easily

reconfigurable by changing the basic array definitions of the resources

available. The essence of this design objective was carried over into the

.".: iesign ci "he debugger. A reconfiguration of the computer's rzscurczs in te

AM is acknowledged by the debugger while performing its operations. The

basic definitions for the debugger may also be easily reconfigured for, say,

allowing more program breakpoints or increasing the maximum integer the

*debugger assumes.

22

Page 26: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

2. Debugger Interface to the Physical Resources

In order to implement the debugger facilities, an interface to the

computer's physical resources had to be designed. This interface would be

primarily concerned with the retrieval and storage of data values in the

machine's physical resources. A study of the computer's data retrieval and

storage modules revealed that the following functions were currently

available for these tasks:

a FETCHM0 - retrieves a value from memory;

e STOREMO - stores a value into memory;

. * FETCHRO - retrieves a value from a register;

e STORERO - stores a value into a register;

a TOPSTKO - retrieves a value at top of a stack.

These functions provide a well-defined interface to the data structures upon

which the resource abstraction is built. Interfacing to these functions to

perform the debugger operations resulted in a reduction in the amount of

code needed to implement the debugger.

As is typical in any computing machine, however, some data retrieval

and storage operations generate errors which in turn force abnormal

termination of program execution. Three such operations are as follows:

@ Retrieving a value form an uninitialized storage location;

*a Retrieving a value form a non-existing storage location;

a 3toring a value at a non-existing storage iocation.

Clearly if the debugger is to use the implementation's existing AM data

retrieval and storage functions to perform its operations, a means of

properly handling these types of errors had to be developed. To display

uninitialized storage locations while in the debugging mode, the retrieval

23

Page 27: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

functions were modified to return a NULL value for displaying to the user. If

the computer is not in the debug mode, a regular execution error is

generated. The means for preventing the latter two types of errors while in

the debug mode were designed into the user interface to the debugger.

3. Debugger Interface to the User

The interface was designed to permit, of course, the capability to

perform the operations listed in section i11.5.1. It was also tailored to keeD

the user from specifying debugger commands that would cause preventable

errors in the debugger interface to the physical resources abstraction and in

program execution. 5ince the debugger has access to available computer

resources, the user can be kept from trying to access a non-existing storage

segment or offset address, from setting the program counter to a memory

location that does not contain an instruction value, or setting a breakpointat a memory location that does not contain an instruction value. This type

of interface traps potential errors at the earliest possible stage. It does

not, however, prevent the user from setting a storage location with a value

that may cause an error during program execution. This particular kind of

error correction was considered beyond the scope of this thesis and,

therefore, was not entertained.

The debugger was designed to prompt the user for each piece of

command input (prompted commands) instead of the user entering the entire

Jeougger :kmmana on one or two ;ines 'line commands). Promore' ;nDUt

allows for "layered" error checking of the debugger command, allowing the

user to reenter input at that layer instead of having to reenter the entire

debugger command. This also permits new users, familiar only with this AM

implementation's value representation and instruction opcodes, to quickly

24

Page 28: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

learn and use the debugger without learning debugger command-line formats.The debugger interface to the user is shown in Appendix A, Sample Sessions.

25

Page 29: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

IV. IMPLEMENTATION

A. ASSUMPTIONS

In building any software tool, some of the many variables in a

programming environment must be made fixed due to implementation

considerations and a need for establishing a point of reference. These"constant" variables take the form of assumptions about the programming

environment. The following ones have been made about the AM programming

,nvironment:

" The user knows how to assemble files using the environment's

assembler for execution on the comDuter;

" The user is familiar with the instruction opcodes used in this

implementation of the AM;

" There are no more than six (6) operands per instruction;

" A character string is less than 81 characters in length;

" Integer values range from - 2147483647 to 2147483647;

B. DEBUGGER COMMAND SYNTAX SYMBOLS

The debugger command syntax symbols are in Appendix B, Debugger

Command Syntax Symbols. The user is prompted for each piece of the

:cmmand, :herpf-or. ..he actual wcmmano format 7s ativety Jnimocrani.

C. INTERACTIVE DEBUGGER OPERATIONS

1. DisDlau ODerations

The user can use the debugger to display all the computer's memory,

26

Page 30: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

registers, the top of any stack segment. all the program breakpoints and the

current value of the program counter. Sample demonstrations of the display

operations can be found in Appendix A, Sample Sessions. The following

subsections present the functional details for each type of display operation.

a. Display Memory

All of the computer's memory cells can be displayed with the

'display memory' oDeration. The command has the following syntax:

d' '' ('* I segment:offset} span

The operat~lon retrieves a value from a specified memory ceil ara displays ;t

to the user. It uses the computer function 'fetchmO' to perform the retrieve

and 'showmem0' to display the /alue at the memory location. Normally,

during regular program execution, a retrieval from an uninitialized memory

location causes an execution-terminating error in the computer. For

debugging purposes, however, a means was developed to interject a null value

into the retrieve if, in fact, no value is contained at the specified memory

cell. A control variable was used to tell the computer whether to return a

null value (implying the machine was performing a debugger task) or generate

an error (machine under program execution). Control variables are covered in

section IV.D.b. Display Register

All -f 'he cOmDuter"3 -7-gisters :an e /iewed with Thl i sD ta

register' operation. It has the following command syntax:

'd' 'r' segment:offset span

Like the 'display memory' operation, this operation causes similar retrieval

27

I!

Page 31: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

and display operations to be performed, but using the AM's register segments

instead of the memory segments. This operation uses 'fetchro' to retrieve

the value from the register cell and 'showmemo' to display the value to the

user. As in displaying memory, similar provisions are made for the

interjection of a null value if the register cell contains no value.

c. Display Stacktop

The top of any stack segment can be displayed using the 'display

stack' operation. Its command syntax is as follows:

'd' 's' segment

The mechanics of the 'display stack' operation are similar to that of 'display

memory' and 'display register'. It, however, uses 'topstk0' to retrieve the

value stored at the top of a stack segment. One might wonder why the user

is given a free hand in viewing any memory or register cell, but is restricted

to seeing only the top cell in a stack segment. This, in part, is in keeping

with the notion that the resources are a "black box." For a particular state

of the computer, the values stored in the memory and registers 'exist' andare all accessible by the user, typically via a computer program. Values in

stack cells below the top cell conceptually do not exist for a particular

state of the machine. The interactive debugger adheres to this principle.

d. Display Breakpoints

This operation dispiays 311 the :ntries in the Oreakpoint 'able.

The command syntax is as follows:

.d' 'b'

The table has three items per entry: the break number, the memory location

28

Page 32: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

where the breakpoint is set, and the opcodeof the regular instruction. The

table is updated by the 'set breakpoint' and 'remove breakpoint' commands.

e. Display Program Counter

This debugger operation displays what segment the program

counter is currently in and at what offset in the segment it is currently

pointing. Its command syntax is as follows:

2. Set Operations

The set operations are perhaps the most important of all the other

debugger operations since they permit the user to actually change the state

of the computer. The operations give the use the capability to alter the

state of the computer's memory, registers, stacktops and the program

counter. The set operations also include the capability to set breakpoints at

specified memory locations. Demonstrations of the set commands can be

found in Appendix A, Sample Sessions. The functional description of each of

the set operation now follows.

a. Set Memory

The debugger operation 'set memory' gives the user the capability

to store any of the AM's defined values at any memory location, uninitialized

or not. This allows the user to "patch" faulty instructions so that program

testing can proceed uon a user-desired path. Its command syntax is as

"o1 lows:

's' 'im' segment:offset value

This operation uses the computer function 'storemo' to place the desired AM

29

Page 33: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

value into a specified memory location. This operation can indirectly affect

the behavior of another debugger operation, 'remove breakpoint' (which is

covered in detail later). Breakpoints are implemented by substituting

breakpoint opcodes for the actual instruction opcode in the instruction

value. Setting a memory location which contains a breakpoint opcodewould,

in effect, removethe breakpoint opcode,but leave its breakpoint entry in the

break table. For this reason, the 'set memory' operation first retrieves the

value using 'fetchmO' and checks to see if a breakpoint exists at the

location. If there is, the user is given the option of aborting the operation

or confirming it. If the ooeration is confirmed, the breakpoint is removed

from the table and the new value stored into memory. This technique helps

to ensure closure in the debugger operations and to maintain a significant

degree of operation independence between the debugger commands.

b. Set Register

This operation allows the user to set any register location to

any one of the regularly defined values. Its command syntax is as follows:'s' 'r' segment:offset value

It uses the function 'storerO' to store 'value' into the indicated register.

c. Set Stacktop

This operation lets the user store any regularly defined value at

The *CD of any stack segment. Its command syntax s as follows:'s' 's' segment:offset value

This AM implementation contained no function for actually changing the

value at the stacktop without modifying the stack pointer. In other words,

30

Page 34: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

the value at the stacktop can normally be changed only by pushing values onto

or popping values off of the stack, thus changing the stack pointer. To give

the user the freedom to actually alter the value at the stacktop without

modifying (in all but one case) the stack pointer, a new function was added

to the computer called 'storestkO.' The function uses the stack segment

stack pointer to actually store the value at the stacktop.. It does change the

stack pointer when the stack is empty since the stack pointer must be

initialized before the value can be stored.

d. Set Breakpoint

This operation gives the user the capaoility to temporarily halt

program execution to examine and possibly alter the state of the AM. Its

command syntax is as follows:

's' 'b' segment:offset

Breakpoints can be set in any memory location that contains an instruction

value. The operation will self-abort if a non-instruction value is stored at

the memory address (and the user is so informed). The operation also

self-aborts if a breakpoint is currently set at the memory location.

The operation first uses 'fetchmO' to retrieve the value stored at

the specified location, Then the aforementioned tests are performed. If the

value in memory is an instruction and no breakpoint is set at the location, a

new ,reak!oint oDcode 1s computed, The 7egular oDcode ind the memory

address are stored in the table, the new breakpoint opcode is stored in the

instruction, and then the instruction is stored back into the memory location

using the computer function 'storemO.'

31

Page 35: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

The breakpoint opcode is formed by taking the debug breakpoint

code, which in this implementation is '0812', and adding the break number to

the front of the code. For example, if the next open entry in the break table

is at position 4, the break opcode computed would be '4812'. (Currently, up

to eight (8) breakpoints may be set at any one time during the debug session.)

e. Set Program CounterThis operation gives the user the ability to set the program

counter to any location in memory that contains an instruction value.

Restricting the target memory location this way prevents a program

execution error by the computer. In other words, trying to execute a

non-instruction value causes the computer to generate an

execution-terminating error. The command syntax is as follows:V d '*' segment:off set

It the user enters a memory location that does not contain an instruction,

the operation self-aborts and the program counter remains unchanged.

3. Remove BreakDoint Operation

This operation undoes the 'set breakpoint' operation. Its command

syntax is as follows:'r' brknum

t removes breakooints bu 'heir ntry numoer n the break table. it ";rst

cnecks to see if the entry is in the taOle. if it is not, the operation

self-aborts (and informs the user). If it is, the operation uses 'fetchm'

(with the break table entry memory address as a parameter) to retrieve the

instruction value, inserts the regular opcode from the break table into the

32

. . ..N"~ '."% - -. *.-% °% ,

Page 36: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

linstruction value, deletes the break table entry and stores the value back into

memory using 'storemo.' A sample demonstration of this operation can be

found in Appendix A, Sample Sessions.

4. Trace Execution Operations

These operations are used to turn on and off the debug trace flag.

They can also be used to trace a certain number of instructions and return

control to the debugger. After the operation is set, it's is activated by

issuing the 'go execute' command. Sample demonstrations can be found in

Appendix A, Sample Sessions. The following subparagraphs present the

functional details for each of the trace operations.

a. Trace On

This operation turns on the debug trace flag. When the flag is on,

each instruction is displayed before it is executed. The command syntax is

as follows:,t' 'I'

The operation can be disabled at the debugger level by the 'trace off'

command. The operation is also aborted during program execution by

program termination or a breakpoint being encountered. This operation

partially disables the 'trace n' operation and completely disables the 'trace

off' operation.

b. Trace Off

This operation turns off :he JeDug trac2 flag. When zte ;lag ;s

off, the instruction about to be executed is not displayed to the user. Its

command syntax is as follows:It FzF

33

w - '

Page 37: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

This operation also disables the 'trace on' and 'trace n' commands at the

debugger level. It can be disabled by the 'trace on' and 'trace n' commands at

the debugger level.

c. Trace n

This operation causes execution to be traced for n instructions

and then control to De transferred Dack to the deOugger. its command syntax

is as follows:

'r' span

While at the debugger command level, it can completely disable the 'trace

off' operation. After the specified number of instructions are executed, the

debug trace is again turned off. While at the debugger command level, this

operation can be partially disabled by the 'trace on' command and totally

disabled by the 'trace off' command. During program execution, the

operation is disabled by program termination or a breakpoint being

encountered. The number of instructions to be traced can also be overriden

by the 'go execute n' command.

5. Go Ooerations

These commands are used to transfer control from the debugger back

to the computer. Demonstrations of the operations can be found in Appendix

A. 5ample Sessicns. The 'uncticnal details of ?ach of the go operations :r7-

- ~presented n che iollowing subparagrapnls.

a. Go Uncontrolled

This operation transfers control back to the computer so that it

can proceed with program execution. The operation proceeds until a

34

Page 38: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

breakpoint is encountered, a 'trace n' operation is complete or the program

terminates, its command syntax is as follows:

. on

Like the 'go uncontrolled' operation, this operation causes

control to be transferred from the debugger back to the computer for

program execution. However, after n instructions are executed, control is

transferred back to the debugger. Its command syntax is as follows:'g' span

The operation is disabled in program execution by a breakpoint being

encountered, program termination or the completion of the specified number

of instructions. This operation has an indirect effect upon the 'trace n'

operation. Changing the number of instructions to be executed in the 'go n'

command also overrides the number to be traced.

6. Held Operation

This operation lists the available debugger operations and their

command formats. Its has the following command syntax:

IIT

A demcnstration of the operation is shcwn in ADDendix 4, 5amole 5essicns.

0. DEBUGGER CONTROL OF MACHINE EXECUTION

For the debugger to control the execution of the computer requires that

certain "toggles" be added to the machine. Implementing these "toggles"

35

I ...... .....

Page 39: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

translates into defining control variables that the debugger sets and the

computer reads to alter machine execution and flow of control. Figure 4.1

on page 37 is a list of the control variables added to this AM

implementation. A more detailed description of the function of each of the

control variables is presented in the following subparagraph.

1, Debugf lag

This control variable directs the computer to activate and transfer

control to the interactive debugger. It is set on two occasions, the user

specifying the '-d' option at computer "startup" and the program terminating,

normally or abnormally. It is reset when control is passed from the

debugger back to the computer.

2. Debgtask

This control variable keeps the retrieve operations from generating

an error if the debugger attempts to retrieve a value from an uninitialized

storage location. If the storage location is uninitialized, the retrieve

function generates a null value and returns it to the debugger. The

termination of each debugger operation zeroes the variable.

3. Left2do

This variable controls the number of instructions to be executed for

a 'go n' or a 'trace n' debugger operation. This control variable is zeroed if

an execution error occurs or a breakpoint is encountered. It also works in

tandem with the 'debgcntl' control variable.

4. DeDgcntl

This control variable tells the computer that a 'go n' or a 'trace n'

operation is being performed in tandem with program execution. If 'debgcntl'

36

Page 40: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

int debugf lag = 0;/I When == 1, calls the interactive debugger. */

int debgtask = 0;/* When == 1, tells AM that debugger is directly using AM functions fordebugger operations. '/

int left2do = 0;/* When == 1, tells AM how many instructions to do before forkinq backto the debugger. Set by 'go n' and 'trace n' debug ops. "/

int debgcntl = 3;/* When == 1, tetls AM that its execution ;s under control of a 'go n' or'trace n' debug operation. "/

int bre3kfig = 0;/I When == 1, tells AM that breakpoint encountered in its execution andconversionof an instruction must be made. "/

int errorf lg = I;/* When == 0, tells error() that ICSTOP instruction has occurred and notto print certain error messages. */

int dbgtrace 0;/* When 1, sends value at the _pc.val to standard output device, thusperforming a program execution trace. "/

Figure 4.1: Debugger Control Uariables

is set, then the control variable 'left2do' is checked for equality with zero.

This variable is zeroed when the number of instructions has been executed, a

breakpoint occurs, or the program terminates.

37

Page 41: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

5. Breakflg

Breakpoint opcodes are substituted for the regular instruction

opcodes, with the regular opcode being stored in the break table. The

'breakfig' "toggle* is set when an instruction containing a break opcode ,s

encountered. The variable signals the debugger that the instruction must be

restored to an executable form by reinserting its regular opcode from the

4 break taole. 'Breakflg' is zeroea after the instruction is modified. When the

debugger transfers control back to the computer, the modified instruction is

then interpreted and executed.

5. Errorflg

In the AM's current implementation, normal as well as abnormal

program termination cails the error handler to halt execution. This flag is

set by the ICSTOP instruction so that certain error messages are not printed.

7. Dbgtrace

This "toggle" causes the computer to display the instruction to the

user prior to its execution. It is set by the 'trace n' and 'trace on'operations. It is zeroed by a breakpoint being encountered, by the

completion of the 'trace n ' operation, by the 'trace off' operation, or

program termination.

E. ERROR HANDLING IN PROGRAM EXECUTION

The control variables -idded to this -V-1 mDlementaticn. ccuDled with "he

-rror handler mooification, give the aeDugger the means ior 'trapping"

control of program execution. Calling the error handling module now causes

the debugging control variables to be zeroed, the appropriate messages to be

displayed to the user, and a return to the debugger command level so that the

38

Wtb

Page 42: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

user can examine or alter the machine state and, if desired, rerun the

program.

F. MODIFICATIONS TO AM IMPLEMENTATION

The main debugger program files added to this impiementation of the AM

are contained in Appendix C, Debugger Program Files. Some modifications

were also made to the actual implementation of the Ail. These cnanges were

necessary to establisn an interface between the deougger and the AM's

physical resources. The more significant changes are briefly listed below:

* Decugger control varaDles Yer: aded to he AI ;mpiementauon to

provide proper transfer of control between the computer and the

debugger;

e The memory, register and stack retrieve operations were modified to

return a null value to the debugger if the storage location was

uninitialized;

" A breakpoint opcodewas added to the computer opcodedefinitions;

9 A function for storing a value at a stacktop was added to the valueretrieve and store module;

e The original copy-value function was duplicated and renamed for use

in the AM assembler. This was done so as to hide the separate

debugging process from program assembly process;a The displatj-value function was modified lo supprss disDlauina this

ANi's mpiementation details to the user;

. The error handler function was modified to call the debugger upon

program termination, normal or abnormal.

,.3

.-... .. . . . . . . .

t .J X- .a

Page 43: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

V. CONCLUSION5 AND FUTURE WORK

Designing the interactive debugger to make use of the AN

implementation's existing functions again demonstrates the advantage of

formally specifying functional interfaces for computer resources. Because

the interfaces were well defined and built as conceptual "black boxes,"

linking them to the debugger was relatively straightforward. Having the

interfaces being built as "black boxes" also helped to prevent the

.noification "rippie effect" upon the ehavior of 2xisting functions. ,t Is

expected that the addition of an interactive debugger to the AM programming

environment will significantly aid future developers of AN resourcz tools.

Although the interactive debugger significantly enhances the AM

"? programmers ability to interact with the other elements in the AM

programming environment, its interface to the user can be improved. In light

of this, the following areas for continuing research are suggested:

" Implement an in-line assembler for the debugger. This would permit

the user to set storage resources by entering the actual assembler

language statements. This provides a debugger interface at the level

of the assembly language programming abstraction;

" Implement an in-line disassembler for displaying instruction values

:n ,nmortj;

" Implement a graphical user interface to the debugger.

40

-war

Page 44: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

APPENDIX A: SAIIPLE SESSIONS

>am -d

* THE DEBUGGER

HELP OPERATION

Enter letter of operation:

d (isplayj)3(o execute)(list debug ops)

r (emove break)s (et)t (race)

W~Cit & halt exec)

Debuuer Commands

A(lspaq) m'(emoryj), {~Iseg:of fset), span*r(egister), seg:off set, spans0 tack - top only), segb reaks - all)9*( ro rmcuter)

a~ I nl ?n nstrs>)Ils vailable debug commands)*slet) .mlemoryj), seg:offset, val-tgpe, val

Yr(egi ster), seg:of fset, val-type, vals (tacktop, seg, val-type valb(reak), seg:of fsetOW*(program counter), seg:of f set

't1race) T(on) (TRACEz~of I) STARTEDfor n instrs By *60'>

q'(ult debug and halt executi on)Legend: I - or, [I - optional, (> - comment, 0-Must choose an Item.

Enter non-blank char to continue.

DISPLAY OPERATIONS

nter letter of operation: DslyMm

d (isplagc)?(list debug ops)

41

Page 45: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

r (emove break)s (et)t (race)q (ult & halt exec)

Enter one of choices below-

m (emorij)r (egitrs (tck top)b (reek)* (program counter)

Enter one of following:.*- addr value promptW- for current PC val ueW- to dbort the operation:

*OPERATION SPAN

Enter decimal number between 1 and 20or

@to abort the operation:>16

Memaddr Contents

00000000 (V.JNSTR) ISPSHL(V.IILE) 2('L.SAD) (0: 0)

00000001 (Y-UNSTR) ISPSHLY-MIAD) (1: 0)(V-.SAD) (0: 0)

00000002 (V.JNSTR) IFWRITE('LSAD) (0: 0)

00000003 (V..JNSTR) ISPSHLk Y-FILE) 2

V.SAD) (0: 0)00000004 (V.JNSTR) ISPSHL

(VJIAD) (1: 1)('LSAD) (0 : 0)

00000005 ('Vi NSTR) IFWRITE(V..SAD) (0 -.0)

00000006 (V...INSTR) ISPSHL(V..FILE) 2(V...SAD) (0: 0)

00000007 (V.JNSTR) ISPSHL(VJIAD) (1:0)

(V..SAD) (0 : 0)00000008 (VJINSTR) IFWRITE

42

Ka" a .

Page 46: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

(V...SAD) (0 : 0)00000009 (VJINSTR) ISPSNL

(MFILE) 2('L.SAD) (0 : 0)

OOOOOOOA (VJINSTR) ISPSHLN VJAD) (1: 1)'L.SAD) (0: 0)

00000000 (VJINSTR) IFWRITEi(V...SAD) (0: 0)

OOOOOOOC (V-INSTR) ICSTOPOOOOOOOD (VJ4ULL) 0OOOOOOOEW(VJUL)00OOOOOOF V...NULL)0

Enter letter of operation: DslyRgse

d (isplauj)g(o execute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

>d

Enter one of choices below:

m (emoryj)r (egister)s (tack top)b (reak)* (program counter)

Enter one of foll'Owing:-v addr value prompt

- to abort the operation:

Enter decimal segment * between 0 and 0or

9 to abort the operation:>0

Enter decimal offset between 0 and 31or

W to abort the aperation:>0

*OPERATION SPAN

43

Page 47: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter decimal number between 1 and 20or

' to abort the operation:>5

Regnum Contents

00000000 (VNULL) 000000001 (VNULL) 000000002 (VNULL) 000000003 (VNULL) 000000004 (VNULL) 0

Enter letter of operation:

d (isplay)g(o execute). (list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:

m (emorn)r (egister)s (tack top)b (reak)* (program counter)

>5

Enter one of following:"V.- segment value promptW - to abort the operation:

Enter decimal segment * between 0 and 0or

W to abort the operation:>0

Top of Stack:000001FF (VNULL) 0

Disol au BreakontsEnter letter of operation: -

d (isplag)g (o execute)

44

N.

Page 48: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

?(list debug ops)r (emove break)s (et)t (race)q (Wit & halt exec)

Enter one of choices below:

m (emorj)r (egister)s (tack top)b (reak)

A (program counter)

Enter T to continueor

'0 to abort the operation:>1

B REAKPOJINTS

BRKNUM IIEtADDR OPCODE01234567

Enter letter of operation: 01splayI Program Counter

d (isplay)q(a execute)?(list debug ODS)

r 'emove break)s (et)t (race)q (ult & halt exec)

)d

Enter one of choices below:

m (emorv)

45

Page 49: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

r (egister)s (tack top)b (reek)* (program counter)

Enter one of following:T to confirm display pc'0' to abort the operation

>1

PRGM COUNTER In segment 0 at offset 0.

SET OPERATIONS

Enter letter of operation:

d (isplay)g (o execute)(list debug ops)

r (emove break)s (et)t (race)q (Wit & halt exec)

>s

Enter one of choices below:m (emorg)r (egister)s (tack top)b (reek)* (program counter)

Enter one of following:- memaddr value promptW - to abort the operation:

Enter uecimal segment * between 0 and 1or

' P to abort the operation:>0

Enter decimal offset between 0 and 1023or

W@ to abort the operation:13

46

Page 50: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

*~*Entering Value to be Stored

Enter number besides type desired:

1-0001 2 -NAT 3 -INT 4 -CHAR5 -CSTR 6 -MAD 7 -RAD - SAD9 -FILE 10 -INSTR I11-Map 12 -DOP13 -ROP 14- BOP a-bort op

>10

Enter HEX opcodeor

*to abort the operation:>363 1

Entering Operand 1**~Entering Value to be Stored **

Enter number besides tyjpe desired:

I1-5001 2 -NAT 3 - NT 4 -CHAR5 -CSTR 6 -MAD 7 -RAD - SAD9 -FILE 11I-MOP 12 -DOP 13 -ROP

>314- SOP # -abort op

Enter decimal number between

-2147483647 & 2147483647 (no )or

e to abort the operation:>500

Enterng 0 erand *2***Entering Vafue to be Stored *~

Enter number besides type desired:

1 -0001 2 -NAT 3 -INT 4 -CHAR5-CSTR 6- MAD 7 -RAD 8 -SAD9 -FILE 11 -MOP 12 -DOP 13 -ROP14-SBOP 9- abort op

Enter one of following:Y- regaddr value prompt0- to abort the operation:

Enter decimal segment between 0 and 0or

47

Page 51: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

" to abort the operation:>0

Enter decimal offset between 0 and 31or

" to abort the operation:>31

Enter letter of operation:

d (isplay)(o execute)

(list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)>d

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)* (program counter)

Enter one of following:"' - addr value prompt** - for current PC valueW.- to abort the operation:

Enter decimal segment 0 between 0 and Ior

'90 to abort the operation:>0

Enter decimal offset between 0 and 1023or

' to abort the operation:>13

* OPERATION SPAN

Enter decimal number between I and 20or

"0' to abort the operation:>2

Memaddr Contents

48

Page 52: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

00000000) (V-INSTR) 1M-LLR...(V-INT) 500('LRAD) (0:3 1)

OOOOOOQE (VJ4ULL)

Enter letter of operation: StRgse

d (1splay) ego execute?(list debug ops)

r (emove break)S (et)t (race)q (ult & halt exec)

Enter one of choices below:

m (emory)r (egister)s (ack top)b (reak)*(program counter)

Enter one of following:Y- regald value prompt**- to abort the operation:

Enter decimal segment 0 between 0 and 0or

'0 to abort the operation:>0

Enter decimal offset between 0 and 31or

'0 to abort the operation:

*** Entering Value to be Stored

Enter number besides type desired:

1-0001 2-NHAT 3 -NT 4 -CHAR5 -CSTR 6 -MAD 7 -RAD 8 -SAD9 -FILE 10- INSTR I11-MOP 12 -DOP13 -ROP 14- BOP -abort op

>8

49

Page 53: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter one of following:' - stkaddr value promptW - to abort the operation:

YV

Enter decimal segment * between 0 and 0or

9 to abort the operation:>0

Enter decimal offset between 0 and 511or

W to abort the operation:>56

Enter letter of operation:

d (isplay)(o execute)(list debug ops)

r (emove break)s (et)t (race)q(Wit & halt exec)>d

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)* (program counter)

>r

Enter one of following:Y - addr value prompt

- to abort the operation:

Enter decimal segment * between 0 and 0or

9 to abort the operation:>0

Enter decimal offset between 0 and 31or

W to abort the operation:>13

*OPERATION SPAN*

50

Page 54: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter decimal number between I and 20or

W to abort the operation:>2

Regnum Contents

00000001) (V...SAD) (0: 56)OOOOOOOE (VJULL) 0

Set StacktoDEnter letter of operation:

d (1splayj)S(o execute)(list debug ops)

r (emove break)s (et)t (race)q (Wit & halt exec)

Enter one of choices below:

m (emorij)r (eglster)s (tack top)b (reek)* (program counter)

4.>s

Enter one of following:Y*- regaddr value promptW- to abort the operation:

Enter decimal segment * between 0 and 0or

W to abort the operation:>0

Entering Value to be Stored **

Enter number tesides tyJpe desired:

1-0001 2 -NAT 3 -INT 4 -CHAR5 -CSTR 6 -MAD 7 -RAD 8 -SAD9g-FILE 10 -INSTR I11-MOP 12 -DOP

>413 - RP 14 -BOP - abort op

Enter character

51

Page 55: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

orW. to abort the operation:

Enter letter of oeain

d (isplav)g(o execute)(list debug ops)

r (ernove break)s (et)t (race)q Wuit & halt exec)

Enter one of choices bel ow:

m (emonj)r Ikegister)s (acc top)b (reak)* (program counter)

Enter one of following:Y'. segment value prompt*0 to abort the operation:

Enter decimal segment * between 0 and 0or

'0 to abort the operation:>0

Top of Stack:000001 FF (V.CHAR)l

Enter letter of operation: SeBrapit

d (isplay)S(o execute)

* (list debug ops)r (emove oreak)s (et)t (race)q (Wit & halt exec)

Enter one of choices below:

m (emonj)

52

61' Z..~- . ~- ,.,,,*K

Page 56: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

r (egister)s (tack top)b (reak)

V * (program counter)

Enter one of following:v' - memaddr value promptW - to abort the operation:

Enter decimal segment * between 0 and 1or

W to abort the operation:>0

Enter decimal offset between 0 and 1023or

AV" to nort, the operation:>2

Enter letter of operation:

.. (isplay)'.- j (o execute)L . (list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)A (program counter)

Enter one of following:Y - memaddr value prompt'W - to anort. the operation:

Enter decimal segment * between 0 and Ior

@ to abort the operation:>0

Enter decimal offset between 0 and 1023

53

4

J/ " ." ' , ,€ w ' ' " ,' q , r ,' # " , / - ,, " - " - " . " . " . " ( " .' . =

Page 57: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

or'@" to abort the operation:>4

Enter letter of operation:

d (isplay)S(o execute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

>S

Enter one of choices below:

m (emonj)r (egister)s (tack top)b (reak)* (program counter)

Enter one of following:I ' - memaddr value promptW - to abort the operation:

Enter decimal segment * between 0 and Ior

'0" to abort the operation:>0

Enter decimal offset between 0 and 1023or

'W to abort the operation:>9Enter letter of operation:

d ( isplxay~t ),(oexecute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

>S

Enter one of choices below:

m (emory)r (egister)

54

Page 58: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

s (tack top)b (reak)

(program counter)

Enter one of following:- memaddr value prompt

'- to abort the operation:)Y

Enter decimal segment * between 0 and Ior

@ to abort the operation:>0

Enter decimal offset between 0 and 1023or

'0" to abort the operation:>I1

Enter letter of operation:

d (isplay)g (o execute)(list debug ops)

r (emove break)s (et)t (race)q (ut & halt exec)

Enter one of choices below:

m (emorg)r (egister)s (tack top)b (reak)* (program counter)

Enter one of following:v - memaddr value prompt

'0' - to abort the operation:>v

Enter decimal segment * between 0 and I

or"W" to abort the operation:>0

Enter decimal offset between 0 and 1023or

55

II1

Page 59: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

" to abort the operation:

>13

Enter letter of operation:d Y4splay)do execute)

(list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

>S

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)* (program counter)>b

Enter one of following:" ' - memaddr value promptW@- to abort the operation:

Enter decimal segment * between 0 and Ior

'0' to abort the operation:>0

Enter decimal offset between 0 and 1023or

'9 to abort the operation:>12

Enter letter of operation:

d (isplay)(o execute)3 (list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:

m (emory)

56

Page 60: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

r (egister)s (ack top)b (reek)

A * (program counter)

Enter T to continueor

W9 to abort tt operation:

* BREAKPOINTS

ORKNUM !IEMADDR OPCIJDE

2 OOOQOOOC ICSTOP3 OOOOOOOD IMIR...4 00000000 IFWRITE5 00000009 !SPSHL6 00000004 ISPSHL7 00000002 IFWRITE

Enter letter of operation: SePrgaConr

d (isplay)S(o execute)(list debug ops)

r (emove break)s (et)t (race)q (ult & halt exec)

>S

Enter one of choices below:

m (emorg)r (egister)3 (tack + op)J (reek)** (program counter)

Enter one of f ollIowi ng:Y. prog cntr value prompt

9 to abort the operation:

57

. . ....

Page 61: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter decimal segment * between 0 and 1or

'09 to abort the operation:>0

Enter decimal offset between 0 and 1023or

'0' to abort the operation:>16

Sorry, non-Instr at memaddr.Program counter unchanged.

Enter letter of operation:

d (isplag)(a execute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

)s

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)* (program counter)

Enter one of following:ey' - prog cntr value prompt' - to abort the operation:

Enter decimal segment * between 0 and 1or

"' to abort the operation:>0

Enter lecimai offset between 0 dnd 1023or

90' to abort the operation:>2

Enter letter of operation:

d (isplay)

ml" 58

Page 62: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

(o execute)• (list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

>d

Enter one of choices below:

m (emorj)r (egister)s (tack top)b (reak)"(program counter)

Enter one of following:T to confirm display pcW to abort the operation

>1

PRGM COUNTER in segment 0 at offset 2.

Enter letter of operation:;: d (Isplag).

to execute)

(list debug ops)(emove break)

s (et)t (race)q (ult & halt exec)

>8

Enter one of choices below:

m (emorj)r (egister)s (tack top)b (reek)* (program counter)

Enter one of following:X.- prog cntr value prompt0 - to abort the operation:

>v

Enter decimal segment * between 0 and Ior

59

-, -*1.~~~~~~~ ~ ~ Ol ' ' V . " .', ', - , -

Page 63: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

W to abort the operation:>0

Enter decimal offset between 0 and 1023or

9to abort the operation:>0

TRACE / 60 OPERATIONS

Trace On with Go UncontrolledEnter letter of operation:

d (isplaJ)g(o execute)?('st debug ops)

r (emnove break)s (et)t (race)q (Wit & halt exec)

Enter one of following-Decimal number between I and 2.0Tr for 'trace on'0z' for *trace off*

>1 9W to abort the operation:

Enter letter of operation:

d(lsp] ay)3 ( execute)(list debug ops)

r (emove break)S (et)t (race)q (ult & halt exec)

Enter one of choices below:Decimal range btwn I and 20T - uncontrolled go

'W-to abort the operationA4

00000000 (V.JNSTR) ISPSHLSVJILE) 2V...SAD) (0 : 0)

00000001 (V.JNSTR) ISPSHLVJMAD) (1: 0)

V.SAD) (0: 0)

60

Page 64: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

** BREAKPOINT ENCOUNTERED *-

* THE DEBUGGER

Trace Off with Go UncontrolledEnter letter of operation:

d (isplay)(o execute)(list debug ops)(emove break)

s(et)t (race)q (uit & halt exec)

Enter one of following:Decimal number between 1 and 20'T for 'trace on'z' for 'trace off''@' to aort the operation:

t>Z

Enter letter of operation:

d (isplay)- (o execute)

(list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)3 >g

Enter one of choices below:Decimal range btwn I and 20T - uncontrolled go

> @ W - to abort the operation

3-REAKPOINT ENCOUNTERED -

* THE DEBUGGER *

Enter letter of operation:

61

.~~ ~~ . . ... ..

Page 65: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

d (isplay)S(o execute)(list debug ops)

r (emove break)s (et)t (race)q (Wit & halt exec)

Enter one of choices below:

m (emory)r (egister)s (tack top)b (reak)

>* * (program counter)

Enter one of f oIIow ing:!to confirm display pcSto abort the operation

PRGM COUNTER in segment 0 at offset 4.

Go n InstructionsEnter letter of operation:

d (Isplay)S(o execute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:Decimal range btwn 1 and 20T- uncontrollIed goW- to abort the operation

indicated numoer of instrs done.

* THE DEBUGGER*

Enter letter of operation:

62

Page 66: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

d (isplay)

(list debug ops)r (emove break)S (et)t (race)q (Wit & halt exec)

Enter one of choices below:

m (emorg)r (egstrs (tck top)b (reek)* (program counter)

E-nter 3ne of f jI Iowi nq:T to conf irm display pcW to abort the operation

A1

PRGtI COUINTER in segment 0 at offset 6.

Enter letter of operation:

d (isplag)

r (ernovebreak)s (et)t (race)q (uit & halt exec)

Enter one of choices below:

m (emortj)r (egisteOs (ack top)J, (nrak)

A * (program counter)

Enter T to continueor

90 to abort the operation:>1

63

Page 67: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

* * BREAKPOINTS*

BRKNUM 1EIADDR OPCODE012 0000000C ICSTOP3 0000000D IM'LLR..4 00000008 IFWRITE5 00000009 ISPSHL6 00000004 ISPSHL7 00000002 IFWRITE

Remove BreakpointsEnter letter of operation:

d (ispiao)

(itdebug ops)r femove break)s (et)t (race)q (uit & halt exec)

Enter decimal break number between 0 and 7or

*'0' to abort the operation:>0

Breakpoint not In Table.

Enter letter of operation:

d (Isplay)

(list debug ops)r (emove break)s (et)t(race)Wi(ut &' h~alt exec)

Enter decimal break number between 0 and 7or

'0 to abort the operation:>7

Enter letter of operation:

64

Page 68: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

d (isplay)

(ls debug ops)r (emove break)s (et)t, (race)q (uit & halt exec)

I)A

Enter one of choices below:

mn (emory)r (egister)s (tack top)b (reek)

>b * (program counter)

Enter T to continueor

AV to abort the operation:A*

B REAKPOINTS

BRKNUM MEMADOR OPCODE012 0000000C ICSTOP3 OOOOOOQD IMttL..4 00000000 IFWRITE5 00000009 ISPSHL6 00000004 ISPSHL7

Enter letter of operation:gTruhPoga xcto

d (ispla!J)k ~o execute) os

r (emove break)(et)(race)

q (Wit & halt exec)>g

65

Page 69: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter one of choices below:Decimal range btwn I and 20

- uncontrolled go'0 - to abort the operation

>1

BREAKPOINT ENCOUNTERED *

* THE DEBUGGER *

Enter letter of operation:

d (isplay)(o execute).(list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices beow:

m (emor)r (egister)s (tack top)b (reek)* (program counter)

Enter one of following:T to confirm display pc'0' to abort the operation

>!

PRGM COUNTER in segment 0 at offset 9.

Enter letter of operation:

-a (*splay)i o execute)

(list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

>r

66

'. N X*

Page 70: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Enter decimal break number between 0 and 7or

@ to abort the operation:>4

Enter letter of operation:

d (isplay)S(o execute)? (list debug ops)r (emove break)s (et)t (race)q (uit & halt exec)

>g

Enter one of choices below:Decimal range btwn 1 and 20T - uncontroliled go10. - to abor, the ooeration

BREAKPOINT ENCOUNTERED **

THE DEBUGGER *

Enter letter of operation:

d (isplay)(o execute)(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:

m (emory)r eqister)

*3 ktacCk IzOP)b (reak)

I* * (program counter)

Enter one of following:T to confirm dlisplay pc'0" to abort the operation

67

.,* - 4

Page 71: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

>1

PRGM COUNTER in segment 0 at offset 12.

Enter letter of operation:

d (isplay)3(o execute)(list debug ops)

r (emoye break)s (et)t (race)q (uit & halt exec)

Enter one of choices below:Decimal range btwn I and 20T- uncontrolled go

'#'- to abort the operationA1

AM: End of execution 32pc=OOOOOOOC

* THE DEBUGGER*

Enter letter of operation:

d (isplag) e* g~o execute(list debug ops)

r (emove break)s (et)t (race)q (uit & halt exec)

Enter one of following:*I to END DEBUG AND EXECUTIONW to abort ooeration:

Enter letter of operation:

d isplay) ego execute(list debug ops)

r (emove break)s (et)

68S

6, WkxiViIa L

Page 72: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

t (race)q (uit & halt exec)

>9

Enter one of choices below:Decimal range btwn 1 and 20T - uncontrolled go' - to abort the operation>9

Enter letter of operation:

d (isplay)(o execute)(list debug ops)

r (emove break)s (et)t (race)Q (uit & halt exec)

>q

Enter one of followinq:r to END DEBUG AND EXECUTION"9" to abort operation:

>1

Exiting Debugger, Halting Execution.

-I

V. ., % . ,L '.'.'.=..% % . .,.-, .- ,.< -- -. -... ...-.

Page 73: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

APPENDIX B: DEBUGGER COMMAND SYNTAX .SYMBOLS

The following symbols are used to describe the general syntax of all the

debugger comands:

Pd' - DISPLAYpsi - SET or STACK (depending on context)

g' - GO AND EXECUTE

- LIST AVAILABLE DEBUG COMMANDSorl - REMOVE BREAKPOINT

- TRACE EXECUTION

'M - MEMORY

- REGISTER

- PROGRAM COUNTER

segment - RESOURCE SEGMENT NUMBER

offset - SEGMENT OFFSET ADDRESS

span - NUMBER OF OPERATIONS TO BE PERFORMED(} - ONE ITEM IN BRACES MUST BE CHOSEN

- OR

- ON or OK (depending on context)#zf - OFF

brknum - BREAKPOINT NUMBER

Jalue - ATA /ALUIE' val-type- DATA TYPE

70

b . * ~ * - - .~ - ' qN

Page 74: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

APPENDIX C: DEBUGGER PROGRAM FILES

Debugger Header File

/* OEBUG.H: Basic typedef s, defines, and giobais for the AM debugger.

-AM version 1.0 - ZIO-This file is included in all the debugger modules.

*ifndef DEBUG.J1Sdef ine DEBUG..H

4 ~ display ef ines .

*9def ine DISPLMEM 000't def ine DISPLRE13 010Tdef ine r)15PL3STK 0240

sdef ine OISPLERK 030sdef ine DISPLYPC 040

/* go define */

sdef ine GOEXEC 100

/* help define */

Sdef ine HELP 200

/* remove breakpoint define 0/

*def ine REM1OVBRK 300

I" set defines *1

sdef ine SETtIEMR 400xdef ine S:ETREGR 410112T1,nQ 3E75TK 4120,del ire 5ERK40

Sdef ine SELPCk 440

/* trace defines 0/

sdetline TRACEOP 500

/* quit defines '

71

Page 75: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

*defjine QUITDEBG 600

/* atomic types and defines */

Sdef ine UNDEFND -1*def ine TRUE ISdef ine FALSE 0*9def ine MAXBRKS 8 /W Max *of breaks allowed

*def ine MAXEXECS 20 /* Max #instrs to executebefore returning to debug '*/

sdefine MAXLINES 20 /* Max items on debug screen

*def ine MXDECSTR 12 I" Max chars in DECIMAL inputstring; 10 for chars in INTstring, 1 for null stringterminator and I for 4ign ~

sdef ine IIXHEXSTR 5 /* Max chars in HEXIDECJMALinput

string; 4 for chars in INTstring and I for null stringterminator. */

Sdef ine MXINPSTR 2 /* Max chars in PROMPT inputstring; 1 f or char in promptstring and I for null stringterminator. *I

*def ine TRACEON -1 I* Couldn't use I due to spanconf 1 ict.*/

*def ire TRACEOFF 0

typedef int BOOLN /* So named to prevent AM def conflict*/f

typedef structint oprtn;long rngebegn;lon rngespan;

*VAL *Val; /11 VAL typedef in amtype.h '3CL' aoor toD;

OPTION;

typedef structaddress memaddr;short opcdval;

IBREAKS;Sendif

72

Page 76: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Debugger Driver File

I* DEBUG.C: Driver module for the AM debugger.-AM version 1.0 - ZIOO

Changes:

*include *amdef.h m

*include 'amtyjpe.hosin~clude amextern.hosincIUde <set jmp.h>*include 'debugJV'

/H EXTERNAL REFERENCES ~

extern jmp-.uf *-context; /* defined in maino/am.c ~

extern char *stripblko; /* from debugut Lc ~

extern short getopndO; /* from aminstr.c ~

extern short gtopcdexQ; /* allI from debugopr.c M

extern dispmemu;extern dispre ;extern dispIstkU;extern displbrk ;extern displ...pc)extern goexecO;extern lielpO;extern removbrkO;extern setmemrQ;extern setregro;extern setstkQextern setbrk;extern set-pc(extern traceopOextern quitdebgU/* GLOBAL VARIABLES*W/

-PTICN cMegq3Pt;

/*GETRESRC()f unction:

-This function prompts the user for the resource to beoperated upon and returns the key character for theresource indicated.

inter face:

73

Page 77: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

called by:

getopr()

calls:stripbl kO/debugutILc

errors:

chargetresrc()

( char *strptr;char inpstr[MXINPSTR1; I" MXINPSTR 2 w

do{fprintf (stdout,"Enter One Of CtIOiC2s below:\n\n"');fprintf~stdout,:\tNm (emory)\n\t\tr (eq ister)\n-);fpr int ( stdout, \t\ts (tack top)\n\t\tb (eak)\nN);fprintf (stdout, \t\t* (program counter) \n\nml;

fscanf(stdin,"%1sNnpstr);

strptr =stripblk(inpstr);

if (strler~strptr)= 0) (fprint fstdout,mNo choice entered\nl);fprintf~stdout,nOne MUST be specified.\n\nn);

elseswitch(strptr[OI)(

case Wm: returri(m);

case Tr': return(r');

case V5: return(vs);

case bV: return('b);.as '*W: ptr(*

default:

fprintf(stdout,"Inval id response \n");

while (TRUE);

74

Page 78: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

/*GETOPR()f unction:

-This function maps the ascii user operation requestinto an debugger operation code and returns the code.

interf ace:

called by:debug()

calls:stripbiko/debugutl.cgetresrc()

errors:

intgetopr()

{ char *strptr;char irpstr[MXINPSTRJ; /* MXINPSTR 2 ~

dofpr Intf S dout,O\r~nter letter of operation\n"n);

f printf stdout,\t\t? f(list debug ops)\n);,fprintf stdout,n\t\tr (emove break\n\t\ts (et)\n-);tprintfistdout,;\t\tt (race)\n\t\tq (uit & halt exec)\n\nw);tsf sdIs,inpstr);

strptr stripblk(inpstr);

if (strlen(strptr) ==0) (fpr intf (stdout,o~o operation entered.\n");fprintf(stdout,"One MUST be specified.\n\nM);

elseswitch(strptrfOj)

c-ase'3': 3witcnl(getresrq) Itcase Win: if (strptr[O) =- d)

retur n(DISPLMErI);return(SEMEMR);

case 'r': if (strptr[OJ d'return(DISPL-REG);

return(SE TREGR1);

75

Page 79: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

case 's': if (strptrfOl == Vd)return(DISPLSTK);

return(SETSTK);

case Vb: if (strptrO] -- dV)return(ISPLBRK);

return(SETBRK);case '*': if (strptrOJ ==d')

return(DISPL-PC;return(SET.YC);

case 'g': return(GOEXEC);

case ?': return(HELP);

case 'r': return(REriOVBRK);

case 't': return(TRACEOP);

case 'q': return(QUTDEBG);

default: fprintf(stdout,"Inval id operation.\n');

while (TRUE);

/*DEBUG()function:

-This is the driver function for the interactive debug-ger.

interf ace:

p Irafga~ instruction pointerpm program counter value

,Lg) debq....ct varianle 1'cr d2oUqggr Draticn

called by:mair<)/am.c

calls:getopndo/am nstr.cgtopcdexo/debugopr.cgetopro/

76

Page 80: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

disp lmemO/debugopr.cdispirego /debugopr.cdisplstkU/debugopr.cdisplbrko/debugoprcdispiLpc /debugopr.cq oedebugopr.cFel po/debugopr .crl2MOvbrko, debugopr.csetmemro/debugopr.csetregro/debugopr.csetstk. O/debugopr.csetbrk /debugopr.cSeL--.c,/debugoPr. ctraceopQ/debugopr.cguitdeDgo/ debugopr.c

errors:

debug~i,)

MIAD 4m;

( short brknum;OPTION "opt;BOOLN dif fpc =FALSE;

f printf (tot*tt THE DEBUGGERfprintdstdout,\t\t******* N************\n\n);

/* Exchange the debug opcode for the regular opcode*/

if (breakf lg) (brknum =getopnd(i->val[OJ.opcdval)-i->val[Ol.opcdval =gtopcdex(brknum 5;breakflIg =0;

opt &debgopt;

o:pt->oprtn = JNDEFND;opt->rngebegn =UNDEFND;opt->r nespan =UNDEFND;opt->va = NULL;opt->abortop = FALSE;

switch(getopro) (

77

Page 81: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

case DISPLrIEr: displmem(opt);break;

case DISPLREG: displreg(opt);break;

case DIS.PLSTK: dispistk(cpt);break;

case OISPLBRK: displbrk(opt);break;

case DISPL..PC: dispL-pckopt);bre-ak;

case GOEXEC: ~oexec(opt);

case HEL-P heip(opt);break;

case REMOVBRK: removbrk(opt);break;

case SETMEMR: setmemr(opt);break;

case SETREGR: setregr(opt);break;

case SETSTK: setstk(opt);*S*1 tbreak;

case SETBRK: setbrk(opt);break;

case SET-P'C: seLpc(opt);break;

case TRACEOP: traceop(opt);break;

caose QL)!TDEBG: 2uitdebq(CDt);

if ((!(opt->abortop)) && (opt->oprtn ==GOEXEC))

if (dif f..pc) (debugf l ag 0; /* Keeps debuge f rom

being called after setjmpO)in main(O/am.c m/

78

Page 82: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

) long jmp(....context, I);

return;

if ((!(opt->abortop)) && (opt->oprtn ==SEL.PC))dif fpc TRUE;

while (TRUE);

79

Page 83: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Debugger Operations File

/* DEBUGOPR.C: This module contains the SET initialization functionsfor the AM debugger.

-AM version 1.0 - Z100

Changes:

*includ& "amdef.Yinclude *amtype.h"include amexternihminclude "debug.hN

/' EXT ERNAL FUNCTI1ONSq 4/

extern char *stripblko; /* both from debuqutlcWextern str 2hexQ;extern str 2decu;extern addr2SS :n rv-2ad rt)

extern short getopcod2(); /* both from aminstr.c 4

extern short getopndO;

extern char *pmallocO; /* al I from amstate.c ~extern fmallocQ;extern VAL *fetchmoj;extern STATE storemo;extern VAL *fetchrk);extern STATE storerO;extern VAL *topstkO;

extern storestkO; I* an EXCLUSIVE debugger functioni n

in amstatexcW

extern char *amdef sO; /* from amcutl.c N/LCCAL GLOIBAL VARIABLES *I/

.-'CCLN ;nsf get zFrAL3E,; !" When tCrue, usedI to keep getvalueC) i mallowing recursive calls to get-inst()o

l ong -segnum;l ong -..of fset;

Astatic BREAKS brktable[MAXBRKSJ;static short mLslots[IAXBRKS];static short topsiot;

80

le - N '

Page 84: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

static BOOLN mt-init =FALSE;/* Tells if mL-slotsHI initialized. Note theinitialization is done once! (ref 'C' manual)*~/

/GTOPCDEX()function:

-returns the opcode stored in the brktatle at slot 'brknum'.

interf ace:p3 brknumgbrktablet]

called by: '/dtu~aebugs /dbu,copyvalO)/amcutl .cshowmemo/amcut i.c

calls:

errors:

4/

gtopcdex(brknum)short brknum;

if (brktable[brknumJ.opcdval UNDEFND)return( 0);

returr~brktablefbrknuml.opcdval);

/TMGE TRANGEOfunction:

-This function prompts the user for range value.

interf ace:opt~p maxnum

:311 ea J14:

:prnern)displregostr2dec U /debugutlxc

calls:

errors:

81

Page 85: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

g etranqge(opt,maxnum)OPTIO *opt:int maxnum;

{ char '*strptr;char inpstr(MXDECSTRJ;l ong number;BOOLN validnium;

do(fprintf (stdout,\tIt OPERATION SPAN *n"V);fprintf stdout,"Enter decimal number between Ifprintf (stdout," and %d\ni\t\tor\n"maxnum);fprintf stdout,M '@' to abort the operation: \fn");f scanf 1stdin,%s",inpstr);

strptr = tripblk(inDStr);

if (strptroJ == PC&#) (opt->abortop =TRUE;return;

str2d2c(strptr&valI i dnum, &number);if (!validnum)(

fprintf(stdout,"Inval id number entered.\n");cont inue;

if ((umber < 0) II(number > maxnum))(f printf (s tdout,"Number out of range.\n");continue;

opt->rngespan number;return;

while (TRUE);

-This function prompts the user for segment value.

interface:%: (p) mxse gnum

p) abor top

called by:

82

Page 86: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

dipsimem()dispir~gQ

setmemrtj)setregrkOsetstko

seL.Pct)get-raagetsadget-mad()

stri~bico/debugut i.c

errors:-4/

longget-se~rn(abortop, rnxsegnum)

nt rnxsegnum:

( char *strptr:char inpstr[rIXDECSTR];l ong number;BOOLNva licinum;

do{ f prntf (stdout, "Enter decimal segment *between 0 9)

fprintf( stdout,N and %d\n\t\tor\n,mxsegnum);fprintf stdout,"'@' to abort the operation: \n");,fscanf( stdin,*%l0s*,inpstr);

strptr = stripblk(inpstr);

if (strptr(01 == '@') (*abrto =TRUE;

return(O);

3tr 2d Pcf.strotr, &vai ionum.&num)2rif ,!vaiidnum) i

fpr intf (stdout,ilnva lid number entered\nM );continue;

if ((number >= 0) && (number <= mxsegnum))(return(number);

83

Page 87: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

frirntf(stdout,:Segment out of range.\n');continue;

while (TRUE);

/MGET-.OFST()function:

-This function prompts the user for of fset value.

interf 3C2:~P3 mxos f set

bale y:dipsirnem()W-splreo()setmenr()rsetrecjr(setbrkK"

get-radQget-sad)get-mad)

calls:stripblk Q/debugutl.cstr2dec8,/debugutl.c

errors:

longge~ofst(abortop, mxoff set)BOQIN *abortop;l ong mxof fset;

( char Nstrptr;:nar :nDStrfriXOECSTRl;:co nMMDer:

30Ivatidanum;

do (fprintf stdout,mEnter decimal offset between 0")U fpr!*ntf stdout,N and %d\n\t\tor\nM,mxof fset);fprintf stdout,'@, to abort the operation: \n");f scanf (stdin,%10sjnpstr);

84

Page 88: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

strptr =stripblk(;Inpst~r);

if (strptr[Ol 10 [)*aborto p =TRUE;return(O);

str2dec(strptr,&val idnum,&numtoer);if (!validnum) I

fpr intf (stdout,"Inval id number entered.\n");continue;

if ((number < 0) (number > mxof fset))(fpr mntf (stdout, 0Of f set out of range\n");continue;

returnrnumber);

while (TRUE);

/WDISPLM1EMO(function:

-This function performs the 'display memory' operation.interface:

p optx ...numusrseg/am.hx ...pc/am.hx -mem[]/am.hg ...segnUM

-..of tsetxi debgtasklam.h

calIled by:debugo/debug.c

calls:getranqe(fetchm )lamstateac3nowmemi. /amcut L.ccnv 2 adrkc /d eou gu t1. cstr ipbl ko/debugulILcgeLsegm()ge-of sto

errors:

85

Page 89: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

aisplImem(opt)OPTION *opt;

( char *strptr;char inpstr[MXINPSTR];long %;IlOng number;lonq totalrnem =0;BOOLN val idnum;MAD tmpaddr;

opt->oprtn =DISPLIErI;

dotf pr intf (stdout, "Enter One of following\nN);fprintf (stdout M\t\t'v - addr value prompt\nn);fprintf stdout,\ t\t'*' -for current PC value\n");fDr,,ntf( stdout. \t 't'@' -to abort the operation: \n");T .scanf(stdjn, '%ls", npstr);

strptr = stripblk(inpstr);

if (strptrfOl == '1Iopt->abortop = TRUE;return;

if (strptr[OJ == '*') (_s2gnUM= (4pc.val & X-S.EGMSK) >'> )LSEGSFT;-of f set = pc.val & )C.ADRMSK;

~reak ~ '

if (strptr[O] == 've)(..segnum geLsegm(&opt->abortop, -.numusrseg - 1);if (opt->abortop)

return;

-.offset = get-ofst(&opt->abortop,_nemL..seqnumjsize-

f 'opt->abortop)return;

getrange(opt,MAXLINES);

break;

86

Page 90: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

fprintf(stdout,oincocrrect response. \n,);

while (TRUE).

if (opt->abortop)return;

debgtask 1

fpr intf(stdout,ntlemaddr Contents\n\n");

if (opt->rngespan ==UNDEFND)(tmpaddr.val =cnv2addr(~seanum...off Set);snowmem(&tmpaddr,fetchm(&tmpaadr,Q));

else ( 0

Whl((i < opt->rnqesoan) && (.-seanum < -numusrseg)),tmpaddr.val = cnv2addr(_.seqnum,...orf set);shoWM2M(&tCmpaddr,fetchm(&tmp addr,Q));

-Of fSt+-:if (-offset == .inemL..segnumjsize)

-.offset =0;,) .segnujm++;

debgtask 0;

/,"D1SPLREG()function:

-This function performs the 'display register' operation.

interf ace:p) opt

,., nurnreqsea/amih

S..segnum-..of I set

called by:debugo/debug.c

calls:

87

Page 91: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

fetc roamstate.cshowem()/amcutt.c

cnv2addr( /xebugutl.cstripblko,/ debuguti .c

errors:

dispireg(opt)OPTION *opt;

( char *strptr;char iripstr[MXDECSTR1;long i-;l ong number;ianq numregs=O0;BOOLN val idnum;RAO tmpreg;

opt->oprtn =DISPLREG;

do{f printf (stdout,MEnter one of f ol lowing:\n");fprintf stdout M\t\t'v' -addr value promptn);fprintf stdoutM*\t\t'@ - to abort the operation: Wfl);f scanfistdinMkls',inipstr);

strptr = stripblk(irpstr);

if (strptr[OI =='@) (opt->abortop =TRUE;return;

if (strptr[OI =v' SO-.segnum geLsegm(&opt->abortop, ....numregseg - 1);

if (opt->abortop)return;

- ) ..-offset =ge-o fst(&opt ->abortop,-reg..segnumi.num

if (opt->abortop)return;

getrange(opt,MAXL NES);

88

-'1 - -.

Page 92: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

break;

fprintf(stdout,oincorrect response\nm);

while (TRUE);if (opt->abortop)

return;debgtask =1;

fprintf(stdoutMRegnum Contents\n\nm):

if (opt->rngespan =UNDEFND) ( ,..ofe)tmpreg.val =cnv2addr( segnumofse)showmem(&tmpreg,fetchr( &tmpreg,Q));

else(i=0;

while((i < opt->rxqespan) && (...segnuim <....nmreqseg))tmpre§.val = cnv2addr(-segnum-of fset);showmem(&tmpreg,f etchr(&tmpreg,Q));i++;

if (-..offset == .. regL-segnuml.num){-offset =0;

) ....segnum.+;

debgtask =0;

/*DISPLSTK()f unction:

-This function performs the 'display stack' operation.

interf ac2:~p Ot~x -mmstkseg/am.n(x ...stk[I/am.h(g)segnum

(x debgtask/am.h

called by:debugo/debug.c

89

Page 93: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

calls:cnv2addrQ/debugutl.cstripblko/debugut I.c

errors:

disp stk(opt)OPT ION *opt;

{ char *strptr;

long stksize =0;i t i;SAD stktop;

opt->oprtn =DISPLSTK;

do{f printf ( stdout, "Enter one of following:\n");fprintf stdout,"\ttV' segment value prompt\n");fprintf stdout,"\t\t'@ - to abort the operation: \n");fscanf stdi,"%sM ~inpstr);

strptr = stripblk(inpstr);

if (strPtr[0] == 00' (opt->abortop = TRUE;return;

if (strptr[0J ==V)(-segnum =geLsegm(&opt->abor top,

break; -..numstkseg - 1);

f pr intf (stdout, "Incorrect response.\n"):

whiile (TRUE);

if (opt->abortop)return;

ciebgtask =I;

-.off set _stk[_segnuml.size - 1;

90

Page 94: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

stktop.val cnv 2addrC...se~num,of f set);

fprintf(stdout,*Top of Stack:\n");showmem(&stktop,topstk(&stktopQ));

debgtask = 0;

/GDISFLBRK()funct ion:

-This function performs the 'display breaks' operation.

interf ace:(p) opt(g brktable[]~g mLinit~g mLslots(]

gtopsiots

called by:debugo/ debug.c

catils.stripblk0/debugutt.camdef s( /amcutl .c

errors:

displbrk(opt)OPTION *opt;

( char *strptr;char inpstr[MXINPSTRI;short 4

opt->oprtn = DISPLBRK;

do(fprintf (stdout,"Enter 'l' to continue\n\t\tor\n");fprintf (stdout,.'@' to abort the operationc \n");fscanf( stdin,.%ls",inpstr);

strptr =stripolk(inpstr);

if (strptr[O1 ==POO) (opt->abortop =TRUE;

) return;

if (strptr[01 '1')

91

S..- -VS V S - .V -M

Page 95: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

break;

fprintf(stdout,oincorrect response.\n");

while (TRUE);

if (Imt-init) 'for (0 = OJi < MAXBRKS; ..

mt-slotsfil =;brktablelii.memaddr =0brktable iI.opcdval =UNDEFND;

topslot = MAXBRKS - 1;mt-init =TRUE;

tprintf( stdout,'\t\t"*I4\fprintf( stdout,"\t* BREAKPOINTS

fprintf (stdout,"BRKNUrI t1EMADDR OPCODE\n");

for(i =0; i < MAXBRKS; i++){if (brktablei1.opcdval =UNDEFND)

elsf fprintf (stdout,*%6d\n",i);f pr intf (stdout,*5%6d i);

*fprintf(stdout,"%08 lx 00, brlctable[Qi.memaddr);fpr intf(stdout,M%s\n*, amdefs(brktable[ il.opcdval ));

IWDISPLPC()function:

-This function performs the 'display program counter'operation.

interf ace:k.p) opt

4cx/am.l

g of Iset

called by:debugo/debug.c

calls:str ipblIko/debugut L~c

92

Page 96: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

errors:

dispL-pc(opt)OPTION *opt;

char *strptr;char inpstr[MXINPSTR1;

opt->oprtn =DISPL.PC;

o{ fprintf(stdout,"Enter one o followinq:\n");f pri!ntf(stdout,*\t\t'!' to confirm display pc \n");frprintf(stdout M\t\t'@' to abort the operation \n");f scanf ( stdin,uilsw,inpstr);

Strptr =stripblk(inpstr);

if (strptr[O] ==@W) (opt->abortop = TRUE;return;

if (strptr[OJ= T-segnum = (-pc.val & X-SEGMSK) >> )CSEGSFT;-of rset = 4pc-vai & XCADRMSK;fprintf(stdout,"\n\t\tPRG1 COUNTER in segment %Id ~

- ..segnum);fprintf(stdout,"at offset %I d.\nM ..offset);return;

f pr intf (stdout, "Incorrect -r2sponse.\n");

while (TRUE);

ITMGOEXEC()function:

-This function initiates the rest of the DrOMDtS f or thego execution' operation.

inter face:

I p optI left 2do/am.h

XdebgcntI/am.h

called by:debugo/debug.c

93

Page 97: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

calls:str2dec /debugutl.cstripblk()/debugutl.c

errors:

goexec~opt)OPTION *opt;

{ char inpstrrlXDEC.-TRl;char *str;,BOOLNvalidnum;I c~ng number;

oot->oprtn = GOEXEC;

doif printf (stdout,'Enter one of choices below:\rV);f printf ( stdout,M.\t\tDecimal range btwn I and %d\n,MAXEXECS);fpri~ntf (stdput,,\t\t'!4 - uncontroled go\no);fprintf (stdcut, \t\t'9' - t o abort ',he operation\n\n");fscanf (stdin,"%l~s",inpstr);

str = stripblk~inpstr);

if (str[O] == '@') (opt->abortop = TRUE;return;

if (str[O] == 'I')return;

str2dec(str,&val idnum,&number);if (ivalidnum) (I

fpr intf (stdout, "Invalid number entered.\n");continue;

if "((numter < ( number > ',AXEXECS))forintf( taour. '\Jumter out orflq. 1,nae');

lef t2do number;,debgcntl = 1;return;

94

Page 98: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

while(TRUE);

/*HELPO/fucion:

-This function displays the debugger commands available.interfac2:

(P) opt

called by:debugo/debuq.c

v CallIs:errors:

OPTiON *opt;

othar strIIXINPSTRI;J. opt-> rt HL

fprintf stdout,m\t\t Debuqaer Commands \n)

fprintt sdout'd'(isplaq)\tm'(emory), (~jseg:of fset), span\n");fprint stdout,O \tr (egister), seg-off set, span\nm);fprintf stdout,O \t's 1tack - top oni g) seg\nw);fprintf st out,* \t'b'(reaks _ al l)\nNJ;,fr intf stdout," \t'N'Pr m counter)\nm);printf stdout'( o) nt rf<instrs>\n*);

fpit tot '~ist available debug commands)\n)-fprIntf stdout,"'s' et) \tmW(emory), seg:offset, val-type, valnw);printf stdout," \t'r'(legister), seg:offset, val-t~e, val\nm);

fprintf stdout,M \s( tacktop, seq, valt te, va n)*fprintf stdout,M \MWbreak), seg:o fset\nVfprintf stdout," \t'*'(proqram counter), seg:offset\n");

fprintf st out,M \t'z' M(onf) TAE\n");fprintf stdout," \tz( fo n !nt S TABYD\n)fDrintf stdcut."tn M for and iat BY cut On)\n" ;orntf stdout,",Vit eno: - 1lal -2xejt'cflA n );-czmnrprntf(staout, u -qna rs o O Dsea n ai . <> .n");~

fprntr StdoutEne ni-"s onlana ito cont\n");fscantf (stdoun,Z"tr)nn; akca t otnen

} safsdn,%st)

- 95

Page 99: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

-At84 691 DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR ANd ABSTRACT 2/?2MRCHINE(U) NAVAL POSTGRADUATE SCHOOL MONTEREY CA

7UNCLASSIFIED S ITU U 7F/G 12/5 Nt

EhhhhhE0 10hhhhhE1EhhhhEEohhhhhEI.Esmmmms

Page 100: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

L23MM

1-1125 11-1 . 11 6

MICROCOPY RESOLUTION TEST CHART

NATIONAL BUREAU OF STANDARDS 963-A

Page 101: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

/TMRErIOVBRK()f unction:

-This function removes a breakpoint at a specifiedmemory location.

interface:P)optx debgtaslc/am.M

gm~initgbrktablel1g tpslotmtsIots1

x Q/am.11

calIlIed by.debugO/dabu.c

calls:stripolkO Idebugutl.cstr2dec()/debuqutl.cfclmQ /amstate.c

storem ,/amstate.ccnv 2addr( /debuqut i.c

errors:

removbrk(opt)OPTION *opt;f char *strptr;

char irpsfrMXDECST RI;long numrber;BOOLN val idnum;VAL~v;MAD m;BREAKS *brkptr;

opt->oprtn =REMOVBRK;

dofprintf stdout,"Enter decimal break number )fpr intf stdout,"between 0 and %d\n\t\tor\n,MAXBRKS- 1);fprintf stdout N'' to abort the operation: \n");fscanf 1stdinN%4s~irwstr);

strptr =stripblk(inpstr);

96

Page 102: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if (strptrOl =@'boa)

opt->abortop = TRUE;

str2dec(strptr &val idrum,&number);if (!validrim) I

fprintf(stdout,*lnva lid number entered.\n");continue;

if ((number < 0) 11 (number > (MAXBRKS - 1)))(fprintf(s tdout, 'Number out of range.\n");cont inuie:

opt->rngebegn =number;break-,

while (TRUE);if (Imtinit)

for 0(= 0;; < MAXERKS; i++)mt-slotsfi iibrktablefi].memaddr =0;brktable[ii.opcdval =UNDEFND;

topsiot =MAXBRKS - 1;mLint= TRUE;

if (topsiot > MAXBRKS - 2)(fpr intf(stdout,"Break Table empty\n");return;

if (brktable[opt->rngebegnl.opcdvaI == UNDEFND)(fprintf(stdout,Breakpoint not in Table\n");return;

debgtask =1:

brkptr = &brktable~opt->rnqebegnl;m.val = brkp tr->memaddr;v= fetchm(&M,Q);v->instrval.valf 0J.opcdval =brkptr->opcdval;storem(v,&m,Q);brkptr->memaddr = 0;brkptr->opcdval =UNDEFND;mt-slots(.+topslot] opt->rngebegn;

97

Page 103: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

debgtask =0;/*TRACEOP()

f unction:-This function initiates the rest at the prompts tar thethe 'traceop'operation.

interf ace:poptx ~ debqcntl/am.hxlet t2do/am.h

called by:debugo/debug.c

calls:stripblk ldebugopr.cstr2decS/debugopr.c

errors:

traceop(opt)OPTION *opt;

( char *strptr;char inipstr[IXDECSTRJ;int 1;Ionq number;BOOLNvalidnum;

opt->oprtn =TRACEOP;

do(fprintf stdout,"Enter one at al lawing\n");tprintf stdaut,\t\tDecimal number between I and U);

fprintt stdout dWnWMAXLNES);fprintt stdout,"\t\t' tar 'trace on\n*);fpr intf stdaut,\t\t'z' far 'trace of t \n");tprintf stdaut,\tMtO to abort the aperatiarr\nw);fscanf stdin,*%10sH~inpstr);

strptr = stripblk(inpstr);

if (strptr[0I ='@90 (opt->abortop =TRUE;

) return;

if (strptr[01 I) (

98

Page 104: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

opt->rngespan =TRACEON;dbgtrac2 = 1;debgcntl =0;return;

if (strptrfOl = z')(opt->rngespan = TRACEOFF;dbgtrace =0;deggcntl -0;return;

str2dec(strptr,&val idnum,&nurnber);

if (Ivalidnum) (fprintf(stdout,"lnval id number entered\nm);continue:

if ((umber < 1) 1Ji (number > rIAXLINES)){f print f(s tdout, "Number out of range\nl);continue;

left2do =number;dbtrace =1;

deI.5gntl = ;return;

while (TRUE);

/NQUITDEBG()function:

-Upon user conf irmation, this function exits the debug-ger and halts program execution.

interf ace-(p) opt

called by:debugo/detuq. c

calls:stripblko/debugopr.cexit()

errors:

99

Page 105: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

OPTOI ~opt;

o car *strptr:char iripstr[MXINPSTR1;

opt->oprtn = QUITDEOG;

do(fprintf(stdout,"Enter one of followirn);nfprintf(stdout,M \t\t'!' to END DEBUG AND EXECUTION\no);fpr intf( stdout. \tMt'' to abort operatiorr\n");fscanf(stdin,O%lsM~inpstr);

strptr = stripblk(inpstr);

if (strptrO1 = W'@'opt->abortop = TRUE;return;

if (strptr[Ol ){f printf (stdout, Exiting Debugger, Halting Execution.\")2Xit (0);

fprintf(stdout,"Inicorrect response.\n");

while (TRUE);

/*GET...BOOL()funct ion:

-This function initializes the boolval structure, promp-ting the user to enter the actual value part of thestructure.

interf ace:

pabortop

C31led bti:*aetvaiue()

calls:str ipb Iko/debugutlI.c

errors:

100

Page 106: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

gebool(v,abortop)

BOOLN *abortop;

( char *strptr;char irpstr[MXINPSTR1;

v->boolval.type = _0 ;

do(fprintf stdout,mEnter letter of uour choice\nm);fprintf (stdout,\t\tt(rue)\n\t\tf( alse)\ni;-fprintf (stdout, 4\t \t@(abort operat ion\nm);f scanf( stdin.M%ls',inpstr);

strptr =stripblk(inpstr);

switch(strptrf 01)case I': v->Ooolval.val = I

return;case 'f: v->boolval.val = f';

return;case ': *'abortop = TRUE;

return;default: fprintf(stdout,*Bad response.\n");

while (TRUE);

/*GETJ.JAT()function:

-This function initializes the natval structure, promp-ting the user to enter the actual value part of thestructure.

interface-

Pabortop

callIed by:getvaluei)

calls:stripblkO,/debugutl~cstr 2dec) /debugutt.c

errors:

101

Page 107: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

getnat(v,abortop)VAL *v;

BOOLN *abortop;

l ong number;bCLN vat idnum;char I*strptr;char inpstr[IXDECSTR],v->natval.type =V.JJAT;

dofprintf fstdout, T Enter dec imalI number betW22n\n*);fpr intf (stdout,*\t\tO and 65535\nor\n*);fprintf stdout *\t\t'@' to abort the operatiorv\n*);fscanf( stdin,%10~s*,inpstr);

strPtr =stripblk~npstr);

if (strptr[O = W@)*abortop =TRUE;return;

str2d2c(strptr,&vat idnum,&number);

if (Ivalidnum) (fprintf(stdout,"Irval id number entered.\n");continue;

if ((number < 0) 11 (number > 65535))(fprintf(s dout,*Number out of range.\n");continu e;

v->natvat.val =number;return;

white (TRUE);

*G~ETJNr(

funct ion:-This function initiatizes the intval structure, promp-tinig the user to enter the actual value part of thestructure.

interf ace:

Pabortop

102

Page 108: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

called by:getvalue()

calls5:stripblkQ /debuguti.cstr2decO/debugutl.c

errors:

get-int(v.abor top)VAL *v;BOOLN *abortoo:

l ong number;60 IN val idnum;char *strDtr:-nar InostrrlXDECST9.1;

v->intval.type =VIJNT;

do{f Dr intf (stdout. 'Enter decimal number between\n\n")-;rprintf(stdout,"\tM -2147483647 & 2147483647 (,no ','):n");fpr intf(stdout."or\n\t\t'@' to abort the operat ion:\n"),fscant (stdin,M%1 sM, npstr);

strptr =stripblk(irpstr);

if (strptr[OJ == ) (*abortop = TRUE;

) return;

str2dec(strptr,&va I idnum,&number);

if (Ivalidnum) (fpr tntf(stdout, TInva lid number entered\n");continue;

v->1ntvaiyval =numoer;,return:

while (TRUE);

/*GET-CHAR()function:

-This function initializes the charval structure, promp-ting the user to enter the actual value part of the

103

Page 109: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

structure.

interf ace.

P3 abortop,called by:

getvaiue()

calls:getcharo/ *system*

errors:

geLchar(v,abortop)

BOOLN *abortop;

chiar Chi;v->charval.type = &CHAR;

fprintf( stdout. mEnter character\n\t\tor\n");fprintf~sdout,*@' to abort the operation:\nn);ch = getcharo; /* MUST be done to CLEAR LAST NEWLINE CHARACTER

user typed. M

ch =getcharO;

if (ch: == W) (*abortop =TRUE;return;

v->charval.val =ch;return;

/*GET-CSTR()f unction:

-This function initializes the cstrval structure. ' romD-tithe user to enter the actual value part of the

structure.

interf ace:

abortop

called by:

104

Page 110: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

getva IueC'

cal:Pmal locOlamstate.cgetcharo! *system*getsO/ *system*strcpy)/ system*

errors:

vLcstr(v,abortop)BOOLN Wabortop;

(char str[8lJ;char *ptr;char *ge-tsO;char ch.

v->cstrval.type = &CSTR;

do fprintf (stdout,'Enter char string (max 80 chars)\n");fprintf(stdout,M\t\tor\n'@' to abort the operatior\nN);ch = getctiaro; /* MUST be done to CLEAR LAST NEWLINE

character user typed. W

ptr =gets(str);

if (ptr 1= NULL)if (str[O1 = '09

*abortop = TRUE;return.

v->cstrval.val =pmalloc(strlen(str) +1);strcplj(v->cstrval.val, str);return;

fprintf(stdout,"Error in reading strinq.\n");

while (TRUE);

/*GETJIAD()funct ion:

-This function initializes the madval structure, promp-ting the user to enter the actual value part of the

105

Page 111: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

structure.

interf ace.

1p3 atortopcalled by:

getvalIue()

cal:cnv2addrO,/debugutI.c

get-segrt )

errors:

q~tmad(v,abortop)

BOOLN *abortop;

{char *strptr;char irnpstrIIXINPSTRJ;

>4long ..S2 mm;long -ot~set;

v->madval.tupe =VJIAD;

do fprintfl stdout,NEnter one of f ol lowi ng:\nw);fprintf stdout M\t\t'v' -memaddr valFue prompt\nv);fprintf stdout,'\t\t'O' -to abort the operation: \nlM);fscanf( stdin,mklsM,inpstr);

strptr = stripblk(inpstr);

if (strptr[OJ == 00 (*abortop TRUE;utreturn;

if (strptrO] == 'V)-segnum =get-segm(abortop..nmusrseg- )

if (*abortop)return;

-..offset get-ofst(abortop,...mem-segnuml.size - 1);

A 106

Page 112: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if (*abortop)return:

v->madval .val =cnv2addrC...segnum, -offset)-,

return;

fpDr int f(stdout, Incorrect r2sponseAn");

while (TRUE);

/*E-RDfunction:

-This function initializes the radval structure, promp-ting the user to enter the actual value Dart of thestructure.

interf ace:(p vp) aoortop

called by:getvalu2()

calls:cnv 2addro/debuguti.cstripblk()/debugti.cgetsegm )

errors:

getrad(v,abortop)

BOOLN *abortop;

( char *strptr-,char inpstrfrlXINPSTRI;ong -seanum:.long -ofrfset;

v->radval.type = V...RAD;

do( fprintf(stdout,Enter one of following:\n');fprintf (stdout,"\t\t'v - regaddr value prom pt\n);,fprintf(stdout,'\t\t'@ to abort the operat ion: \n");

107

KI P(

Page 113: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

f scanf (stdin,%1s,!npstr);

strptr =stripblk(inpstr);

if (strptr[O1 = '@') (*abortop: TRUE;return;

if (strptrOI = 'V)(...segnum geLsegm(abortopmnmregseg - 1);if (*abortop)

return:

-..offset=- geLofst(abortop.regLsegnum.num 1 );if (*abortop)

return;

v->radval.val =cnv2addr(..segnum, -..offset);

return;

fprintf(stdout,mlncorrect response.\nn);

while (TRUE);

/HGET-.SAD()* function:

-This function initializes the sadval structure, promp-ting the user to enter the actual value part of thestructure.

interf ace:

Pabortop

called by:getvalue()

calls:cnv2addrO/debugutlI.cstripblkOfdebugtI.cgeL.segm)ge-of st()

errors:

108

Page 114: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

get-sad(v,abortop)V AL *v:BOOLN Wabortop;

{ char *strptr-char irpstr[MXINPSTRI;long ...segnum;long -of Tset;

v-sadval.tyipe =V..5AD;

do fprintf (stdout.dEnter one or f ollowing\n");fprintfgstdout,ff\t\t'v - stkaddr value prompt\nM ;fprintf stdout,"\t\t'@' -to abort the operation: \n);f scanf(stdimffi%ls~,npstr);

strptr = stripbllc(inpstr)-;

if (strptr[O] =0W)(*abortop TRUE;

return;

if (strptr[OJ = 'v)(-.segrum geLsegm(abortop, ...nmstkseg - 1);if (*abortop)

return;

-offset = geLofst(abortop..stkL-segnuml.size 1 );

if (*abortop)return;

v->sadvaltval =cnv2addr(..segum, -off set);

return;

fprintf(stdout, Incorrec+t reSponse\nM);

while (TRUE);

/*GET..FILE()funct ion:

-This function initializes the f ileval structure, promp-ting the user to enter the actual value part of the

109

11,1111, p i ll',

Page 115: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

structure.

interf ace:

1abortop

called by:getval ue()

calls:stripblkQ/debugutl .cstr deo/eugt~

errors:

geLf i le(v,abortop)VAL 'v;BOOLN *abortop;

I lon number;BOO-N validnum;char *strptr;char inpstr[IXDECSTRI;

v->f ileval.type =V.IILE;

do (fprintt stdoutMoEnter decimal number 0);tprintf stdout,"between 0 and %d\n\t\tor\n...numf lies -1);

fprintf stdoutM '0' to abort the operatiorv\nm);fS ;,n~stiN~llsOuinpstr);

strptr = stripblk(inpstr);

if (strptr[0l=Iap@) (*abortop =TRUE;return;

str2dec(strptr,&val idnum,&number);

if (!validnum)fpr ,ntf(stdout, Invalid number entered.\n");continue;

if ((number < 0)11I (number > ...numf iles - 1))(fprintf(s tdout,"Number out of range.\n");continue;

110

Page 116: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

v->f ileval.val = number;return;

while (TRUE);

I K(3ETI N5 TOCfunctijon:

-This function initializes the instrval structure, promp-ting the user to enter the actual value part of thestructure. It resets global file var 'insLget' to FALSEjust before function termination.

interf ace:

~p abor top

called by:getvalue()

ClI:getopndolaminstr.cgetopcodeo/am instr~cgetvalueO /* Note that this is a recursive cal I/

pmal ocO/astatexcstr2hexQ/debugut l.cstripblku /debugut l.c

errors:

eLinst(v,abortop)BOQLN *abortop;

I long number;BOOLNvalidnum;char *strptr.,char inpstrrlXHEXSTRI;int i:

VAC!Ap;

v->instrval.type =VJNSTR;insLget =TRUE;

do (f pr intf (s tdout, "Enter HEX opcode\n\t\tor\n");

Page 117: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

fprintf(stdout,'@' to abort the operationr\n");f scanf (stdin,"%4sM~inpstr);

strptr =stripblk(inpstr);

if (strptr[O1 == W)(*abortop TRUE;inst-get =FALSE;return;

str2hex(strptr,&valI idnum,&number);

if (Ivalidnum) (fprintf stdout,"inval id number entered.\n");continue;

if ((umber < 0) 11I (number > Oxffff)){fIprintf(stdout. 'lnva lid opcode\n");continue;

if (getopcode(number) ==ILDBG){fprin tf stdout,:Breakpoint opcode entered. \n");fpr intf stdout , Opcode can't be 2ntered.\n\n");continue;

jgetopnd(nurrber);Y->instrval.val = (VAL*) pmal loc(sizeof(VAL)* j);v->instrva.val[OJ.opcdval =number;p =v->instrval.val;

for (i =1; i < j; i++)(fprintf~stdout*\t\t ""Entering Operand *%dM"i);

fpritf~sdout* **\nN)getvalue(&p[i), abortop);

if (*abortop){Inst-get FALSE;return.

inst-get FALSE;return;

while (TRUE);

112

Page 118: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

/*GETJIOP()f unction:-This function initializes the mopval structure, promp-

ting the user to enter the actual value part of thestructure.

inter fac2:

~p3 abortopcalled by:

getvaiue()

calls:str2hexo/debuguti.cstripblko/debugutl.c

errors:

get-mop(v,abortop)VAL Iv;,BOOLN *abortop;

BOLNvaidum;char Wstrptr;char inpstr[MXHEXSTRJ;v->mopval.type =VJIOP;

doprintf stdout,"Enter HEX number )fprintf stdout,"between 0 and ffff\n\t\tor\nn);fprintf stdout,n3 @' to abort the operation:\n");fscr stIn. %4sM,inpstr);

strptr =stripblk(inpstr);

if (strptr[OJ '=0W) (*abortop =TRUE;return;

str2hex(strptr,&val idnum,&number);if (Ivalidnum) I

fpr intf(stdout, TInval id number entered\nN);continue;

113

pA

Page 119: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if ((number < 0) (number > 65535))(fprintf(s dout,"Number out of range\nM);continue;

v->mopval.val =number;return:

while (TRUE);

/*GETDO(f unct ion:

-This function initializes the dopval structure, promp-ting the user to enter the actual value part of thestructure.

interfac2:

p abortop

called by:getvalue()

calls:str2hexQ/debugutl .cstripblko/debugutl.c

errors:

geLdop(v,abortop)VAL *v;BOQIN T*abortop;

I long number;BOOLN val Idnum;char *strptr;char irpstr[MXHEXSTR1;

v->dopval.'Lupe =V..20P:

do(fprintf stdout,nEnter HEX number )f printf( stdout,"between 0 and ff f f\n\t\tor\n");fprintf stdout "@' to abort the operatiorv\nw);fsanf IstdinV%4s~,irpstr);

strptr stripblk(inpstr);

114

,~Mmi

11

- --

Page 120: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if (strptrOl @') {*abortop TRUE;return;I

str2hex(strptr,&val idnum,&number);

if (!validnum) {fprintf(stdout,'invalid number entered.\n');continue;

if ((number < 0) 11 (number > 65535)) (fprintf(s tdout,*Number out of range.\n);continue;I

v->dopval.val = number;return;}

while (TRUE);

/*GETROP()function:

-This function initializes the ropval structure, promp-ting the user to enter the actual value part of thestructure.

interf ace:

abortop

called by: ugetvalue()

calls:str2hexO/debugutl.cstripblkO/debugutl.c

errors:

get-rop(v,abortop)VAL *v;BOOLN *abortop;

long number;BOOLN validnum;

115

Page 121: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

char *strptr;,char inpstrUIXHEXSTRI;

v->ropval.type= V...ROP;

dofprintf(stdout,'Enter HEX number )f printf (stdout,"*between 0 and ffff\n\t\tor\n):-fprintf (stdout,'@' to abort the operation~no);f scanf (stdin,"%4s',inpstr);

strPtr =stripblk(inpstr);,

if (strptrfOl==V(*abortop =TRUE;return;

str2hex(strptr,&vaI ianum,&number);

if (!validnum)fpr intf (stdout,"invalid number 2ntered.\n");continue-,

if ((number < 0) 1(number > 65535))fprintf(sdout,*Number out of range.\n);continue;

v->ropvalval =number;return;

while (TRUE);

/*GET..BOP()f unction:

-This function initializes the bopval structure, promp-ting the user to enter the actual value part of thestructure.

:,nterfaC2:

*p abor top

called by:getvalue()

calls:str2hexo/debugut l.c

116

Page 122: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

stripblI ko/debuguti.c

errors:

get-bop(v,abortop)VAL Tv-;BOOLN *abortop;

I on number;

char *strPtr;char inpstrtlXHEXSTRl;,

V->bopval.type = ..BOP;

do (f pr intf (stdout, "Enter HEX number )f Drintf (stdout, "between 0 and 'ffff\n\t\tor\'n");fprintf (stdout,"W@ to abort the operationr\n');f scanf MsdinI34s,inpstr);

strptr = stripbik(inpstr);

if (strptr[O] == W@) (*abortop =TRUE;return;

str2hex(strptr,&val idnum,&number);

if (!validnum)fpr intf (stdout,M lnva lid number entered\nM);

if ((number < 0) 1(number > 65535))fprintf(s tdout,"Number out of range.\n");continue;

V->boDVa1.Val = number;return;

while (TRUE);

/NGETVALUE()function:

-This function prompts the user for value of type VAL

117

Page 123: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

which can be placed into memory, a register or thestack.

interf ace:

p abor top

ca IlIect by:setmemr()setregr()setstk()get-inst() /* Note -- indirect recursive call! M

calls:str2deco/debugut l.cstripblko/debugut l.cgeL-bool()geL-nat)get-into)ge'tchar()geLcstr~geL ad)geL ad)ge radgelLsadgeLfilHege~rnop)tgeLdmopget'ropgeLbop

errors:

getvalue(v,abortop)

BOOLN *abor top;

(char *strptr;char jnpstrfr1XDECSTRI; /* M'XDECSTR 12 /nt number:

BOCLNvalidnum;

do(

fprintf(stdout,M\t\t **** Entering Value to be Storedf printf(stdout,"Enter number )fprintf(stdout,"besides type desired:\ntn);

118

Page 124: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

f printf ( stdout,"\t I - BOOL\\t 2 - NAT \t 3 INT ;fprintf ~staout,"\t 4 - CHAR\n\t 5 - CSTR \t 6 - MAD ;

fprintf (stdout,'\t 7 - RAID \t 8 - SAD\n\t 9 - FILE )

if (Iinst-get) (fprintf(stdout,N"t1 - INSTR\tll - MOP \M12 - DOP\nn);,,)fprintf( stdout,"\t3 - ROP \t14 - BOP \t @ - 3bort C.D\n)

else (fprintf stdoutM\t11 - MOP Vt12 - DOP \t13 - ROP\nw);1fprintf~sdout,\t14 - BOP \t @-abort op\n");

fscanf(stdin,*%1 Is",nDstr);

strptr =stripblk(inpstr);

if (strotrf~l == ''*abcrtoD -TIUEutreturn;

str2dec(strptr,&vai idnum,&numter),;

ipr intf(stdout,*Invalid numoer entered. n");continue;,

switch(rtirber) (case 1: geLbool(v,abortop);

F. return;case 2: geLnat(v,abortop);

return;case 3: geLint(v,abortop);

return;case 4: geLchar(v,abortop);

return;case 5: geLcstr(v,abortop);

return;case 6: get-mad(v,abortop);

return;case 7: get-rad(v.abortop);

return;case 8: oetusaa(\v,3DcrocD);

return;case 9: geLf ile(v,abortop);

return;

case 10: if (linsLget) ige is~~b ro)

return;

119

Page 125: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

f printf (stdout, "Incorrect, number.\n");break-,

case If: getmop(v,abortop);return;

case 12: geL-dop(v,abortop):return;

case 13: get..rop(v,abortop):return;

case 14: get-bop(v,abortop);return;

def au It: fprintf (stdout, incorrect number\nM);

while (TRUE);

/WSETMErR()functilon:

-This function performs the 'set memory' operation.L

interf ace:p opt

g segnm-of set

called by:debugo/debug.c

calls:stripblko/debugut l.c? etvalue()

pmalloco/amstate.cfinal locU/amstate.ccnv2addro/debugutl .cgetopcodeo/aminstrC

.)rrors:

setmemr(opt)OPTION *opt;

( char M1str ptr;char inips tr[rIXINPSTRJ;

120

Page 126: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

BOOLNop...abort = FALSE.VAL *v;MAD m;short brknum;

opt->oprtn =SETMEMR;

do fpr intf (stdout, *Enter one of following\n1);fprintf stdout n\t\t'v' -memaddr valrue prompt\nM);fprintf stdout,"\t\t'@' -to abort the operation: \nm);

strptr = stripblk(inpstr);

if (strptr[O] = '@') (opt->abortop = TRUE;return:

if (strptr[O] V){-segnum get-segm(&opt->abortop,

...numusrseg - 1);

if (opt->abortop)return;

-.offset = get-ofst(&opt->abortop,...memL.segnumtslize -0

if (opt->abortop)return;

opt->val (VAL*) pmalloc(sizeof (VAL));getvalue(opt->val,&op-abort);

break;

fprintf(stdout,"Incorrect response.\n");

while (TRUE);

f ',opt ->,3tor~cp =opmort, /,I Assignment *ntencec!! '

return;

debgtask = 1;

m.val = cnv2addrC...segnum, -.offset);v =fetchm(&m,Q);

121

Page 127: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if (v->type ==VINSTR){if (getopcode(v->instrval .va 1(0 .opcdval) ==ILDBG)(

do (fpr intf (stdout,"Breakpoint at memnaddr.\n");f printf stdout "Enter '1 to confirm set\ni);fprintf( stdout:m\t\tor\n'@' to abort op\ni);fscanf( stdnM%1sMnpstr);

strptr = stripblk(inpstr);

if (strptr[O1 ==@V) (opt->abortop = TRUE;debgtask 0;return;

if (strptr[O1 == '10)brkrnum~tletopnd(v->insti.rval .va 1(0 .opcdva i);storem(opt-> va l,&m,Q);fmalloc(opt->val);brktable[brknum].memaddr =0;brktabl e~brknuml.opcdval =UNOEFND;mt-slots++topslot1 brknum;debgtask = 0;return;

f pr int f(stdout, "Incorrect response.\n);

while (TRUE);

storem(opt->val ,&m,Q);final loc(opt->val);debgtask =0;

/NSETREGR()function:

-This function performs the '3et register' operation.

interface:(p opt

g senum

called by:debugo/debug.c

122

Page 128: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

calls:str ipb i kodebugut Lcgetvalueppma 1oc /astate.cfinalloc /amstate.ccnv2addro/debugutl .c

err ors:

setreqr(ont)OPTI ON *ODt;

char *strptr;char inpstr[MXINPSTRI;BOOLNop...abort = FALSE;IRADr

opt->oprtn =SETREGR;

do f;:Drintf(stdout.'Tte one of followinq:\rV);fprintf( stdout,*\t\tCv' -r'egaddr value promptn");fprintf( stdout,*\t\tV@' -to abort the operatior nf);fscanf stdin,'*%ls ,inpstr);

strptr =stripbik(irpstr);

if (strptr[O1 = @') (opt->abortop =TRUE;return;

if (strptr[O1 ==') 0...segnum =geLsegm(&opt->abortop,

...rmmregseg - 1);

if (opt->abortop)return;

-offset =get-ofst(&oot-1>'3Dortcp,-:2L..egnumo~um -

if (opt->abortop)return;

opt->val = (VAL *) pmallIoc(sizeo (VAL));getvalue(opt-;pvaI ,&op-abort);

break;

123

Page 129: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

fprintf(stdout,"Incorrect response\nM);

while (TRUE);

if (opt->abortop = op-abort) /* Assigrnent intended!! ~return;

r~vl cw~dd(...segnum, -..offset);

fmai loc(opt->val);

fWSETSTK()function:

-This function Performs the 'set stack' operation.interf ace:

(p) opt(g) -segnum

* called by:clebugo/debug.c

calls:stripblk( )fdebugutl.cgetvalue~pmal loc lamstate.cfinal Ioc /amstate.ccnv2addro/debugut l.c

errors:

setstk( opt)OPTION *opt;

( char *strptr;chiar inostr(M1INPSTRI;3OLN op-..abcrt =FALSE;SAD s;

opt->oprtn =SETSTK;

do([fpritf~tdo "Eterone of following\nN);

fprintf (stdoutO\t\t'v' -regaddr value prom pt\n);fprintf(stdout,"\t\t'@' -to abort the operation: In")

124

Page 130: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

f scanf (stdin,"%1s',inpstr);

strPtr =stripblk(inpstr);

if (strptr[O] == vi) [opt->abortop =TRUE;return;

if (strptr[O] == 'v')(-.segnum geLsegm(&opt->abortop,

-..nmstkseg - 0);if (opt->abortop)

return;

opt->val =(VAL*~) pmalloc(sizeof(VAL));getval ue(opt->val,&op...abort);

break:

f printf (stdout, "Incorrect response.\nm);

while (TRUE);if (opt->abortop =op...abort) /0 Assignment intended! if

return;

-.offset= ..stkL..segnuml.size -1;s.va = cnv2addr(..eanum, -..offset);

fma! Ioc(opt->va I);

/*SETBRK()function:-This function sets a breakpoint at an memaddr with an

instruct ion.

interf ace:"pp opt

x aebgtask/am.ng mLinitg brktable[lg topsiotg mt-slots[1g -seynumg I..-of set

125

Page 131: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

called by:debugo/debug.c

calls:str ipblko/debugutlI.c

?,etopcodeo/aminstr.cstorem8 /amstate.ccnv 2addro/debugut lc

errors:

setbrk(opt)OPTION *opt;

char *strptr;char InpstrfrlX1NPSTrRI;short opcode;.VAL *v;M1AD m;short i;BREAK-Obrk-;

opt->oprtn =SETBRK;

do(fpr int f stdout, Enter one of f o IIow ing\nN);fprintf stdout M\t\t'v' -memaddr val[ue prompt~n");fprintf stdout,"\t\t'@ to abort the operation: \n*);f scanf 1stdin,"%s M ,inpstr);

strptr =stripblk(inpstr);

if (strptr[O1 =@W){(opt->abortop =TRUE;return;

if (strptr[OI == SO)...segnum =get-segm(&opt->abortop,

....umusrseg -

if (opt->abortop)return;

-..offset =get-ofst(&opt->abortop,...memL-segnuml.size -0

if (opt->abortop)return;

126

.......... ......

Page 132: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

bJreak:

fprintf(stdout,"lncorrect response.\n");

whiie (TRUE);

if (Imt-init)(for (0 = o;i < MAXBRKS; i++)(

mt-slots(II I;OrKtableti1.memaddr = 0;brktabie(i1.oocdvaI UNDEFND:

topsiot =MAXBRKS - 1;mt-init =T RUE;

if (topslot < 0fprintf~stdout,"Break Table Fulln");return;

debgtask =1;

m.val =cnv2addrG..segnum, -.offset);v = etchm(&mQ);

if (v->tu e =V INSTR)(Tpr intf (stdout, "Sorry, non- instr at meadrn)debgtask =0;return;

if (getopcode(v->instrval.val[OJ.opcdval) ==ILDBG)fpr int f (stdout, *Sorry, Breakpoint already at memaddr\nM);debgtask =0;return;

Drk.oDcdvaI v->instrvai.vaI[0 I.opcdvai;rk.memaadr = rn.vai;

opcode= ((mLslots[topslotl < «XOPNDSF) I(ILDBG));v-instrval.val[0J.opcdval =opcode;brktable(mt-slots[ topsiot JJmemaddr =brk.memaddr;brktable[mLslots topslot JJ-opcdvaI= brk.opcdval;topsiot--;

storem(v,&m,Q);

127

Page 133: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

detogtask =0;

/*SEL..PC(f unct ion:

-T7his flunction performs the 'set program counter'operation.

interf ace:

..otnumusrseg/am.hx -pc/ Ai

xI debgtask/am.h

call Ied by:debUg0C/debug.c

C aI Is:str ,pblkQ/detuqut1 .c

cnv'2addrQ/debugutl~cgetsegmY)ge-of st()

errors.

sLjc(opt)

( char *strptr;char inpstr[MXINPSTRJ;VAL *v;MAD m;

opt->oprtn = SET-PC;

*Drintf( StdCUt.'Thter one of flollowinq:',.n '2(printf(staout, \'d\Cv' -Prog cntr vafue prompt\n');fprintf~stdout,"\t\t'@' -to abort the operation: \nlU);fscanf (stdin "%lsN,inpstr);

strptr = stripblk(inpstr);

if (strptr[O1 == 0 (opt-)abortop = TRUE;

128

Page 134: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

return;

if (strptr[O] ==V')...segnum geLsegm(&opt->abortop,

...numusrseg - 0);if (opt->abortop)

return;

-offset =geLofst(&opt->abortop,..memL-segnumtsize - 1);

if (opt->abortoD)return;

break;

fprintf(stdcut, !nccrrect response. \nm);

while (TRUE);

debgtask = ;

m.val = cnv2addr(..segnum, -..offset);v= fetchm(&m,Q);

if (v->tUpeIl V-JNSTR)(T print f ( stdoutM"Sorry, non-instr at memaddr.\n');f printf stdout,mProgram counter unchanged. \no);opt->abortop =TRUE;return;

..pc.val =m.val;

debgtask =0;

129

Page 135: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

Debugger Utility File

/*DEBUGUTL.C :This file contains the utility programs for the AMdebugger.

-AM version 1.0 - ZIO

Changes.

*include "amdef.hn*jpcjude "amtype.h*vinclude namexterahM*include Mdebug.hM

./*CNV2ADDR()function:

-This functions converts its parameters into a regularsegmented memory address.

interf ace:Sp) -seqnump)-ofrfset

called b IU mm/dbgp:reovbrk/debugoprcsetmemro/debugopr.csetbrkQ/debugopr.cseLpco/debugopr.cget-madQI/debugopr.cdisplre (/debugopr.cse tregrQdebugopr.cgeLradj/debugopr.cdisp ist k debugopr.csetstko/debugopr.cgeLsadofdebugopr.c

calls:

erfrors:

addresscnv2addr(.segrnum, -.offset)

long segnum;

130

Page 136: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

}return((-segnum << X-SEGSFT) I-offset);

/*STR1PSLK()f unction:

-This functions strips leading blank characters from acharacter string.

interf ace:(P) str

called b Isp memo/debUgopr.cdiSDlreqQ/debugoprcdispibrk /debugopr.cdisplstk /debugopr.cdispL-pc )/debuigopr.cqs topro/ debug.cgetresrcO/de~ug.cgetvaluek,)/debugopr.cgoexec( /detniqopr cremovbrko/debugopr.csetmemro/debugo or. csetregroldebugoor.csetstk -/ debugopr.csetbrk I/debugopr.cset-pc)/debugopr.ctraceopQ/debugopr.cquitdebq /debugopr.cget-mad /debugopr.cgetradQ/debugopr.cgeLsad /debugopr.cgeLint( debugopr.c

geLmop ()/debugopr.cgeLf bo/debugopr.cgeLmop/debugopr.cgeLdop /debugopr.cgetinst U/debugopr.cgeLdo dbgp~

ge, /debugopr.c,iuitaebg( /denuqopr.c

calls:err:strlen()! *system*

char

131

Page 137: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

*stripblk(str)char *str;

int index =0;int lngth;

Ingth =strlen~str);

while ((index < ingth) && (strfindexiindex++;

return(str + index);

INSTR2HX()function:

-Converts an unsigned hex character string into itsinteger equivalent. !! Warning !! The function can anddoes mnodifyj the Dointer to The inDut String parameter'

The ax sringlength the .Function assumes is four (4)for conversion to regular hexidecimal integer.

interf ace:p) str

pvalidnum

called by:get-insto/debugopr.cget-mop /debugopr.cget-dopU/debugopr.cgeLrop fdebugopr.cgeLbop /debugopr.c

callIs:

errors:-Initializes parameter 'validnum' with the results ofof the conversion.

str2hex(str~vau dnumljntPtr)nrar 4str-,300LN *,/alidnum;long *intptr;

{ mt index = 0;int maxchars;

str =stripblk(str);

132

Page 138: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

if (strlen(str) ==)0)*validnum = FALSE;return;

*intptr =0;

rnaxchars =MXHEXSTR -

while ((((strfindex] >= '0') && (str[indexl <= :9')I((strbindex] >= Va) && (strbindexl <= ')(index < maxchars)) (

if ((strindex] >= '0') && (strfindex] <= '9'))*intptr= !6 (*4ntptr) +str~inaex*+j - '0;

else intptr= l6 (*intptr) + (str[index..] - 'a') +10;

3Wr = strfindexl;str zstripbik(str);*validnum = (strlen(str) ==0) ? TRUE :FALSE;

5 T R2D E Cfunction:

-Converts an signed or unsigned character string intoits long integer equivalent. H Warning H! The functioncan an does modify the pointer to te input string para-meter! The max string length the function assumes iseleven (11) for conversion to regular signed integer.

interf ace:

p val idnum

called byJ:ge se m )/debugopr.cgeLof st /debugopr.cgetrange /debugopr.cgoexec9O'debugopr.ctracoi~ )/debuqopr..rerinvt( )/deugopr.cget-natQ/debugopr.cget-f i Ie )/debugopr.cgetvalue( )/debugopr.c

callIs:strien(O! *system"

133

Page 139: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

errors:~-initializes parameter 'validnum' with the results ofof the conversion.L

str2dec(str,val idnum, intptr)char Ostr;BOOLN *val idnum;long "intptr;

{ mt index = 0;int maxcnars;int strsize;5300LN negnum =FALSE;long maxnum = 2147483647;

maxchars = 1XDECSTR - 2;

if (strlenIsr == 0)(*validnum =FALSE;return;

if (strJil -){

negnum =TRUE;str =&strfll;

if (strlen(str) == 0) (*validnum =FALSE;return;

*intptr = 0;index =0;

while (((str[indexl >= '0') && (str[indexJ <='g)&& (index < maxchars) && (*intptr <= maxnum))(

Nintptr = 10 *(*intptr) + (strfindex++1 - '0');

str = &striindexl;str stripblk(str);*validnum =(strlen(str) == 0) ? TRUE :FALSE;

if (*validnium) () intptr =negnum ? 0 - *intptr *intptr;

13

Page 140: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

LIST OF REFERENCES

Hunter, J. E., The Formal Specification of a Visual Display Device: Design and

implementation "aster's- Thes;s, Navat -ostgracuate Schccl, Iontereg, 'a..

Jun 1985.

Ozisik, M. G., DesiQn and implementation of a C Compiler for an Abstrac:

Machine, Master's Thesis, Naval Postgraduate School, Monterey, Ca., Jun

i986.

Wray, B., Crawfor, 3., What Every Engineer Thouic <,cw Abcur

'"icrocomputer 'Lystems Desin and Deougging, 'Iarca2i eKker, inc.. New "cr',

N. Y., 1984, pp. 98 - 108.

Yurchak, J., The Formal Specification of an Abstract Machine, Design and

Implementation, Master's Thesis, Naval Postgraduate School, Monterey, Ca.,

Dec 1984.

Z Zang, K. H., The Formal Specification of an Abstract Database: Design and

Implementation Master's Thesis, Naval Postgraduate School, Monterey, Ca.,

Dec 1985.

Naval Postgraduate School, Tech. Report NP552 84-022, A Formal Method for

Specifuing Computer Resources in an Implementation Independent Manner, by

Davis, D. L., Monterey, Ca., Nov 1984.

135

I' . , . . . , . . . - . ; - . - ., ,.:, :,. . , - ' ' ,

Page 141: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

INITIAL DISTRIBUTION LISTNo. Copies

1. Chief of Naval OperationsDirector, Information Systems (CP-945)Navy DepartmentWashington, 0. C. 20350-2000

2. Defense Tecnnical Information C2nterCameron StationAlexandria, Virginia 22304-6145

3. SuperintendentAttn: Library (Code 0142)Naval Postgraduate ScnoolMonterey, California 93943-5002

4. Chairman (Code 52)Department of Computer SciencesNaval Postgraduate SchoolMonterey, California 93943-5000

5. Computer Technology Programs (Code 37)Naval Postgraduate SchoolMonterey, California 93943-5000

6. Daniel L. Davis (Code 52) 5Department of Computer ScienceNaval Postgraduate SchoolMonterey, California 93943-5000

7. 5ruc2 .;. MacLennan (Code 52) 5Department of Computer ScienceNaval Postgraduate SchoolMonterey, California 93943-5000

136

Page 142: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

8. lstLt Stanley Victrum, USM1Cc/o George Wilson 10Rte 2, Box 116Cross, South Carolina 29436

137

Page 143: FOR AN ABSTRACT t/2 MACNINE(U) NAVAL POSTGRADUATE SCHOOL … · 2014-09-27 · I1E(cludo Securfy Cla,wicarlOn) DESIGN AND IMPLEMENTATION OF A DEBUGGER FOR AN ABSTRACT MACHINE (u)

MUM