0

I have the following assembly, which I'd like to see how the:

push %rbp
mov %rsp, %rbp

work before the actual code starts, for example:

.globl main
main:
    push %rbp
    mov %rsp, %rbp
    movq $8, -8(%rbp)
    mov -8(%rbp), %rax
    pop %rbp
    ret

However, when I run gdb and then b main and then run, it starts directly on the instruction movq $0x8,-0x8(%rbp). Is there a way to "start from the top" and not skip the prologue?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • `starti` will start at the top of `_start`, but I think `start` is going to always stop at wherever it wants in `main`. You can set a breakpoint at the numeric address of the top of `main`, like `b *0x123456` (copy/paste the real number) to sidestep GDB's normal skip-the-prologue "feature". Or apparently `b *main` works, per this answer: [How does GDB determine the address to break at when you do "break function-name"?](https://stackoverflow.com/a/31451340) – Peter Cordes Aug 12 '20 at 03:16
  • 1
    Don't forget to search for duplicate questions before posting; especially for this one it seems easy to find. For me, a google search on `site:stackoverflow.com gdb break before prologue` found several hits including [Why is GDB breakpoint set at the wrong address for an x86 assembly function?](https://stackoverflow.com/q/46878778) and the duplicates I used to close this. – Peter Cordes Aug 12 '20 at 03:22
  • @PeterCordes thanks, the answer with doing `*main` works great. What do you mean by "copy/paste the memory address" -- how/where would I find that address? – samuelbrody1249 Aug 12 '20 at 03:41
  • 1
    Before searching and finding you could use `*main` instead of a numeric address, I meant finding the address from disassembly in GDB; it shows you the addresses. Or `p main` should also show you the address. Then copy/paste that or type it on a `b *number` command. But since `b *main` works, you don't need to do that. However, that is a way to set a breakpoint on any instruction you want without having to figure out a line number for it or anything like that. – Peter Cordes Aug 12 '20 at 03:55

0 Answers0