Ejemplo n.º 1
0
    def GetLocation(self, location=None):
        """Get location of current line of execution, or location of provided location name."""
        import gdb
        try:
            if location == None:
                current_line = gdb.decode_line()
            else:
                try:
                    current_line = gdb.decode_line(location)
                except:
                    locationalt = "{0}:1".format(location)
                    current_line = gdb.decode_line(locationalt)

            symbol_table_and_line = current_line[1][0]
            symbol_table = symbol_table_and_line.symtab
            fullsource = symbol_table.fullname()
            source = symbol_table.filename
            line = symbol_table_and_line.line

            return fullsource, source, line
        except:
            if location == None:
                raise VimgdbError("Current location not detected")
            else:
                raise VimgdbError("Location '{0}' not found".format(location))
Ejemplo n.º 2
0
    def file_symbols(filename, regexp):
        '''Iterate over all symbols defined in a file.'''
        if not filename:
            return

        try:
            unparsed, sal_options = gdb.decode_line("'{}':1".format(filename))
        except gdb.error as e:
            # n.b. This is very brittle -- nothing in gdb specifies these error
            # strings, so they could easily change.
            # Until I find a better way, I'm simply adding each exception I
            # come across that I know is fine to ignore.
            # The only real way to get this is to add search_symbols as a
            # function into the gdb python interface.
            if e.args[0].startswith('No line 1 in file "'):
                return
            if e.args[0].startswith('No source file named '):
                return
            raise

        if unparsed:
            raise ValueError('Failed to parse {} as filename'.format(filename))

        # TODO Check source code and see if this is always the case.
        # NOTE: When there are more than one symbol and file options given from
        # the same source file, they all have the same set of symbol names.
        #   (as far as I can tell -- haven't yet looked at the gdb source).
        # Hence ignore any extra ones.
        sal = sal_options[0]
        for block in (sal.symtab.global_block(), sal.symtab.static_block()):
            yield from (sym for sym in block
                        if sym.is_function and re.match(regexp, sym.name))
Ejemplo n.º 3
0
 def invoke(self, arg, from_tty):
     bps = gdb.breakpoints()
     for bp in bps:
         s = gdb.decode_line(bp.location)[1][0]
         l = gdb.find_pc_line(s.pc)
         print l
         loc = ''
         
         print ("Breakpoint #%d - Location: %s Enabled: %s" % (bp.number, loc, bp.enabled))
Ejemplo n.º 4
0
 def get_locations(self, breakpoint):
     if breakpoint.location is not None:
         try:
             unparsed, locs = gdb.decode_line(breakpoint.location)
         except gdb.error:
             pass
         else:
             if locs:
                 return [ self.to_loc(loc) for loc in locs if self.to_loc(loc) ]
     return []
Ejemplo n.º 5
0
    def invoke(self, arg, from_tty):
        (remaining, locations) = gdb.decode_line(arg)
        if remaining is None:
            raise gdb.GdbError('printf format missing')
        remaining = remaining.strip(',')
        if locations is None:
            raise gdb.GdbError('no matching locations found')

        spec = arg[0:- len(remaining)]
        _LPrintfBreakpoint(spec, 'printf ' + remaining)
Ejemplo n.º 6
0
    def invoke(self, arg, from_tty):
        (remaining, locations) = gdb.decode_line(arg)
        if remaining is None:
            raise gdb.GdbError('printf format missing')
        remaining = remaining.strip(',')
        if locations is None:
            raise gdb.GdbError('no matching locations found')

        spec = arg[0:-len(remaining)]
        _LPrintfBreakpoint(spec, 'printf ' + remaining)
Ejemplo n.º 7
0
	def trigger(self, wp, time, action, value, pc):
		value = gdb.Value(value).cast(wp.vartype)
		if pc:
			sal = gdb.decode_line("*" + hex(pc))[1][0]
			pc = "%s:%d" % (sal.symtab.filename, sal.line)
		else:
			pc = ''
		if tpa_time.value == 'off':
			time = ''
		action = "%5s %s=%d" % (action, wp.varname, value)
		tpa_log.write("%s %-25s %s\n" % (time, action, pc))
Ejemplo n.º 8
0
 def invoke(self, arg, from_tty):
     (remaining, locations) = gdb.decode_line(arg)
     if self._verbose:
         print("-> Argument: {}".format(arg))
         print("-> Remaining: {}".format(remaining))
     if len(locations) != 1:
         gdb.GdbError("The command `BHCmd` supports just one location.")
     location = locations[0]
     if self._verbose:
         print("-> Location {}".format(location))
     spec = remaining and arg[0 : -len(remaining)] or arg[:]
     BHBp(spec, self._callback, location, remaining, self._go_on)
Ejemplo n.º 9
0
 def invoke(self, arg, from_tty):
     (window, arg) = self._parse_arg(arg, False)
     orig_arg = arg
     (ignore, arg) = gdb.decode_line(arg)
     if arg is None:
         raise gdb.GdbError("no printf arguments to 'gui dprintf'")
     arg = arg.strip()
     if not arg.startswith(','):
         raise gdb.GdbError("comma expected after linespec")
     arg = arg[1:]
     spec = arg[0:-len(arg)]
     DPrintfBreakpoint(spec, window, arg)
