How to make local labels in GNU GAS ELF output that GDB can break on but not count as functions?

前端 未结 1 1568
误落风尘
误落风尘 2020-12-21 03:44

When writing assembly manually with GNU GAS, within a function, I want to set a label such that:

  • GDB won\'t treat that label as the function name
  • I ca
相关标签:
1条回答
  • 2020-12-21 04:25

    I'm not sure if this fits your needs, but you can do this (for a non-PIE binary, so link with -no-pie):

    .text
    .global _start
    _start:
        /* exit */
        mov $60, %rax
    .Lmylabel:
        mov $0, %rdi
        syscall
        .section .rodata
    mylabel:
        .long .Lmylabel
    

    Then, you can set a breakpoint using break *mylabel (note the *):

    (gdb) break *mylabel
    Breakpoint 2 at 0x401007: file t.S, line 7.
    
    

    Since mylabel is more or less a function pointer, GDB does not know anything about it and will ignore it:

    Breakpoint 1, _start () at t.S:5
    5       mov $60, %rax
    (gdb) si
    7       mov $0, %rdi
    

    With a linker script, it should be possible to put the mylabel symbol into a section which is not loaded, to reduce run-time overhead.

    0 讨论(0)
提交回复
热议问题