『楼 主』:
Debug命令详解
使用 LLM 解释/回答一下
发信人: liuxf (飞天御剑流), 信区: DOS
标 题: Debug命令详解
发信站: BBS 水木清华站 (Mon Apr 23 16:16:59 2001)
Debug命令详解
精华区没有,就贴上来了。
命令行参数形式:
格式:DEBUG 文件名 ]
用途:debug将所指定文件装入内存,显示提示符“-”等待进一
步命令。若装入文件为.exe文件,按照重定位原则装入为可执行状态
。.com文件类似。若为其它类型文件则直接进行内存映射,由偏移量
100H原封不动读入内存。
debug将在缓冲区为被调试程序建立适当的PSP(程序段前缀,
Program Segment Prefix)。在PSP中的偏移量80H为命令行的末尾。
而且在偏移量5CH和6CH由包含参数后面的可选参数构成缺省的FCB(
文件控制块,File Control Block)。
进入时各寄存器初使情况:
寄存器 .com程序 .exe程序
AX 指定驱动器错误码 指定驱动器错误码
BX 程序空间的高地址 程序空间的高地址
CX 程序空间的低地址 程序空间的低地址
DX 0 0
SI 0 0
DI 0 0
BP 0 0
SP 0FFFFH或可利用的 不定
内存空间上限减2
IP 100H 目标程序的的代码
入口偏移量
CS PSP 目标程序代码段址
DS PSP PSP
CS PSP PSP
SS PSP 目标程序堆栈段底
命令:
A: 编写汇编代码(Assemble)
格式:A
用途:程序允许在指定位置(若无缺省为IP指针位置)进行汇编
程序书写。
细节:
*所有数值皆为十六进制整数,数值后不带“H”
*不支持文件管理用的目录表、宏标记、条件汇编
*跳转指令后要直接书写十六进制地址不支持标号
*数据类型若非默认类型,要以PTR加以指定
*字符串操作要指定类型为B或W(如lodsb和lodsw等)及长度
*用DB和DW接受数据定义,直按进行汇编
*对内存地址加以与立即数区分
C: 内存内容比较(Compare)
格式:C 地址范围 地址
地址范围:做比较的第一个内存域始未地址或始地址和长度
地址: 做比较的第二个内存域的始地址
用途:*对内存中两个域的内容加以比较,以字节为单位。对发现有
差别的内容及其地址用如下形式显示出:
地址1 始位置 未位置 地址2
*若地址范围或地址不含段地址,默认为DS的值。
D: 显示内存内容(Dump)
格式:D
地址范围:给定显示区的始未范围或始地址和长度。
用途:*内存内容显示指令,以十六进制和ASCII码形式显示指定范
围内的内存内容。
*若不指定范围,第一次按目标程序的CS:IP的位址开始显示。
以后使用上次显示的未地址的下一地址为开始进行显示。
*若不指定长度,则显示128byte的内容。计8行。
E: 数据的输入
格式:E 地址 数值列表
地址: 数据输入的内存始地址
数值列表:从始地址输入的连续数据
用途:*向内存区域输入数据。数据以十六进制形式,或以ASCII码形式
均可。覆盖掉原有数据。
*十六进制时要用空格、逗号或制表符加以分隔。字符串则要用单
引号或双引号括起且区分大小写。
*若不指写段址,则默认为DS中值。每写完一数据地址自动增加。
*如省略数值列表,对应每一字节请求输入。点号前为该字节原
始值,点号后请求输入。这时若按空格,跳过这一字节;按回车,
结束输入;按减号或连字符,显示前一字节内容。
*出错时内存内容有可能已被改变。提示后终止。
*字符串只能以数值列表的形式输入,不能按地址提式输入。
F: 内存填充(Fill)
格式:F 地址范围 数值列表
地址范围:数据输入的内存始本地址或首地址和长度
数值列表:从始地址输入的连续数据
用途:*将列表中数据写入内存。输入数据以十六进制或ASCII码形式。
覆盖原有信息;若出错,显示出错信息,原有信息保留。
*若未指写段址,默认为DS寄存器值。
*列表中可有十六进制或字符串两种形式,各内容用空格、逗号、
制表符隔开。字符串必须以单引号或双引号括起,区分大小写。
*若要填充区域大于数据数目,列表可重复使用;相反,若列表
比要填充区域大时,则自动截断后面的数据。
G: 程序执行(Go)
格式:G
地址: Debug开始执行的地址。
断点0……断点9:指定的0—10个临时中断点。
用途:*将CPU控制权由Debug转移给被调试中的程序。不设断点时,则程
序的执行或是中途失败或是正常结束。结束时,提示有“Program
termminated nomally”,即程序结束正常,控制权再返回到
Debug。
*此时因数据有可能重写,若需再次执行,因重新装入。
*地址中,如未指定段址,则使用目标程序的CS寄存器中的值。当
地址省略时,则Debug使用目标程序的CS:IP寄存器的值开始执行。
且为与断点区分,地址参数前必须加等号,否则将其认为是第零
个断点。
*断点参数可指定10个临时断点。当程序执行到指定的断点地址时
则发生中止。与断点表内的次序无关,断点可按任意次序输入。
*中止时,将会显示寄存器的内容、标志位状态及CS:IP指出的指
令(也就是下一条将要执行的指令),然后是提示符“-”。
*若没有装入可执行程序或程序内容未知,有可能进入死状态。
*若目标程序的栈不起作用或太小,则可能引起系统“破碎”。
H: 执行十六进制算术运算(Hexadecimal)
格式:H 值1 值2
值1、2为0—FFFFH范围内的任意十六进制数。
用途:*用来求两个十六进制数的和、差,对结果显示为值1+值2及值1-
值2。如果值2 > 值1则显示其补码。
*虽然很少用,但事实还是很有用的,熟练掌握。
I: 端口的输入(Input)
格式:I 端口地址
端口地址:0—FFFF范围内的I/O端口地址。
用途:用来读取指定I/O端口地址,并以2位十六进制数加以显示。
警告:I指令将直接访问计算机硬件,不是所以错误检查都能进行,所以
使用是必须小心。对某个外设控制器分配端口的输入操作,可能
干涉系统固有的操作。对没有分配指定I/O端口的设备,或该端口
为写入专用端口等情况,I命令都不能保证可显示。
L: 装入命令(Load)
格式:L 地址
或
L 地址 驱动器 开始扇区 扇区数
地址: 存放从盘中读出数据的内存地址。
驱动器: A=0, B=1, C=2, 以此类推。
开始扇区:以十六进制数表示要最先装入的逻辑扇区号。
扇区数: 以十六进制数表示要装入连续扇区个数。
用途:*若输入了一个不完全的L命令时,则对下述磁盘文件进行装入:
1在Debug命令行中指定过的文件;
2由命令末尾参数N指定的文件。
*在地址中若未指定段址,则使用CS中的值。若为可执行文件按重
定位原则装入为可执行状态。
*装入后文件长度,或.exe文件程序的实际长度放入目标程序的BX
和CX两个寄存器中。高十六位放在BX中。
*若在命令行中给出所有参数,则不必用MS-DOS的文件系统访问磁
盘。
M: 数据传送(Move)
格式:M 地址范围 地址
地址范围:被复制域的始末地址,或始地址和长度。
地址: 数据复制目的域的起始地址。
用途:*对内存中数据进行复制。目的域被覆盖。
*若地址范围中无段址,则使用DS内容;若地址中无段址,使用地
址范围中的值。
N: 文件名或命令末尾的参数(Name)
格式:N 参数
参数:插入到仿真的PSP中去一个以上的文件名或者是开关项。
用途:*对磁盘读写操作L、W指定目标文件。
O: 端口的输出(Output)
格式:O 端口 字节
端口:I/O端口地址。
字节:写入I/O端口的0—FFFF范围的值。
用途:向I/O端口地址写入一字节。
警告:错误的操作将导致系统崩溃。
P: 循环或子程序处理(Procedure)
格式:P
地址: 执行的起始地址。
指令数:执行的指令条数。
用途:*循环或子程序处理。将循环、串指令、软件中断或子程序调用
视为单语句。执行中了,显示目标程序寄存器内容、标志位状态
和下一条要执行的指令。
*若地址参数中无段址,则使用CS中的值。完全忽略地址时,则从
程序中的CS:IP指定位置开始执行。
Q: 结束Debug操作(Quit)
格式:Q
用途:程序结束返回。对未保存的结果丢失。
R: 寄存器显示与更改(Register)
格式:R
寄存器:AX BX CX DX SP BP SI DI
DS ES CS IP PC
F
用途:*若R不带参数,则显示所有寄存器的内容和状态标志、下一指令。
*若指定新值,在显示内容后,给出冒句提示输入新值。回车结束。
*对状态字F,在连字符“-”后以空格间隔输入新值,次序不计。
*若直接回车,则跳过修改,寄存器内容不变。
S: 内存检索(Search)
格式:S 地址范围 列表
地址范围:想来你该明白是什么样了吧:)
列表: 欲检索的一个以上的字节值或字符串。
用途:*在指定的内存范围内检索列表的值。对每一个匹配的地址进行
显示。
*若起地址中无段址,默认为DS的值。
*检索范围不得大于FFFFH
*列表必须以分隔符(空格,逗号,制表符等)分隔;字符串要加
单引号或双引号括起,区分大小写。
T: 程序执行跟踪(Trace)
格式:T
地址: 执行的第一条指令的地址。
指定数:执行的机器指令的条数。
用途:*执行单条指令,显示寄存器及下一条指令。
*在地址参数中若无段址,则默认为CS寄存器的值。
*若全部省略,则由CS:IP寄存器指出的地址开始执行。
*以后则顺序执行。
*对ROM内的跟踪应使用T命令。
警告:对Intel 8259 中断屏幕的内容(IBM PC及兼容机端口20H和21H)
的更改,或者系统功能调用(INT 21H),不能使用T指令,对上述
情况要使用P指令。
U: 反汇编(Unassemble)
格式:U
用途:*将机器指定解码为汇编语言的助记符。
*地址范围中无段址时,默认使用CS值。
*当始地址与实际边界不一致时,结果将不可信。
*若不含末地址或长度,则自给定始地址起反汇编32个字节。
*以后由前次U最后一指令的下一指令做32字节的反汇编。
*若从没用过U,则于CS:IP开始进行反汇编。
*只能对8086指令解码,对其它以DB来显示。
W: 写入文件或扇区(Write)
格式:W
或
W 地址 驱动器 开始扇区 扇区数
地址: 待写入盘的数据在内存中的起始位置。
驱动器:写入数据的盘的驱动器号(A=0,B=1,C=2,以下类推)。
始扇区:写入数据的最前的逻辑扇区号(0—FFFFH)。
扇区数:写入数据的连续扇区个数(0—FFFFH)。
用途:*将内存中的文件或一个个扇区传送到磁盘上。
*W若不带参数,或只有地址参数,则按BX:CX寄存器指出的字节,从内
存向磁盘写入数据。此时的文件名是此命令前最后一个使用过的文件名
,或者是N命令中指定的文件,如果没有使用过N命令,则使用Debug命
令行中指定的文件。
*Debug的W命令,不能向扩展名为.EXE或.HEX的文件中写入数据。
*这可用改扩展名的方法得到应用,让其能对.exe文件写入。
*若无地址项,则认为是目标程序的CS:0100H。
*该命令可不通过MS-DOS的文件系统直接访问磁盘的逻辑扇区。但必须
以十六进制形式给在命令行中给定各参数。
*W命令不能对用于网络上的驱动器进行逻辑扇区写入处理。
警告:若参数有误,则可能破坏盘文件结构。
请务必先搞清再作试践,特别是对硬盘的操作。
--
※ 来源:·BBS 水木清华站 smth.org·
(本文采用S-Term文章拷贝脚本拷贝)
==================================================
Sender: liuxf (Flying Sword Flow), Forum: DOS
Subject: Detailed Explanation of Debug Commands
Posted: BBS Tsinghua Station (Mon Apr 23 16:16:59 2001)
Detailed Explanation of Debug Commands
There is no essence area, so I'll post it.
Command Line Parameter Format:
Format: DEBUG filename ]
Purpose: Debug loads the specified file into memory and displays the prompt "-" waiting for further commands. If the loaded file is an.exe file, it is loaded into an executable state according to the relocation principle. The.com file is similar. If it is another type of file, it is directly memory-mapped, and the offset 100H is read into memory as is.
Debug will create an appropriate PSP (Program Segment Prefix) in the buffer for the program being debugged. The offset 80H in the PSP is the end of the command line. Also, the default FCB (File Control Block) is composed of optional parameters after the parameters at offsets 5CH and 6CH.
Initial situation of each register when entering:
Register .com program .exe program
AX Specified drive error code Specified drive error code
BX High address of program space High address of program space
CX Low address of program space Low address of program space
DX 0 0
SI 0 0
DI 0 0
BP 0 0
SP 0FFFFH or the upper limit of available memory space minus 2 Indefinite
IP 100H Offset of the target program's code entry
CS PSP Segment address of the target program's code
DS PSP PSP
CS PSP PSP
SS PSP Bottom of the target program's stack segment
Command:
A: Write Assembly Code (Assemble)
Format: A
Purpose: The program allows assembly writing at the specified position (if there is no default, it is the position of the IP pointer).
Details:
* All values are hexadecimal integers, and the value is not followed by "H"
* Does not support directory tables, macro markers, conditional assembly for file management
* For jump instructions, directly write the hexadecimal address, and labels are not supported
* If the data type is not the default type, it must be specified with PTR
* String operations must specify the type as B or W (such as lodsb and lodsw, etc.) and length
* Use DB and DW to accept data definitions and directly assemble
* Add to the memory address to distinguish it from immediate numbers
C: Compare Memory Contents (Compare)
Format: C address range address
Address range: start and end addresses or start address and length of the first memory area for comparison
Address: Start address of the second memory area for comparison
Purpose: * Compare the contents of two areas in memory, byte by byte. For the content and address where a difference is found, it is displayed in the following form:
Address 1 start position end position address 2
* If the address range or address does not contain the segment address, the value of DS is default.
D: Display Memory Contents (Dump)
Format: D
Address range: Given start and end range or start address and length of the display area.
Purpose: * Memory content display instruction, displaying the memory content within the specified range in hexadecimal and ASCII code form.
* If the range is not specified, the first display starts at the address of CS:IP of the target program. Later, the display starts at the next address of the last displayed end address.
* If the length is not specified, the content of 128 bytes is displayed. There are 8 lines.
E: Input Data
Format: E address value list
Address: Start address of memory for data input
Value list: Continuous data input from the start address
Purpose: * Input data into the memory area. The data can be in hexadecimal form or ASCII code form. Overwrite the original data.
* When in hexadecimal, use spaces, commas, or tabs to separate. The string must be enclosed in single quotes or double quotes and is case-sensitive.
* If the segment address is not specified, the value in DS is default. Each data address is automatically increased after writing.
* If the value list is omitted, each byte is requested to be input. The original value of the byte is before the dot, and input is requested after the dot. At this time, if you press the space, skip this byte; press Enter to end the input; press the minus sign or hyphen to display the previous byte content.
* If there is an error, the memory content may have been changed. The prompt terminates.
* The string can only be input in the form of a value list and cannot be input by address prompt.
F: Fill Memory (Fill)
Format: F address range value list
Address range: start and end address or start address and length of data input
Value list: Continuous data input from the start address
Purpose: * Write the data in the list to the memory. The input data can be in hexadecimal or ASCII code form. Overwrite the original information; if there is an error, display the error message and the original information is retained.
* If the segment address is not specified, the value of the DS register is default.
* The list can have both hexadecimal and string forms, and each content is separated by spaces, commas, tabs. The string must be enclosed in single quotes or double quotes and is case-sensitive.
* If the area to be filled is larger than the number of data, the list can be reused; conversely, if the list is larger than the area to be filled, the subsequent data is automatically truncated.
G: Execute Program (Go)
Format: G
Address: The address where Debug starts to execute.
Breakpoint 0……breakpoint 9: Specified 0-10 temporary breakpoints.
Purpose: * Transfer the CPU control from Debug to the program being debugged. If there are no breakpoints, the program either fails halfway or ends normally. When it ends, it prompts "Program terminated normally", that is, the program ends normally, and the control returns to Debug.
* At this time, because the data may be rewritten, if you need to execute again, you need to reload.
* In the address, if the segment address is not specified, the value in the CS register of the target program is used. When the address is omitted, Debug uses the value of CS:IP register of the target program to start execution. And to distinguish from breakpoints, the address parameter must be preceded by an equal sign, otherwise it is considered as the 0th breakpoint.
* The breakpoint parameter can specify 10 temporary breakpoints. When the program executes to the specified breakpoint address, it will be suspended. Irrespective of the order in the breakpoint table, breakpoints can be entered in any order.
* When suspended, the content of the register, the state of the flag bit, and the instruction pointed to by CS:IP (that is, the next instruction to be executed) will be displayed, and then the prompt "-".
* If no executable program is loaded or the program content is unknown, it may enter a dead state.
* If the stack of the target program is not working or is too small, it may cause the system to "break".
H: Perform Hexadecimal Arithmetic Operations (Hexadecimal)
Format: H value 1 value 2
Values 1 and 2 are any hexadecimal numbers in the range 0-FFFFH.
Purpose: * Used to find the sum and difference of two hexadecimal numbers, and the result is displayed as value 1 + value 2 and value 1 - value 2. If value 2 > value 1, its complement is displayed.
* Although it is rarely used, it is actually very useful, so master it proficiently.
I: Input from Port (Input)
Format: I port address
Port address: I/O port address in the range 0-FFFF.
Purpose: Used to read the specified I/O port address and display it in 2-digit hexadecimal.
Warning: The I instruction will directly access the computer hardware, and not all error checks can be performed, so use it with caution. The input operation of allocating a port to a certain peripheral controller may interfere with the inherent operation of the system. For devices that do not allocate the specified I/O port, or for ports that are dedicated to writing, etc., the I command cannot guarantee to display.
L: Load Command (Load)
Format: L address
Or
L address drive start sector number of sectors
Address: Memory address where the data read from the disk is stored.
Drive: A=0, B=1, C=2, and so on.
Start sector: The logical sector number to be loaded first, expressed in hexadecimal.
Number of sectors: The number of consecutive sectors to be loaded, expressed in hexadecimal.
Purpose: * If an incomplete L command is entered, the following disk file is loaded:
1 The file specified in the Debug command line;
2 The file specified by the command end parameter N.
* If the segment address is not specified in the address, the value in CS is used. If it is an executable file, it is loaded into an executable state according to the relocation principle.
* The length of the loaded file, or the actual length of the.exe file program, is placed in the BX and CX registers of the target program. The high 16 bits are placed in BX.
* If all parameters are given in the command line, there is no need to access the disk using the MS-DOS file system.
M: Data Transfer (Move)
Format: M address range address
Address range: start and end addresses of the copied area, or start address and length.
Address: Start address of the data copy destination area.
Purpose: * Copy data in memory. The destination area is overwritten.
* If there is no segment address in the address range, the content of DS is used; if there is no segment address in the address, the value in the address range is used.
N: File Name or Command End Parameter (Name)
Format: N parameter
Parameter: Insert one or more file names or switch items into the simulated PSP.
Purpose: * Specify the target file for disk read and write operations L and W.
O: Output to Port (Output)
Format: O port byte
Port: I/O port address.
Byte: Value in the range 0-FFFF written to the I/O port.
Purpose: Write a byte to the I/O port address.
Warning: Incorrect operation will cause the system to crash.
P: Loop or Subroutine Processing (Procedure)
Format: P
Address: Start address of execution.
Number of instructions: Number of instruction lines to execute.
Purpose: * Loop or subroutine processing. Treat loops, string instructions, software interrupts, or subroutine calls as a single statement. During execution, the content of the target program register, the state of the flag bit, and the next instruction to be executed are displayed.
* If there is no segment address in the address parameter, the value in CS is used. If the address is completely omitted, execution starts from the position specified by CS:IP in the program.
Q: End Debug Operation (Quit)
Format: Q
Purpose: The program ends and returns. The unsaved results are lost.
R: Display and Change Registers (Register)
Format: R
Register: AX BX CX DX SP BP SI DI
DS ES CS IP PC
F
Purpose: * If R has no parameters, display the contents and status flags of all registers and the next instruction.
* If a new value is specified, after displaying the content, a colon prompt is given to enter the new value. Press Enter to end.
* For the status word F, enter the new value separated by spaces after the hyphen "-", and the order does not matter.
* If you press Enter directly, the modification is skipped and the register content remains unchanged.
S: Memory Search (Search)
Format: S address range list
Address range: I think you should understand what it is like :)
List: One or more byte values or strings to be searched.
Purpose: * Search for the value in the list within the specified memory range. Display each matching address.
* If there is no segment address in the start address, the value of DS is default.
* The search range must not be greater than FFFFH
* The list must be separated by delimiters (spaces, commas, tabs, etc.); the string must be enclosed in single quotes or double quotes and is case-sensitive.
T: Program Execution Trace (Trace)
Format: T
Address: The address of the first instruction to execute.
Number of instructions: Number of machine instructions to execute.
Purpose: * Execute a single instruction and display the register and the next instruction.
* If there is no segment address in the address parameter, the value of the CS register is default.
* If all are omitted, execution starts from the address pointed to by the CS:IP register.
* Then execute in sequence.
* Use the T command for tracing in ROM.
Warning: For the change of the content of the Intel 8259 interrupt screen (IBM PC and compatible machine ports 20H and 21H), or the system function call (INT 21H), the T instruction cannot be used. For the above situations, the P instruction should be used.
U: Disassemble (Unassemble)
Format: U
Purpose: * Decode the machine instruction into the mnemonic of assembly language.
* If there is no segment address in the address range, the value of CS is used by default.
* When the start address is inconsistent with the actual boundary, the result will be unreliable.
* If the end address or length is not included, disassemble 32 bytes starting from the given start address.
* Then disassemble 32 bytes from the next instruction of the last instruction of the previous U.
* If U has never been used, disassemble from CS:IP.
* Only decode 8086 instructions, and display others with DB.
W: Write to File or Sector (Write)
Format: W
Or
W address drive start sector number of sectors
Address: Start position in memory of the data to be written to the disk.
Drive: Drive number of the disk to write data (A=0, B=1, C=2, and so on).
Start sector: The first logical sector number to write data (0-FFFFH).
Number of sectors: Number of consecutive sectors to write data (0-FFFFH).
Purpose: * Transfer the file or sectors in memory to the disk.
* If W has no parameters or only the address parameter, write data from memory to the disk according to the bytes pointed to by the BX:CX register. At this time, the file name is the last file name used before this command, or the file specified in the N command. If the N command is not used, the file specified in the Debug command line is used.
* The W command of Debug cannot write data to files with extensions.EXE or.HEX.
* This can be applied by changing the extension to make it possible to write to.exe files.
* If there is no address item, it is considered as CS:0100H of the target program.
* This command can directly access the logical sector of the disk without passing through the MS-DOS file system. But each parameter must be given in hexadecimal form in the command line.
* The W command cannot process logical sector writing for drives used on the network.
Warning: If the parameters are incorrect, the disk file structure may be damaged.
Please be sure to figure it out before practicing, especially for hard disk operations.
--
※ Source:·BBS Tsinghua Station smth.org·
(Copied using S-Term article copy script)
==================================================
此帖被 +1 点积分 点击查看详情 评分人:【 vsbat 】 | 分数: +1 | 时间:2010-5-20 16:18 |
|
|