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

Python exception under gdb-8.2-2 #523

Closed
hexhexd opened this issue Sep 12, 2018 · 12 comments

Comments

Projects
None yet
7 participants
@hexhexd
Copy link

commented Sep 12, 2018

Description

Hi,

I just recently updated gdb to 8.2-2 on Arch. Now pwndbg commands will trigger the warnings below:

pwndbg> pwndbg
Python Exception <class 'ValueError'> invalid literal for int() with base 10: 'warning:':
Error occurred in Python command: invalid literal for int() with base 10: 'warning:'

And gdb changelog mentioned various Python API enhancements.

Steps to reproduce

My setup

@disconnect3d

This comment has been minimized.

Copy link
Member

commented Sep 12, 2018

Hey, thanks for the issue. I will try to dive into that in a free time.
As I am occupied with a lot of stuff recently, it might take few days or 1-2 weeks :(.

If you are willing to help, I would be happy to help/answer questions here or in #pwndbg freenode irc channel.

PS: from gdb changelog

* Python API

  ** Type alignment is now exposed via the "align" attribute of a gdb.Type.

  ** The commands attached to a breakpoint can be set by assigning to
     the breakpoint's "commands" field.

  ** gdb.execute can now execute multi-line gdb commands.

  ** The new functions gdb.convenience_variable and
     gdb.set_convenience_variable can be used to get and set the value
     of convenience variables.

  ** A gdb.Parameter will no longer print the "set" help text on an
     ordinary "set"; instead by default a "set" will be silent unless
     the get_set_string method returns a non-empty string.
@hexhexd

This comment has been minimized.

Copy link
Author

commented Sep 13, 2018

Sounds good. I'll give it a try.

@ecx86

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2018

In pwndbg/commands/__init__.py, check_repeated.

    def check_repeated(self, argument, from_tty):
        """Keep a record of all commands which come from the TTY.

        Returns:
            True if this command was executed by the user just hitting "enter".
        """
        # Don't care unless it's interactive use
        if not from_tty:
            return False

        lines = gdb.execute('show commands', from_tty=False, to_string=True)
        lines = lines.splitlines()

        # No history
        if not lines:
            return False

        last_line = lines[-1]

last_line = warning: bad breakpoint number at or near '0' rather than expected output

pwndbg> python
>import gdb
>print gdb.execute('show commands 9999999999')
>warning: bad breakpoint number at or near '0'
No breakpoint number 1410065407.

But regular 'show commands' is ok???

pwndbg> show commands
   87  python print __import__('gdb').execute('show commands', from_tty=True)
   88  python print __import__('gdb').execute('s commands', from_tty=True)
   89  python print __import__('gdb').execute('sho commands', from_tty=True)
   90  python print __import__('gdb').history
   91  python print __import__('gdb').history(0)
   92  show commands
   93  python print __import__('gdb').execute('show Commands', from_tty=True)
   94  python print __import__('gdb').execute('show command', from_tty=True)
   95  show commands
   96  show commands

This is stupid. Regression from gdb's side? Probably due to this changelog item:

The commands attached to a breakpoint can be set by assigning to
     the breakpoint's "commands" field.

GDB sucks.

@ecx86

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2018

Temporary workaround, just make the function return False or True.
We need a fix from GDB folks, ugh.

@bennofs

This comment has been minimized.

Copy link
Contributor

commented Sep 29, 2018

This is gdb bug https://sourceware.org/bugzilla/show_bug.cgi?id=23669. It was caused by commit 56bcdbea2bed ("Let gdb.execute handle multi-line commands") in GDB.

Note that this commit broke other things in pwndbg as well. For example, all commands executed though execute are now added to the last-command history, so s followed by ENTER now doesn't work anymore (since pwndbg's hooks execute commands in between that override the s so the s is no longer the last command)

There's a really ugly hack to work around the show commands bug: use eval "show commands". Not sure how to work around the "repeat last command" bug.

@disconnect3d

This comment has been minimized.

Copy link
Member

commented Sep 30, 2018

Thanks for inspecting this. It seems we have to wait a little bit more for a GDB release :(.

@disconnect3d disconnect3d added the bug label Sep 30, 2018

@bennofs

This comment has been minimized.

Copy link
Contributor

commented Oct 19, 2018

The other bug that is relevant for pwndbg is this one: https://sourceware.org/bugzilla/show_bug.cgi?id=23714. If you build from git, include the patch there and pwndbg should work with new gdb.

@gymgit

This comment has been minimized.

Copy link
Contributor

commented Nov 22, 2018

I still experience this issue on arch with up to date gdb and gdb-multiarch as a temporary work around I suggest adding the following exception case:

        lines = gdb.execute('show commands', from_tty=False, to_string=True)
        lines = lines.splitlines()

        # No history
        if not lines:
            return False

        last_line = lines[-1]
        
        number, command = last_line.split(None, 1)
        try:
            number = int(number)
        except ValueError:
            # Fixes gdb bug when show command fails
            return False
@disconnect3d

This comment has been minimized.

Copy link
Member

commented Nov 22, 2018

@gymgit can u send a pr with this workaround? if there is a way, pls check a gdb version too (i think we have this somewhere in the codebase).

@TheAifam5

This comment has been minimized.

Copy link

commented Nov 23, 2018

@disconnect3d Its actually flagged as "RESOLVED FIXED", so should be in the next release.

@Aloxaf

This comment has been minimized.

Copy link

commented Jan 5, 2019

gdb 8.2.1 has been released: http://lists.gnu.org/archive/html/info-gnu/2018-12/msg00013.html
This bug seems to have been fixed.

@disconnect3d

This comment has been minimized.

Copy link
Member

commented Jan 7, 2019

@Aloxaf Thx for noticing this! I am closing the issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.