Talk:Debug (command)

From Wikipedia, the free encyclopedia

[edit] Syntax section

The syntax section, IMHO, ought to contain descriptions of the command-line invocation parameters for DEBUG; and using DEBUG with DOS redirection ought to be discussed separately, as should running DEBUG from batch files.

(Calling DEBUG's commands "subcommands" is unnecessarily pedantic.)

As an example of running DEBUG with redirection (implemented by COMMAND.COM or CMD.EXE), consider a text file containing the following two lines:

 ?
 q

This file can be given any name (and perhaps extension), for example, DEBUG-IN.TXT.

Then, invoking DEBUG with:

DEBUG < DEBUG-IN.TXT >> DEBUGOUT.TXT

will invoke DEBUG, taking its input not from "standard in", but from the file, DEBUG-IN.TXT, and sending its output, not to "standard out", but to the file DEBUGOUT.TXT, appending it to the original file, if it exists, or creating it otherwise. This is a feature of DOS's COMMAND.COM called redirection, and is supported by DEBUG, which can indeed be very useful, but is peripheral to DEBUG's syntax. In this example, DEBUGOUT.TXT will contain the output of DEBUG's "?" command, a brief listing of its commands (along with an "echo" of its prompts and input) as follows:


-?

assemble     A [address]
compare      C range address
dump         D [range]
enter        E address [list]
fill         F range list
go           G [=address] [addresses]
hex          H value1 value2
input        I port
load         L [address] [drive] [firstsector] [number]
move         M range address
name         N [pathname] [arglist]
output       O port byte
proceed      P [=address] [number]
quit         Q
register     R [register]
search       S range list
trace        T [=address] [value]
unassemble   U [range]
write        W [address] [drive] [firstsector] [number]
allocate expanded memory        XA [#pages]
deallocate expanded memory      XD [handle]
map expanded memory pages       XM [Lpage] [Ppage] [handle]
display expanded memory status  XS
-q

The "trick" of RCX isn't a trick at all; it's simply DEBUG's way of working nicely without separators when they can be inferred. It's equivalent to R CX, as implied above in the output of the "?" command. Here's the output of DEBUG < DEBUG-IN.TXT when the input file has "R" on the first line, followed by "Q" on the next:


-R

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000  
DS=1671  ES=1671  SS=1671  CS=1671  IP=0100   NV UP EI PL NZ NA PO NC 
1671:0100 65            DB      65                                 
-Q

This is DEBUG's register display. Each of the strings containing an equals sign gives the value of a register. Those ending in "S" are segment registers. Those ending in X are general-purpose registers, CS and IP stand for Code Segment and Instruction Pointer, respectively, and the others are Stack Pointer, Byte Pointer, Source Index, and Destination Index, if memory serves me. They all have their peculiarities.

The general purpose registers can be addressed in instructions in two halves. For example "AH" indicates the higher (first) two nibbles of the AX register, "AL" indicates the lower two nibbles of the same, and similarly for BX, CX, and DX.

The final four pairs of letters on the second line DEBUG output indicate the states of the bits in the flag register.

The last line gives the "current" instruction, located at CS:IP (shown here as 1671:0100), which consists here of the hex digits "65", which, since they don't correspond to any instruction DEBUG recognizes, are interpreted as a "data byte", which is shown "disassembled" as DB 65.

Any of the register abbreviations can be used with the "R" command, for example, RIP (or R IP), RCS, or RAX. "R" entered without a register abbreviation causes DEBUG to issue a colon prompt ":", at which time a new value for the register can be entered. If no input is given (by pressing ENTER, or in a script file, by an empty line), the hyphen prompt returns and no register is changed.

This is all easily discoverable by playing with DEBUG.

Hope it helps, somehow.

Unfree (talk) 03:50, 15 December 2007 (UTC)

Actually, DEBUG does use "standard in" and "standard out", and COMMAND.COM causes them to be redirected from and to files, if I understand it correctly.Unfree (talk) 03:54, 15 December 2007 (UTC)
Thanks for the clarification. Could you make these changes yourself? I'm not an expert on this and it seems that know what you are talking about. (RCX (talk) 22:58, 15 December 2007 (UTC))