assembly 如何理解广发中的版画?

f1tvaqid  于 2023-02-23  发布在  其他
关注(0)|答案(1)|浏览(86)

我有汇编代码,

.section .data
    value1:
        .int 1 
    value2:
        .short 2
    value3:
        .byte 3
.global _start   
 _start:      
        nop
        movl value1,%ecx
    movw value1,%bx
    movw value2,%bx
    movb value3,%cl
         movl $1, %eax  
        movl $0, %ebx  
        int $0x80

我用as和ld得到了可执行的二进制文件,但是在GDB中,我不能打印value2.enter image description here
为什么?我很困惑。
我发现地址不在数据区。

xwbd5t1u

xwbd5t1u1#

一些问题...

  1. .section .text * 应该在 * .global _start之前,以便_start.text部分中结束
    1.添加-g以获取调试信息
    不幸的是,将-g添加到.c编译中是可以的,但是对于.s文件就不太好用了
    下面是一个简单的C程序,与您的程序类似:
int value1;
short value2;
unsigned char value3;

我们可以用-S编译得到一个.s文件。我们可以用-g也可以不用-g。没有-g.s文件是7行。增加-g增加到150行。
调试信息必须使用特殊的asm指令添加(例如.loc.section .debug_info,"",@progbits)。
这样,gdb就有了足够的信息来允许p(或x)工作。
要让p在没有调试信息的情况下工作,我们必须将值转换为正确的类型。

p (int) value1
p (short) value2
p (char) value3

以下是.c示例文件 * 的.s输出(不含 * -g):

.file   "short.c"
    .text
    .comm   value1,4,4
    .comm   value2,2,2
    .comm   value3,1,1
    .ident  "GCC: (GNU) 8.3.1 20190223 (Red Hat 8.3.1-2)"
    .section    .note.GNU-stack,"",@progbits

以下是.s的输出 *,带有 * -g

.file   "short.c"
    .text
.Ltext0:
    .comm   value1,4,4
    .comm   value2,2,2
    .comm   value3,1,1
.Letext0:
    .file 1 "short.c"
    .section    .debug_info,"",@progbits
.Ldebug_info0:
    .long   0x71
    .value  0x4
    .long   .Ldebug_abbrev0
    .byte   0x8
    .uleb128 0x1
    .long   .LASF5
    .byte   0xc
    .long   .LASF6
    .long   .LASF7
    .long   .Ldebug_line0
    .uleb128 0x2
    .long   .LASF0
    .byte   0x1
    .byte   0x1
    .byte   0x5
    .long   0x33
    .uleb128 0x9
    .byte   0x3
    .quad   value1
    .uleb128 0x3
    .byte   0x4
    .byte   0x5
    .string "int"
    .uleb128 0x2
    .long   .LASF1
    .byte   0x1
    .byte   0x2
    .byte   0x7
    .long   0x50
    .uleb128 0x9
    .byte   0x3
    .quad   value2
    .uleb128 0x4
    .byte   0x2
    .byte   0x5
    .long   .LASF2
    .uleb128 0x2
    .long   .LASF3
    .byte   0x1
    .byte   0x3
    .byte   0xf
    .long   0x6d
    .uleb128 0x9
    .byte   0x3
    .quad   value3
    .uleb128 0x4
    .byte   0x1
    .byte   0x8
    .long   .LASF4
    .byte   0
    .section    .debug_abbrev,"",@progbits
.Ldebug_abbrev0:
    .uleb128 0x1
    .uleb128 0x11
    .byte   0x1
    .uleb128 0x25
    .uleb128 0xe
    .uleb128 0x13
    .uleb128 0xb
    .uleb128 0x3
    .uleb128 0xe
    .uleb128 0x1b
    .uleb128 0xe
    .uleb128 0x10
    .uleb128 0x17
    .byte   0
    .byte   0
    .uleb128 0x2
    .uleb128 0x34
    .byte   0
    .uleb128 0x3
    .uleb128 0xe
    .uleb128 0x3a
    .uleb128 0xb
    .uleb128 0x3b
    .uleb128 0xb
    .uleb128 0x39
    .uleb128 0xb
    .uleb128 0x49
    .uleb128 0x13
    .uleb128 0x3f
    .uleb128 0x19
    .uleb128 0x2
    .uleb128 0x18
    .byte   0
    .byte   0
    .uleb128 0x3
    .uleb128 0x24
    .byte   0
    .uleb128 0xb
    .uleb128 0xb
    .uleb128 0x3e
    .uleb128 0xb
    .uleb128 0x3
    .uleb128 0x8
    .byte   0
    .byte   0
    .uleb128 0x4
    .uleb128 0x24
    .byte   0
    .uleb128 0xb
    .uleb128 0xb
    .uleb128 0x3e
    .uleb128 0xb
    .uleb128 0x3
    .uleb128 0xe
    .byte   0
    .byte   0
    .byte   0
    .section    .debug_aranges,"",@progbits
    .long   0x1c
    .value  0x2
    .long   .Ldebug_info0
    .byte   0x8
    .byte   0
    .value  0
    .value  0
    .quad   0
    .quad   0
    .section    .debug_line,"",@progbits
.Ldebug_line0:
    .section    .debug_str,"MS",@progbits,1
.LASF1:
    .string "value2"
.LASF5:
    .string "GNU C17 8.3.1 20190223 (Red Hat 8.3.1-2) -mtune=generic -march=x86-64 -g"
.LASF0:
    .string "value1"
.LASF6:
    .string "short.c"
.LASF2:
    .string "short int"
.LASF3:
    .string "value3"
.LASF4:
    .string "unsigned char"
.LASF7:
    .string "/tmp/asm"
    .ident  "GCC: (GNU) 8.3.1 20190223 (Red Hat 8.3.1-2)"
    .section    .note.GNU-stack,"",@progbits

相关问题