bds@lzaz.ATT.COM (B.SZABLAK) (12/22/88)
echo x - mdb.1
gres '^X' '' > mdb.1 << '/'
XCOMMAND
X mdb(1) - MINIX Debugger
X
XINVOCATION
X mdb [<executable> [<link file>]]
X
XEXPLANATION
X Mdb provides a means of debugging minix programs. It supports symbolic
X debugging if a "link file" exists; the link file is the output of the
X ACK linker: ld. The arguments to mdb are:
X
X <executable> - The MINIX executable file. Defaults to "a.out".
X <link file> - The MINIX link file. Defaults to none.
X
X Once started, mdb will display a command prompt: '*'. A command may
X be entered in the following form:
X
X [<expression>][<command> [<argument>]]
X
X <expression> is a symbolic expression representing a location
X in memory or a register, and should be in the form:
X
X [<value> [+|- <value>]]
X
X A <value> may be a symbol, a register, or a constant.
X The symbol may be any external symbol found in the link file, or "_start"
X if no link file is specified. "_start" represents the beginning address
X of the program. A register is specified by a '$' followed by the
X register's name, while a constant may be either an octal, decimal or hex
X unsigned long integer expressed using standard C notation (no 'L' suffix
X should be used). A character constant is represented by a single quote
X followed by the character.
X
X Not all commands use an address, but those that do have a default
X value of the current program counter with the exception of the continue
X command: 'c' and 'C'. Not all commands use an argument
X list, but those that do default to an empty list. If the argument
X contains a semi-colon (';'), then except for the breakpoint
X command ('b') the string following the semi-colon is assumed to be a
X new command.
X
X Following is the list of valid commands. When mdb is first started,
X no process is active. Most of the following commands require an active
X process which may be created using the run ('r') command.
X
X ! - If the exclaimation point begins the command line then the
X MINIX program that follows it is executed. The default
X command is "/bin/sh". Note: full path names are required.
X
X Example: * !vi mdb.c
X
X If the expression preceeding the exclaimation point is a
X valid data address, then the arguments specify how to modify
X its contents. The argument is to be in the form:
X [<constant>] [<size>] [<expression>]
X and are interpreted as: "fill the data space starting at the
X specified address with <constant> values given by <expression>
X and are of size byte ('b'), half word ('h', i.e. short),
X or long word ('l')." The default value of constant is 1, of
X size is 'h', and of expression is 0.
X
X Example: * _buf ! 20b 'a
X
X T - This command prints the current active function in the program with
X its arguments.
X
X Example: * T
X
X t - This command prints the current function invocation
X heirarchy with their arguments.
X
X Example: * t
X
X / - This command prints the values starting at the address
X specified. The argument is to be in the form:
X [<constant>][<size>][<format>]
X format may have the values:
X a - Displays characters until a zero value is found
X (<constant> and <size> are ignored).
X c - Displays <constant> values as characters.
X d - Displays <constant> values as signed decimal numbers.
X i - Disassembles <constant> instructions (<size> ignored).
X I - Disassembles <constant> instructions (<size> ignored).
X o - Displays <constant> vlaues as octal numbers.
X s - Displays characters until a zero value is found
X starting at the address contained at the location
X specified (<constant> and <size> are ignored).
X u - Displays <constant> vlaues as unsigned decimal numbers.
X x - Displays <constant> vlaues as hexadecimal numbers.
X
X Example: * $a6-2/hx
X
X x - This command prints the registers and the instructions
X starting at the specified address. An optional constant
X argument limits the number of instructions printed.
X
X Example: * x
X
X X - This command prints the instructions starting at the specified
X address. An optional constant argument limits the number of
X instructions printed.
X
X Example: * _start X 10
X
X R - This command starts a process using the executable given
X as mbd's first argument. The process will have no arguments
X and will be stopped prior to executing any instructions.
X
X Example: * R
X
X r - This command starts a process using the executable given
X as mbd's first argument. The process will be given the
X arguments on the command line up to the first semi-colon.
X If no arguments are specifed, then the arguments supplied
X with the last 'r' command are used. The processes' standard
X input and output may be redirected. The process will be
X stopped prior to executing any instructions.
X
X Example: * r 3 <input >output
X
X C - This command results in the stopped process being restarted
X with a pending signal specfied by the constant argument.
X A breakpoint is placed at the address specified if one is
X not already there, and if placed it is deleted when the
X process stops for any reason. No default address is assumed.
X
X Example: * C 2
X
X c - This command results in the stopped process being restarted
X with all pending signals canceled. A breakpoint is placed
X at the address specified if one is not already there, and
X if placed it is deleted when the process stops for any reason.
X No default address is assumed.
X
X Example: * _func+4 c
X
X I - This command results in the stopped process executing
X instructions in single step mode. The number of instructions
X executed is given in the constant argument. The signal
X that stopped the process will be sent when execution begins.
X
X Example: * I 10
X
X
X i - This command results in the stopped process executing
X instructions in single step mode. The number of instructions
X executed is given in the constant argument. All pending
X signals are canceled before execution begins.
X
X Example: * i 10
X
X M - This command results in the stopped process resuming
X execution until the long word at the location specified by the
X address is modified or until the number of instructions
X specified in the obtional constant argument are executed.
X The default number is 65,536. Each executed instruction is
X displayed prior to execution.
X
X Example: * _var M 100
X
X m - This command results in the stopped process resuming
X execution until the long word at the location specified by the
X address is modified or until the number of instructions
X specified in the obtional constant argument are executed.
X The default number is 65,536.
X
X Example: * _var m
X
X k - This command results in the current active process being
X terminated.
X
X Example: * k
X
X B - This command results in all the currently active breakpoints
X being listed.
X
X Example: * B
X
X b - This command results in a breakpoint being placed at the
X location specified by the address in program space. The
X string that follows the command contains the command(s) that
X are executed when the breakpoint is hit. It is recommended
X that breakpoints be placed at an offset of 4 bytes from the
X function entry point to permit a valid frame to be set up
X for back-tracing.
X
X Example: * _func+4 b t;_var/lx
X
X d - This command results in the breakpoint at the address
X specified being deleted.
X
X Example: * _func+4 d
X
X D - This command results in all breakpoints being deleted.
X
X Example: * D
X
X q - This command results in the currently active process being
X terminated and mdb exiting.
X
X Example: * q
X
XRESULTS
X Mdb's exit status is always zero.
X
XREFERENCES
X ptrace(2)
/
echo x - user.h
gres '^X' '' > user.h << '/'
X#include "h/type.h"
X#include "h/const.h"
X#include "kernel/type.h"
X#include "kernel/const.h"
X#undef printf
X
Xstruct proc {
X#ifdef i8088
X int p_reg[NR_REGS]; /* process' registers */
X#endif
X#ifdef ATARI_ST
X long p_reg[NR_REGS]; /* process' registers */
X#endif
X int *p_sp; /* stack pointer */
X struct pc_psw p_pcpsw; /* pc and psw as pushed by interrupt */
X#ifdef i8088
X int *p_splimit; /* lowest legal stack value */
X#endif
X#ifdef ATARI_ST
X int *p_splow; /* lowest observed stack value */
X int p_trap; /* trap type (only low byte) */
X#endif
X int p_flags; /* P_SLOT_FREE, SENDING, RECEIVING, etc. */
X struct mem_map p_map[NR_SEGS];/* memory map */
X#ifdef ATARI_ST
X phys_clicks p_shadow; /* set if shadowed process image */
X int p_nflips; /* statistics */
X char p_physio; /* cannot be (un)shadowed now if set */
X#endif
X int p_pid; /* process id passed in from MM */
X
X real_time user_time; /* user time in ticks */
X real_time sys_time; /* sys time in ticks */
X real_time child_utime; /* cumulative user time of children */
X real_time child_stime; /* cumulative sys time of children */
X real_time p_alarm; /* time of next alarm in ticks, or 0 */
X
X struct proc *p_callerq; /* head of list of procs wishing to send */
X struct proc *p_sendlink; /* link to next proc wishing to send */
X message *p_messbuf; /* pointer to message buffer */
X int p_getfrom; /* from whom does process want to receive? */
X
X struct proc *p_nextready; /* pointer to next ready process */
X int p_pending; /* bit map for pending signals 1-16 */
X};
/
echo x - strtol.c
gres '^X' '' > strtol.c << '/'
Xlong
Xstrtol(s, p, base)
X char *s, **p;
X{
X long r;
X int sign, digit, hexlow, hexup, c;
X
X r = 0L;
X sign = 0;
X while (*s == ' ' || *s == '\t') ++s;
X if (*s == '-')
X {
X sign = 1;
X ++s;
X }
X if (base == 0)
X {
X if (*s == '0') base = (s[1] == 'x' || s[1] == 'X') ? 16 : 8;
X else base = 10;
X }
X if (*s == '0' && (s[1] == 'x' || s[1] == 'X') && base == 16) s += 2;
X digit = (base <= 10) ? (base + '0' - 1) : '9';
X hexlow = 'a' + base - 10;
X hexup = 'A' + base - 10;
X for (c = *s ; ; c = *++s)
X {
X if (c >= '0' && c <= digit) c = c - '0';
X else if (c >= 'a' && c < hexlow) c = c - 'a' + 10;
X else if (c >= 'A' && c < hexup) c = c - 'A' + 10;
X else
X {
X if (p != 0) *p = s;
X return sign ? -r : r;
X }
X r = r * base + c;
X }
X}/
echo x - makefile
gres '^X' '' > makefile << '/'
XCFLAGS=-DATARI_ST -I/usr/src -T/usr/tmp
XOBJS=mdb.o mdbexp.o mdbdis.o strtol.o
XLD=/usr/lib/ld
XCV=/usr/lib/cv
XLIB=/usr/lib/libc.a /usr/lib/end.o
X
Xmdb: $(OBJS)
X $(LD) -o $*.out -c /usr/lib/crtso.o $(OBJS) $(LIB)
X $(CV) $*.out $@
X chmem =10000 $@
/
echo x - out.h
gres '^X' '' > out.h << '/'
X/*
X * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
X * See the copyright notice in the file "../Copyright".
X */
X/*
X * output format for ACK assemblers
X */
X#ifndef ushort
X#define ushort unsigned short
X#endif ushort
X
Xstruct outhead {
X ushort oh_magic; /* magic number */
X ushort oh_stamp; /* version stamp */
X ushort oh_flags; /* several format flags */
X ushort oh_nsect; /* number of outsect structures */
X ushort oh_nrelo; /* number of outrelo structures */
X ushort oh_nname; /* number of outname structures */
X long oh_nemit; /* sum of all os_flen */
X long oh_nchar; /* size of string area */
X};
X
X#define O_MAGIC 0x0201 /* magic number of output file */
X#define O_STAMP 0 /* version stamp */
X#define MAXSECT 64 /* Maximum number of sections */
X
X#define HF_LINK 0x0004 /* unresolved references left */
X#define HF_8086 0x0008 /* os_base specially encoded */
X
Xstruct outsect {
X long os_base; /* startaddress in machine */
X long os_size; /* section size in machine */
X long os_foff; /* startaddress in file */
X long os_flen; /* section size in file */
X long os_lign; /* section alignment */
X};
X
Xstruct outrelo {
X char or_type; /* type of reference */
X char or_sect; /* referencing section */
X ushort or_nami; /* referenced symbol index */
X long or_addr; /* referencing address */
X};
X
Xstruct outname {
X union {
X char *on_ptr; /* symbol name (in core) */
X long on_off; /* symbol name (in file) */
X } on_u;
X#define on_mptr on_u.on_ptr
X#define on_foff on_u.on_off
X ushort on_type; /* symbol type */
X ushort on_desc; /* debug info */
X long on_valu; /* symbol value */
X};
X
X/*
X * relocation type bits
X */
X#define RELSZ 0x07 /* relocation length */
X#define RELO1 1 /* 1 byte */
X#define RELO2 2 /* 2 bytes */
X#define RELO4 4 /* 4 bytes */
X#define RELPC 0x08 /* pc relative */
X#define RELBR 0x10 /* High order byte lowest address. */
X#define RELWR 0x20 /* High order word lowest address. */
X
X/*
X * section type bits and fields
X */
X#define S_TYP 0x007F /* undefined, absolute or relative */
X#define S_EXT 0x0080 /* external flag */
X#define S_ETC 0x7F00 /* for symbolic debug, bypassing 'as' */
X
X/*
X * S_TYP field values
X */
X#define S_UND 0x0000 /* undefined item */
X#define S_ABS 0x0001 /* absolute item */
X#define S_MIN 0x0002 /* first user section */
X#define S_MAX S_TYP /* last user section */
X
X/*
X * S_ETC field values
X */
X#define S_SCT 0x0100 /* section names */
X#define S_LIN 0x0200 /* hll source line item */
X#define S_FIL 0x0300 /* hll source file item */
X#define S_MOD 0x0400 /* ass source file item */
X#define S_COM 0x1000 /* Common name. */
X
X/*
X * structure format strings
X */
X#define SF_HEAD "22222244"
X#define SF_SECT "44444"
X#define SF_RELO "1124"
X#define SF_NAME "4224"
X
X/*
X * structure sizes (bytes in file; add digits in SF_*)
X */
X#define SZ_HEAD 20
X#define SZ_SECT 20
X#define SZ_RELO 8
X#define SZ_NAME 12
X
X/*
X * file access macros
X */
X#define BADMAGIC(x) ((x).oh_magic!=O_MAGIC)
X#define OFF_SECT(x) SZ_HEAD
X#define OFF_EMIT(x) (OFF_SECT(x) + ((long)(x).oh_nsect * SZ_SECT))
X#define OFF_RELO(x) (OFF_EMIT(x) + (x).oh_nemit)
X#define OFF_NAME(x) (OFF_RELO(x) + ((long)(x).oh_nrelo * SZ_RELO))
X#define OFF_CHAR(x) (OFF_NAME(x) + ((long)(x).oh_nname * SZ_NAME))
/