linux – 如何调试需要用户输入的NASM汇编程序?

linux – 如何调试需要用户输入的NASM汇编程序?,第1张

概述我正在阅读杰夫的惊人书籍 assembly step by step,我在第8章,他展示了一个汇编程序的例子,它以这种方式从用户那里获取文件: SECTION .bss ; Section containing uninitialized data BUFFLEN equ 1024 ; Length of buffer Buff: resb BUF 我正在阅读杰夫的惊人书籍 assembly step by step,我在第8章,他展示了一个汇编程序的例子,它以这种方式从用户那里获取文件:

SECTION .bss            ; Section containing uninitialized data    BUFFLEN equ 1024    ; Length of buffer    Buff:   resb BUFFLEN    ; Text buffer itself

它将文件文本读入Buff,并将ALL CAPS中该文本的一个版本输出到另一个文件.

我想在调试模式下运行该程序,以逐步分析所有寄存器的情况.

我正在使用INSIGHT在ubuntu上运行它.

我是一个完全的初学者.我知道如何使用Insight来逐步完成,但用户运行此程序的方式是:

myProgram > outputfile.txt < inputfile.txt

我如何在调试器中模仿这个?

这里是完整的来源:

;  Executable name : uppercaser2;  Version         : 1.0;  Created date    : 3/25/2009;  Last update     : 3/25/2009;  Author          : Jeff Duntemann;  Description     : A simple program in assembly for linux,using NASM 2.05,;    demonstrating simple text file I/O (through redirection) for reading an;    input file to a buffer in blocks,forcing lowercase characters to ;    uppercase,and writing the modifIEd buffer to an output file.;;  Run it this way:;    uppercaser2 > (output file) < (input file)  ;;  Build using these commands:;    nasm -f elf -g -F stabs uppercaser2.asm;    ld -o uppercaser2 uppercaser2.o;SECTION .bss            ; Section containing uninitialized data    BUFFLEN equ 1024    ; Length of buffer    Buff:   resb BUFFLEN    ; Text buffer itselfSECTION .data           ; Section containing initialised dataSECTION .text           ; Section containing codeglobal  _start          ; linker needs this to find the entry point!_start:    nop         ; This no-op keeps gdb happy...; Read a buffer full of text from stdin:read:    mov eax,3       ; Specify sys_read call    mov ebx,0       ; Specify file Descriptor 0: Standard input    mov ecx,Buff        ; Pass offset of the buffer to read to    mov edx,BUFFLEN     ; Pass number of bytes to read at one pass    int 80h         ; Call sys_read to fill the buffer    mov esi,eax     ; copy sys_read return value for safekeePing    cmp eax,0       ; If eax=0,sys_read reached EOF on stdin    je Done         ; Jump If Equal (to 0,from compare); Set up the registers for the process buffer step:    mov ecx,esi     ; Place the number of bytes read into ecx    mov ebp,Buff        ; Place address of buffer into ebp    dec ebp         ; Adjust count to offset; Go through the buffer and convert lowercase to uppercase characters:Scan:    cmp byte [ebp+ecx],61h  ; Test input char against lowercase 'a'    jb Next         ; If below 'a' in ASCII,not lowercase    cmp byte [ebp+ecx],7Ah  ; Test input char against lowercase 'z'    ja Next         ; If above 'z' in ASCII,not lowercase                ; At this point,we have a lowercase char    sub byte [ebp+ecx],20h  ; Subtract 20h to give uppercase...Next:   dec ecx         ; Decrement counter    jnz Scan        ; If characters remain,loop back; Write the buffer full of processed text to stdout:Write:    mov eax,4       ; Specify sys_write call    mov ebx,1       ; Specify file Descriptor 1: Standard output    mov ecx,Buff        ; Pass offset of the buffer    mov edx,esi     ; Pass the # of bytes of data in the buffer    int 80h         ; Make kernel call    jmp read        ; Loop back and load another buffer full; All done! Let's end this party:Done:    mov eax,1       ; Code for Exit Syscall    mov ebx,0       ; Return a code of zero     int 80H         ; Make kernel call
解决方法 听起来你想将进程附加到GDB.你可以试试这个.

shell$gdb ./uppercaser2  gdb> List  gdb> break read  gdb> run > ouput.txt < input.txt  gdb> x/5i $eip

在shell提示符下,启动GDB并将uppercaser2附加到GDB.应加载调试符号,您可以使用列表来检查来源.通过行号或功能名称在所需位置创建断点.使用GDB的运行来启动输入和输出文件的程序.从这里,您可以使用GDB命令分析寄存器并逐步执行内存.

总结

以上是内存溢出为你收集整理的linux – 如何调试需要用户输入的NASM汇编程序?全部内容,希望文章能够帮你解决linux – 如何调试需要用户输入的NASM汇编程序?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1017558.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存