Example #1
0
    def invoke(self, arg, from_tty):
        leak_rpt = gdb.execute('monitor leak_check full any', to_string = True)

        # extract the loss record number from the leak report
        rx = re.compile('are (definitely|possibly) lost in loss record ([0-9]+) of')
        m = rx.search(leak_rpt)
        if not m:
            print('no loops found')
            return

        # request block list for that record number
        blockno = m.group(2)
        bl_rpt = gdb.execute('monitor block_list %s'%blockno, to_string = True)

        # get the allocation backtrace for this initial block
        trace_re = re.compile('(at|by) 0x[0-9A-Fa-f]+: ')
        backtrace = ''
        for ln in bl_rpt.splitlines():
            if trace_re.search(ln):
                backtrace += ln + '\n'

        # extract the first block and call "who_points_at" to get pointers
        # key part is the single indentation - the first entry:
        blre = re.compile('=+[0-9]+=+ (0x[0-9A-F]+)\[')
        m = blre.search(bl_rpt)

        g = PointerGraph(m.group(1))
        g.backtraces = g.new_vertex_property('string')
        g.backtraces[g.root] = backtrace
        pred = g.new_vertex_property('int64_t')
        vis = LoopFindVisitor(g, pred, PrintPtrLoop.expand_vertex, PrintPtrLoop.report_backedge)
        dfs_search(g, g.root, vis)
Example #2
0
    def _filter_short_branch(self, filter=False, short=30):
        """
        filter out very short branches: do this maybe not right for some models, for models with flat part, it is right
        I will test how this effect the final matching results
        need to delete nodes, switch with the last one then delete last
        """
        if filter == False:
            self.verts = self.verts_init
            self.edges = self.edges_init
        else:
            init_graph = Graph(directed=False)
            init_graph.add_vertex(len(self.verts_init))
            for edge in self.edges_init:
                init_graph.add_edge(init_graph.vertex(edge[0]), init_graph.vertex(edge[1]))

            terminal_node = []
            for v in init_graph.vertices():
                if v.out_degree() == 1:
                    terminal_node.append(v)

            visitor = DepthVisitor()
            short_nodes = []
            for tn in terminal_node:
                search.dfs_search(init_graph, tn, visitor)
                tmp_node = visitor.get_short_branch(min_length=short)
                visitor.reset()
                for n in tmp_node:
                    short_nodes.append(n)

            ## get edges on the short paths
            short_nodes = list(set(short_nodes))
            short_edges = []
            temp_verts = self.verts_init[:]
            v_num = len(self.verts_init)
            if len(short_nodes):
                for v in reversed(sorted(short_nodes)):
                    for ve in init_graph.vertex(v).out_edges():
                        short_edges.append(ve)

                ## delete edges first, then vertex
                short_edges = list(set(short_edges))
                for e in short_edges:
                    init_graph.remove_edge(e)

                print 'deleting vertex',
                for v in reversed(sorted(short_nodes)):
                    print v,
                    temp_verts[int(v)] = temp_verts[v_num-1]
                    init_graph.remove_vertex(v, fast=True)
                    v_num -= 1
                print '\ndeleting related edges' # already done above, just info user
            else:
                print 'no short branches'

            ######## new vertices and edges ########
            self.verts = temp_verts[:v_num]
            self.edges = []
            for e in init_graph.edges():
                self.edges.append([int(e.source()), int(e.target())])
Example #3
0
 def apply(self):
     self.compute_defs()
     self.compute_gens_kills()
     dfs = DepthFirstSearchVisitor()
     dfs_search(self.cfg, self.cfg.vertex(0), dfs)
     done = False
     while not done:
         in_old = {
             n: {var
                 for var in var_set}
             for (n, var_set) in self.in_b.items()
         }
         out_old = {
             n: {var
                 for var in var_set}
             for (n, var_set) in self.out_b.items()
         }
         for v in reversed(dfs.postorder):
             self.in_b[v].clear()
             for p in v.in_neighbours():
                 self.in_b[v].update(self.out_b[p])
             self.out_b[v] = self.gen_b[v] | (self.in_b[v] - self.kill_b[v])
         done = not self.sets_changed(in_old, out_old)
     self.propagate_dataflow_to_statements()
Example #4
0
    # creating individual pages for family members
    if args.pagedir is not None:
        g.create_html_structure(args.pagedir)

    # if only --pagedir was requested
    if args.out is None:
        sys.exit()

    # optional subgraph selection
    if args.start is not None:
        start = g.by_id(args.start, False)
        root = g.add_vertex()
        ancestor_gatherer = Gatherer()
        # find all ancestors of the node
        dfs_search(GraphView(g, reversed=True), start, ancestor_gatherer)
        for ancestor in ancestor_gatherer.visited:
            g.add_edge(root, ancestor)
        g.vp.selected = g.new_vertex_property('bool')
        # find all ancestors' descendants
        dfs_search(g, root, Selector(g))
        g.remove_vertex(root)
        # include all spouses
        for v in g.vertices():
            if g.vp.selected[v] and g.vp.gedid[v][0] == 'F':
                for w in v.in_neighbors():
                    g.vp.selected[w] = True
        g.set_vertex_filter(g.vp.selected)

    # filtering out the main line of inheritance
    g.fix_main_branch()
        v = e.source()
        while (v != e.target()):
            sys.stdout.write("->" + self.graph.vname[v])
            v = self.predecessor[v]
        print "->" + self.graph.vname[e.target()]

if __name__ == "__main__":
    kohm = pq.Quantity(1e3,    "ohm")
    ff   = pq.Quantity(1e-15,  "farad")

    # construct graph with a resistive loop
    r_loop = CktGraph()
    gnd  = r_loop.gnd

    n1  = r_loop.add_node("n1")
    n2  = r_loop.add_node("n2")         # starting point for resistor loop
    r_loop.add_comp(n1, n2, 100.*kohm)
    r_loop.add_comp(n2, gnd, 10.*ff)
    n3  = r_loop.add_node("n3")         # ending point of loop
    r_loop.add_comp(n2, n3, 2.71*kohm)  # loop branch 1
    n2a  = r_loop.add_node("n2a")
    r_loop.add_comp(n2, n2a, 3.14*kohm) # loop branch 2
    r_loop.add_comp(n2a, n3, 1.*kohm)   # loop branch 2
    r_loop.add_comp(n3, gnd, 10.*ff)

    # construct filtered graph with capacitors removed
    fg = GraphView(r_loop, efilt=isResistor(r_loop))

    # run DFS with special visitor to report loops
    dfs_search(r_loop, n1, visitor(r_loop))