Ejemplo n.º 10
0
 def invoke(self, arg, from_tty):
     self.dont_repeat()
     (extra, sals) = gdb.decode_line(arg)
     if extra is not None:
         raise gdb.GdbError('unrecognized junk at end of command: ' + extra)
     if sals is None:
         raise gdb.GdbError('not found')
     if len(sals) > 1:
         print("Ambiguous linespec, only showing first result")
     sal = sals[0]
     if sal.symtab is None or sal.symtab.filename is None:
         raise gdb.GdbError('could not find file for symbol')
     gui.source.lru_handler.show_source_gdb(None, sal.symtab,
                                            sal.symtab.fullname(), sal.line)
Ejemplo n.º 11
0
	def invoke(self, arg, from_tty):
		print "_LPrintfCommmand arg="+str(arg)
		(remaining, locations) = gdb.decode_line(arg)
		if remaining is None:
			raise gdb.GdbError('printf format missing')
		remaining = remaining.strip(',')
		if locations is None:
			raise gdb.GdbError('no matching locations found')
		msg="_LPrintfCommmand remaining="+str(remaining)
		for loc in locations:
			msg=msg+" locations="+str(loc)
			print msg
		spec = arg[0:- len(remaining)]
		_LPrintfBreakpoint(spec, 'printf ' + remaining)
Ejemplo n.º 12
0
def get_symtab(filename):
    if filename == "":
        return None

    if filename in symtab_cache:
        return symtab_cache[filename]

    try:
        sal = gdb.decode_line(filename)[1][0]
    except gdb.error:
        symtab_cache[filename] = None
        return None

    symtab = sal.symtab
    symtab_cache[filename] = symtab
    return symtab
Ejemplo n.º 13
0
def get_bp_locations(bp):
    if bp.type != gdb.BP_BREAKPOINT:
        return []
    location = bp.location
    try:
        locs = gdb.decode_line(location)[1]
    except gdb.error:
        #current file have not location `location` then produce this error
        return []
    if locs == None:
        return []
    locations = []
    if locs:
        for loc in locs:
            line = loc.line
            if not loc.symtab:
                #maybe breakpoint have not location. For ex. `break exit`, `break abort`
                continue
            filename = loc.symtab.fullname()
            locations.append((filename, line))
    return locations
Ejemplo n.º 14
0
def _breakpoint_created(bp):
    if bp.location is None:
        return
    gui.adapt.notify_bug(18385)
    try:
        (rest, locs) = gdb.decode_line(bp.location)
    except:
        return
    if rest is not None:
        # Let's assume we couldn't reparse for some reason.
        return
    for sal in locs:
        if sal.symtab is None:
            continue
        entry = (sal.symtab.fullname(), sal.line)
        if entry not in _breakpoint_source_map:
            _breakpoint_source_map[entry] = set()
        if bp.number not in _breakpoint_source_map[entry]:
            _breakpoint_source_map[entry].add(bp.number)
            gui.events.location_changed.post(entry, True)
        else:
            _breakpoint_source_map[entry].add(bp.number)
Ejemplo n.º 15
0
    def file_symbols(filename, regexp):
        '''Iterate over all symbols defined in a file.'''
        if not filename:
            return

        try:
            unparsed, sal_options = gdb.decode_line("'{}':1".format(filename))
        except gdb.error as e:
            if e.args[0].startswith('No line 1 in file "'):
                return
            raise

        if unparsed:
            raise ValueError('Failed to parse {} as filename'.format(filename))

        # TODO Check source code and see if this is always the case.
        # NOTE: When there are more than one symbol and file options given from
        # the same source file, they all have the same set of symbol names.
        #   (as far as I can tell -- haven't yet looked at the gdb source).
        # Hence ignore any extra ones.
        sal = sal_options[0]
        for block in (sal.symtab.global_block(), sal.symtab.static_block()):
            yield from (sym for sym in block
                        if sym.is_function and re.match(regexp, sym.name))
Ejemplo n.º 16
0
def decode_1arg(s):
    from _common import zdecode
    x = gdb.decode_line(s)
    zdecode(x)
Ejemplo n.º 17
0
import gdb

tuple = gdb.decode_line("test1.c:print_name")
symtab_and_line = tuple[0]

print "line: " + str(symtab_and_line.line)
print "last: " + str(symtab_and_line.last)

print "filename: " + symtab_and_line.symtab.filename
print "fullname: " + symtab_and_line.symtab.fullname()


tuple = gdb.decode_line("test2.c:print_name")
symtab_and_line = tuple[0]

print "line: " + str(symtab_and_line.line)
print "last: " + str(symtab_and_line.last)

print "filename: " + symtab_and_line.symtab.filename
print "fullname: " + symtab_and_line.symtab.fullname()
Ejemplo n.º 18
0
def decode_0args():
    from _common import zdecode
    x = gdb.decode_line()
    zdecode(x)
