MAINSAIL Compiler User's Guide, Chapter 5

previous   next   top   contents   index   framed top   this page unframed


5. DISASM, the MAINSAIL Disassembler

DISASM, the MAINSAIL disassembler, is used to examine the code generated by the MAINSAIL compiler. Usually, the MODULE being examined will have been compiled with the compiler's ALIST subcommand.

When the disassembler is run, it first prompts for the name of an input file. At this prompt, you can specify an object file name, or a MODULE name if the object file name can be constructed from the MODULE name in the standard way. If the name specified to the input file prompt is a valid MODULE name, then DISASM assumes that a MODULE of that name is to be disassembled, and builds the object file name the same way that the runtime system does when it looks for the object file containing a MODULE. Otherwise, DISASM uses the name as the name of the input object file. If the MODULE to be disassembled is in an objmod library, type <eol> to the input file prompt, and DISASM then prompts for the name of the library and the MODULE name.

DISASM then prompts for the output (disassembly) file name.

Whenever a new input object file or object library name is specified, DISASM prompts for the target system abbreviation. The default is the target used in disassembling the previous MODULE in this DISASM session, or the host system if this is the first MODULE disassembled.

If the intmod file is not the default intmod file for the MODULE being disassembled, the IF intmodFileName command may be used to specify it. IF with no arguments sets the intmod file to the default file for the current MODULE.

To disassemble another MODULE, use the F command. F with no arguments causes DISASM to enter its initial dialogue again. F moduleOrFileName allows the input MODULE or file name to be specified.

The IL libraryName command specifies the name of an input intmod library. This command remains in effect until a new IL command is specified.

OF outputFileName specifies a new output file.

The D command disassembles the entire input MODULE, placing the result in the output file; D procedureName disassembles a single PROCEDURE. D procedure1 procedure2 ... procedureN disassembles the named PROCEDUREs.

The Q command exits the disassembler.

A line beginning with a pound sign (#) is ignored (treated as a comment).

The ? command displays a list of valid disassembler commands. Commands not documented here are for XIDAK's internal use; their effect is undefined.

A sample disassembler session:

MAINSAIL (RDisassembler
Copyright (c) 1984...
 
by XIDAKInc., Point ArenaCaliforniaUSA.

Input file or module name (eol if in library): erode<eol>
Target system (eol for uspa): <eol>
Opening intmod for $SYS...
Output file (eol for logFile): <eol>

Type ? for help

DISASMd<eol>
                
DISASSEMBLY OF OBJECT FILE erode-usp.obj
                ----------------------------------------

                         
SOURCE FILEerode.msl
                         ----------------------

BEGIN "erode"

DEFINE
    
xSz         =        200L,
    
ySz         =        200L;

POINTER($ranClsran;

PROCEDURE erodeOne;
BEGIN
LONG INTEGER x,y;

4       
sub     sp,#0x28,sp
8       
std     fp,0(sp)
C       st      lr,8(sp)
10      
mov     sp,fp

x _ ran.$sRand MOD cvli(xSz) + 1L;

14      
ld      0xc(db),%o2
18      
clr     %o0
1C      
clr     %o1
20      
tst     %o2
24      
bne,a   0x3c
28      
ld      -4(%o2),t1
2C      
ld      calErr(gb),st1
30      
jmpl    0(st1),lr
34      
nop
38      
ld      -4(%o2),t1
3C      
ld      0x2c(t1),t1
40      
ld      0x14(t1),t1
44      
jmpl    0(t1),lr
48      
mov     %o2,db
4C      
ld      4(fp),db
50      
ld      0xc(db),%o2
54      
mov     %o0,t2
58      
ld      liMod(gb),%o0
5C      
jmpl    0(%o0),lr
60      
mov     #0xc8,t3
64      
mov     t2,%o0
68      
add     %o0,#1,%o0
6C      
st      %o0,0x24(fp)

... rest of disassembly...

Disassembly on file TTY
DISASMq<eol>

5.1. Using DISASM to Find the Source Code Corresponding to a Position in a Non-Debuggable MODULE

The utility MODULE CALLS and the CALLS response to the Error response prompt produce descriptions of the MAINSAIL call stack that include decimal offsets within a MODULE. When a reproducible error occurs in a debuggable MODULE, you can find the source text corresponding to a given offset just by entering MAINDEBUG. If you need to find the source code corresponding to an offset in a non-debuggable MODULE, or if you have a stack trace for an error that is not reproducible, you may need to use DISASM.

If you are looking for the source code corresponding to an error in a non-debuggable MODULE, it is usually easiest to try recompiling the MODULE debuggable and then reproducing the error, and entering the debugger at the Error response prompt. However, this may not work because some bugs disappear when the code that produced them is compiled debuggable.

If you compile a MODULE with the ALIST compiler subcommand, the compiler will produce an intmod that will allow the MODULE to be disassembled. DISASM uses a MODULE's object MODULE and its corresponding intmod to produce an assembly language listing of the MODULE's code sprinkled with the source text for each statement in the MODULE; you can use this listing to determine the offsets in the object MODULE corresponding to source code.

If the bug in question is not reproducible, and you have only a stack trace to work from, you must be careful that you do not change the offsets in the MODULE when you recompile it with the ALIST subcommand (if you did not compile it with ALIST originally). The ALIST subcommand does not change the code that the compiler generates. So, if the MODULE you are interested in does was not compiled with the ALIST subcommand, you should recompile it, specifying the same compiler subcommands as it was originally compiled with, but also specifying ALIST. (You should also, of course, place the output object MODULEs and intmods in a different place so as not to overwrite the originals.) You must also use the same revision of MAINSAIL and the same versions of the source files and intmods that were used to create the original object MODULE; otherwise, offsets within the MODULE may change.

Once you have compiled your MODULE with ALIST, you can compare the resulting object MODULE with the original object MODULE by using OBJCOM to confirm that you have not changed any offsets. Despite the fact that the new object MODULE was compiled with ALIST and the old one was presumably compiled without it, the two object MODULEs should be identical. If they are not, then the differences were caused by differences in the input source files, input intmods, or the revisions of MAINSAIL used to compile the MODULEs. These differences should be resolved before proceeding. Otherwise, the offsets from the original stack trace will not match the offsets in the listing produced by the disassembler.

Next, run DISASM to disassemble the new object MODULE. The disassembled listing will contain hexadecimal offsets in the left margin of each line that contains an assembly language instruction. You have to convert the decimal numbers from the stack trace to hexadecimal, and then look them up in the disassembled listing to find the source statements corresponding to them.


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Compiler User's Guide, Chapter 5