Coder Social home page Coder Social logo

Comments (5)

Grazfather avatar Grazfather commented on May 24, 2024

so the current code relies on the user using an hexadecimal address and doesn't handle breakpoints set on a function.

Yeah that is not good. We could try to resolve the bp.location, but maybe check for Breakpoint.locations and use it if we can. If we can get the bp number, then using info breakpoints might be easy, but we probably don't want to run commands and parse its output too often, because it can slow down single-stepping (since it runs on every context print).

from gef.

Angelo942 avatar Angelo942 commented on May 24, 2024

For info breakpoints why do you want the bp number first ? I was thinking about a simple regex such as:

        breakpoints = gdb.execute("info breakpoints", to_string=True)
        bp_locations = re.findall(r'0x[0-9a-f]+', breakpoints)

For parsing bp.location I can start working on it, but I haven't figured out yet how to find the address of a symbol without relying on commands and it will never be perfect, because we have no way of parsing something like b *$rip.
So far I have sketched something like this:

    if GDB_VERSION >= (13, 1):
        bp_locations = [location.address for b in breakpoints for location in b.locations if location is not None]
    else:
        bp_locations = [self.parse_location(b.location) for b in breakpoints if b.location is not None] 

    @lru_cache()
    def parse_location(self, location: str) -> int:
        exact = False
        if location.startswith("*"):
            location = location[1:].strip() # Remove leading spaces
            if location.startswith("0x"):
                return int(location, 16)
            elif location.isdigit():
                return int(location)
            exact = True
        location = location.split("+") # Can a symbol have a 
        if len(location) == 2:
            symbol, offset = map(lambda x: x.strip(), location)
        else:
            symbol, offset = location[0], 0
        base_address = self.parse_symbol(symbol, exact=exact)
        
    def parse_symbol(self, symbol: str, exact=True) -> int:
        #TODO

from gef.

Grazfather avatar Grazfather commented on May 24, 2024

For info breakpoints why do you want the bp number first ? I

So that you can info breakpoint NUMBER so we know which line to parse. I was thinking if we wanted to look for a specific one.

For registers, that is tough, since the register value basically becomes irrelevant immediately after it's set.

I think that we should use hasattr instead of checking the GDB_VERSION, since it better guards against some distros maybe having patches that add the feature early or don't have it in 13.1.

What is your part with b.locations? Why would a breakpoint have more than one location, and from what I see, that attribute is not set.

from gef.

Angelo942 avatar Angelo942 commented on May 24, 2024

I think that we should use hasattr instead of checking the GDB_VERSION, since it better guards against some distros maybe having patches that add the feature early or don't have it in 13.1.

I didn't think about these cases. Okay 👍

What is your part with b.locations? Why would a breakpoint have more than one location, and from what I see, that attribute is not set.

I'm still on version 12.1 so I was looking for a docker to test it and for now I only sketched it based on the documentation. "Variable: Breakpoint.locations. Get the most current list of breakpoint locations that are inserted for this breakpoint". You may end up with a breakpoint in multiple locations if you set it on a line of the source code.

Regarding what to do now, I looked at the performances of info breakpoints and I saw how slow it is, making context take twice as long and getting slower with each additional breakpoint. I don't feel like I can handle the parsing though. Do I still test the code for b.locations and try to push a patch for those who have the new versions of gdb or do we wait to have something that works for everyone ?

from gef.

Grazfather avatar Grazfather commented on May 24, 2024

Thank you for testing the speed. I say we add just the hasattr, and basically behave better if we can.

from gef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.