Ejemplo n.º 19
0
 def get_locations(self, breakpoint):
     unparsed, locs = gdb.decode_line(breakpoint.location)
     if locs:
         return [ self.to_loc(loc) for loc in locs if self.to_loc(loc) ]
Ejemplo n.º 20
0
def get_func_block(funcName):
    # this is a completely and utterly ridiculous thing to have to do...
    pc = gdb.decode_line(funcName)[1][0].pc
    return gdb.block_for_pc(pc)
Ejemplo n.º 21
0
def parse_breakpoints():
    rawmib = gdb.execute("maint info break", False, True).split("\n")
    foo = """
Num     Type                  Disp Enb Address            What
1       breakpoint            keep y   0x0000000000402233 in main(int, char const**) at vtrack.cxx:30 inf 1
        breakpoint already hit 1 time
1.1                                y   0x0000000000402233 in main(int, char const**) at vtrack.cxx:30 inf 1
-1      shlib events          keep n   0x00007ffff7fd0101 <dl_main+7169> inf 1
-1.1                               y   0x00007ffff7fd0101 <dl_main+7169> inf 1

"""
    mib = {}
    for mi in rawmib:
        mi = mi.split()
        #        print("mi = '%s'" % mi )
        if (len(mi) == 0 or mi[0] == "Num"):
            continue
        mk = mi[0].split(".")
        if (not mk[0].isdigit()):
            continue
        if (len(mk) == 1):
            mk = (mk[0], None)
        else:
            mk = (mk[0], mk[1])
        mib[mk] = mi

    ret = {}
    import vdb
    if (vdb.enabled("backtrace")):
        import vdb.backtrace

    previous_type = None
    for mk, mi in mib.items():
        #        print("mk = '%s'" % (mk,) )
        #        print("mi = '%s'" % mi )
        if (mk[0][0] == "-"):
            continue

        sp = stoppoint()
        sp.key = mk
        sp.number = mi[0]

        ixplus = 0
        address_there = True
        if (mk[1] is None):
            ixplus = 2
            sp.type = mi[1]
            if (sp.type == "hw"):
                sp.type += " " + mi[2]
                mi[1] += " " + mi[2]
                del mi[2]
                address_there = False

            previous_type = sp.type
            sp.temporary = mi[2]
        else:
            ixplus = 0
        sp.enabled = (mi[1 + ixplus] == "y")
        #        print("sp.type = '%s'" % sp.type )

        if (sp.type == "catchpoint" or sp.type == "watchpoint"):
            address_there = False
        if (previous_type == "watchpoint"):
            address_there = False

        if (address_there):
            sp.address = vdb.util.mint(mi[2 + ixplus])
        else:
            ixplus -= 1
            sp.address = ""
        sp.what = " ".join(mi[3 + ixplus:])

        #        print("sp.what = '%s'" % sp.what )
        m = re.match("in (.*) at (.*):([0-9]*) inf ([0-9]*)", sp.what)
        if (m):
            plain = ""
            color = ""

            plain = "in "
            plain += m.group(1)
            plain += " at "
            plain += m.group(2)
            plain += ":"
            plain += m.group(3)
            sp.what = plain
            if (vdb.enabled("backtrace")):
                color = "in "
                color += vdb.color.color(m.group(1),
                                         vdb.backtrace.color_function.value)
                color += " at "
                color += vdb.color.color(m.group(2),
                                         vdb.backtrace.color_filename.value)
                color += ":"
                color += m.group(3)
                sp.what = (color, len(plain))

            sp.inferior = m.group(4)
        else:
            m = re.match("(.*) inf ([0-9]*)", sp.what)
            if (m):
                sp.what = m.group(1)
                sp.inferior = m.group(2)

#        print("sp.number = '%s'" % sp.number )
#        print("type(sp.number) = '%s'" % type(sp.number) )
        ret[sp.number] = sp

#    print("ret = '%s'" % ret )
    bps = gdb.breakpoints()
    for bp in bps:
        #        print("type(bp.number) = '%s'" % type(bp.number) )
        sp = ret.get(str(bp.number))
        #        print("bp.number = '%s'" % bp.number )
        #        print("sp = '%s'" % sp )
        #        print("bp = '%s'" % bp )
        sp.type = bp.type
        sp.enabled = bp.enabled
        sp.temporary = bp.temporary
        sp.location = bp.location
        sp.expression = bp.expression

        if (sp.address is None):
            unparsed, locs = gdb.decode_line(bp.location)
            if (len(locs) == 1):
                addr = locs[0]
                addr = addr.pc
            else:
                addr = "<MULTIPLE>"

            sp.address = addr

        for i in range(1, 1000):
            sk = "%s.%s" % (sp.number, i)
            esp = ret.get(sk, None)
            if (esp is None):
                break
            sp.subpoints[sk] = esp
            del ret[sk]

#    print("Dump RET")
#    for k,r in ret.items():
#        print("")
#        r._dump()
    return ret