0

if I have the following assembly code:

foo:
  mov    $0x1,%rax
  callq  bar
  retq   

bar:
  dec    %r8
  cmp    $0x0,%r8
  je     end
  callq  foo
  mov    $0x5,%rax
  mov    $0x1,%rdi
end:
  retq   

_start:
 mov    $0x3,%r8
 callq  4000d4 <bar>
 

and I want to debug the function foo manually (by adding breakpoint to the start and end of the function using int 3 opcode to the machine code), but what is happening now is that the last time foo is called it does callq bar and doesn't return to the last line of foo thus losing the breakpoint, how can we solve this problem?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
CS2000
  • 51
  • 4
  • 2
    How many times do you expect `foo` to get called? The last return from `bar` is going to return to `_start`. – David Wohlferd Jan 25 '22 at 22:50
  • 1
    Are you sure you're putting an `int3` over all the `ret` instructions, instead of getting back into `foo` by having `bar` call back into it? Obviously if you do it right, placing `int3` 0xcc instructions via ptrace, and putting back to original byte before single-stepping and replacing the 0xCC, it should work. So if it's not the way you're doing it, you have a bug somewhere in the code you're not showing. [mcve]. – Peter Cordes Jan 25 '22 at 23:08

0 Answers0