Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stepover command #1086

Merged
merged 5 commits into from
Apr 20, 2024
Merged

add stepover command #1086

merged 5 commits into from
Apr 20, 2024

Conversation

therealdreg
Copy link
Sponsor Collaborator

@therealdreg therealdreg commented Apr 19, 2024

Description

This pull request addresses a limitation in GDB where the "nexti" and "next" commands fail to step over call instructions properly. To resolve this, I have implemented a new feature, "stepover", specifically designed to enhance debugging efficiency by allowing users to step over call instructions seamlessly.

In my bootcamps, it’s a real pain to deal with this situation, especially for a GDB-newbie.


@Ordoviz

[Ordoviz](https://github.com/Ordoviz) [1 hour ago](https://github.com/hugsy/gef/pull/1086#discussion_r1571995694)
I also find this very useful for stepping over instructions with rep prefix.

POC

From a x86_64 Linux create a x32 binary

hello.asm

section .data
    msg db 'Hello, World!', 0xA
    len equ $ - msg
    testmsg db 'test!', 0xA
    lentestmsg equ $ - testmsg

section .text
    global _start

_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80
    call test

    mov eax, 1
    xor ebx, ebx
    int 0x80

test:
    mov eax, 4
    mov ebx, 1
    mov ecx, testmsg
    mov edx, lentestmsg
    int 0x80
    ret

Create executable:

nasm -f elf32 hello.asm -o hello.o
ld -m elf_i386 -s -o hello hello.o
strip hello

its impossible step over a call in GDB :(

image

The "nexti" and "next" commands do not work as expected :-(


btw, my Python skills are a bit rusty, sorry about that! xD

Checklist

  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

Copy link

🤖 Coverage update for 164c242 🟢

Old New
Commit d211658 164c242
Score 71.564% 71.564% (0)

@therealdreg therealdreg self-assigned this Apr 19, 2024
@therealdreg therealdreg added this to the 2024.05 milestone Apr 19, 2024
@Ordoviz
Copy link
Contributor

Ordoviz commented Apr 19, 2024

Pwndbg calls this command stepover (with alias so), which is a neater name IMO.

pwndbg> help so
usage: so [-h] [addr]

Breaks on the instruction after this one.

positional arguments:
  addr        The address to break after.

options:
  -h, --help  show this help message and exit

docs/commands/gnexti.md Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
@therealdreg therealdreg changed the title add gnexti command to step over instruction add so command to step over instruction Apr 19, 2024
Copy link

🤖 Coverage update for 40baf1a 🟢

Old New
Commit d211658 40baf1a
Score 71.564% 71.564% (0)

Copy link

🤖 Coverage update for 439b1e4 🟢

Old New
Commit d211658 439b1e4
Score 71.564% 71.564% (0)

Copy link

🤖 Coverage update for 0b2a9c2 🟢

Old New
Commit d211658 0b2a9c2
Score 71.564% 71.564% (0)

Copy link

🤖 Coverage update for fcd6265 🟢

Old New
Commit d211658 fcd6265
Score 71.564% 71.564% (0)

@therealdreg
Copy link
Sponsor Collaborator Author

@hugsy @Ordoviz @Grazfather opinion? looks good for you?

@hugsy
Copy link
Owner

hugsy commented Apr 20, 2024

Ok this is wild! This should be a GDB bug, is there any tracking of this?

@therealdreg
Copy link
Sponsor Collaborator Author

therealdreg commented Apr 20, 2024

Ok this is wild! This should be a GDB bug, is there any tracking of this?

@hugsy , I don't think it's a bug. I don't believe GDB is designed to step over instructions like call/rep/... for all architectures... Implementing this would be quite a hassle, right? This has been an issue for years.

Also, consider unusual cases like push + ret, polymorphic code, or if it's the last instruction in memory...

Copy link

🤖 Coverage update for ccb7424 🟢

Old New
Commit 399f457 ccb7424
Score 71.564% 71.564% (0)

Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me but the name, please change from so to stepover as a name everywhere, and make so an alias

Thanks!

gef.py Outdated Show resolved Hide resolved
@therealdreg therealdreg requested a review from hugsy April 20, 2024 15:23
Copy link

🤖 Coverage update for 3cbad34 🟢

Old New
Commit 399f457 3cbad34
Score 71.5776% 71.5776% (0)

Copy link

🤖 Coverage update for 310b71a 🟢

Old New
Commit 399f457 310b71a
Score 71.5776% 71.5776% (0)

Copy link

🤖 Coverage update for 060517f 🟢

Old New
Commit 399f457 060517f
Score 71.5776% 71.5776% (0)

@therealdreg
Copy link
Sponsor Collaborator Author

All looks good to me but the name, please change from so to stepover as a name everywhere, and make so an alias

Thanks!

done! @hugsy

@therealdreg therealdreg changed the title add so command to step over instruction add stepover command Apr 20, 2024
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

@therealdreg therealdreg merged commit 13af366 into hugsy:main Apr 20, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants