Ejemplo n.º 1
0
    def to_summary_string(self, verbose=False):
        """Pretty printer for the tcache_perthread_struct supporting different level of verbosity
        with a simplified output. We don't show the tcache_perthread_struct.count values
        but instead print them in front of their associated tcache_perthread_struct.entries[]

        :param verbose: False for non-verbose. True for more verbose
        """

        title = "struct tcache_perthread_struct @ 0x%x {" % self.address
        txt = pu.color_title(title)
        #txt += "\n{:11} = {}".format("counts[]", "{...}")
        for i in range(len(self.entries)):
            if verbose or self.entries[i] != 0:
                curr_size = self.ptm.tcache_bin_size(i)
                txt += "\n{:11} = ".format("entries[%d]" % i)
                txt += pu.color_value("{:#x}".format(self.entries[i]))
                txt += " (sz {:#x})".format(curr_size)
                msg = "entry"
                if self.counts[i] > 1:
                    msg = "entries"
                if self.counts[i] == 0:
                    txt += " [EMPTY]"
                else:
                    txt += " [{:#d} {}]".format(self.counts[i], msg)
        return txt
Ejemplo n.º 2
0
    def __str__(self):
        """Pretty printer for the malloc_par
        """

        title = "struct malloc_par @ 0x%x {" % self.address
        txt = pu.color_title(title)
        txt += "\n{:16} = ".format("trim_threshold")
        txt += pu.color_value("{:#x}".format(self.trim_threshold))
        txt += "\n{:16} = ".format("top_pad")
        txt += pu.color_value("{:#x}".format(self.top_pad))
        txt += "\n{:16} = ".format("mmap_threshold")
        txt += pu.color_value("{:#x}".format(self.mmap_threshold))
        txt += "\n{:16} = ".format("arena_test")
        txt += pu.color_value("{:#x}".format(self.arena_test))
        txt += "\n{:16} = ".format("arena_max")
        txt += pu.color_value("{:#x}".format(self.arena_max))
        if self.ptm.distribution == "photon" and self.ptm.release == "3.0":
            txt += "\n{:16} = ".format("arena_stickiness")
            txt += pu.color_value("{:#x}".format(self.arena_stickiness))
        txt += "\n{:16} = ".format("n_mmaps")
        txt += pu.color_value("{:#x}".format(self.n_mmaps))
        txt += "\n{:16} = ".format("n_mmaps_max")
        txt += pu.color_value("{:#x}".format(self.n_mmaps_max))
        txt += "\n{:16} = ".format("max_n_mmaps")
        txt += pu.color_value("{:#x}".format(self.max_n_mmaps))
        txt += "\n{:16} = ".format("no_dyn_threshold")
        txt += pu.color_value("{:#x}".format(self.no_dyn_threshold))
        txt += "\n{:16} = ".format("mmapped_mem")
        txt += pu.color_value("{:#x}".format(self.mmapped_mem))
        txt += "\n{:16} = ".format("max_mmapped_mem")
        txt += pu.color_value("{:#x}".format(self.max_mmapped_mem))
        if self.version <= 2.23:
            txt += "\n{:16} = ".format("max_total_mem")
            txt += pu.color_value("{:#x}".format(self.max_total_mem))
        txt += "\n{:16} = ".format("sbrk_base")
        txt += pu.color_value("{:#x}".format(self.sbrk_base))
        if self.ptm.is_tcache_enabled():
            txt += "\n{:16} = ".format("tcache_bins")
            txt += pu.color_value("{:#x}".format(self.tcache_bins))
            txt += "\n{:16} = ".format("tcache_max_bytes")
            txt += pu.color_value("{:#x}".format(self.tcache_max_bytes))
            txt += "\n{:16} = ".format("tcache_count")
            txt += pu.color_value("{:#x}".format(self.tcache_count))
            txt += "\n{:16} = ".format("tcache_unsorted_limit")
            txt += pu.color_value("{:#x}".format(self.tcache_unsorted_limit))
        return txt
Ejemplo n.º 3
0
    def to_string(self, verbose=0, use_cache=False):
        """Pretty printer for the malloc_state supporting different level of verbosity

        :param verbose: 0 for non-verbose. 1 for more verbose. 2 for even more verbose.
        :param use_cache: True if we want to use the cached information from the cache object.
                          False if we want to fetch the data again
        """

        title = "struct malloc_state @ 0x%x {" % self.address
        txt = pu.color_title(title)
        txt += "\n{:16} = ".format("mutex")
        txt += pu.color_value("{:#x}".format(self.mutex))
        txt += "\n{:16} = ".format("flags")
        txt += pu.color_value("{:#x}".format(self.flags))
        if self.version >= 2.27:
            txt += "\n{:16} = ".format("have_fastchunks")
            txt += pu.color_value("{:#x}".format(self.have_fastchunks))
        txt += self.fastbins_to_string(verbose=verbose, use_cache=use_cache)
        txt += "\n{:16} = ".format("top")
        txt += pu.color_value("{:#x}".format(self.top))
        txt += "\n{:16} = ".format("last_remainder")
        txt += pu.color_value("{:#x}".format(self.last_remainder))
        txt += self.bins_to_string(verbose=verbose, use_cache=use_cache)
        if verbose > 0:
            for i in range(len(self.binmap)):
                txt += "\n{:16} = ".format("binmap[%d]" % i)
                txt += pu.color_value("{:#x}".format(self.binmap[i]))
        else:
            txt += "\n{:16} = ".format("binmap")
            txt += pu.color_value("{}".format("{...}"))
        txt += "\n{:16} = ".format("next")
        txt += pu.color_value("{:#x}".format(self.next))
        txt += "\n{:16} = ".format("next_free")
        txt += pu.color_value("{:#x}".format(self.next_free))
        if self.version >= 2.23:
            txt += "\n{:16} = ".format("attached_threads")
            txt += pu.color_value("{:#x}".format(self.attached_threads))
        txt += "\n{:16} = ".format("system_mem")
        txt += pu.color_value("{:#x}".format(self.system_mem))
        txt += "\n{:16} = ".format("max_system_mem")
        txt += pu.color_value("{:#x}".format(self.max_system_mem))
        return txt
Ejemplo n.º 4
0
    def to_string(self, verbose=False):
        """Pretty printer for the tcache_perthread_struct supporting different level of verbosity

        :param verbose: False for non-verbose. True for more verbose
        """

        title = "struct tcache_perthread_struct @ 0x%x {" % self.address
        txt = pu.color_title(title)
        for i in range(len(self.counts)):
            if verbose or self.counts[i] > 0:
                curr_size = self.ptm.tcache_bin_size(i)
                txt += "\n{:11} = ".format("counts[%d]" % i)
                txt += pu.color_value("{:#d}".format(self.counts[i]))
                txt += " (sz {:#x})".format(curr_size)
        for i in range(len(self.entries)):
            if verbose or self.entries[i] != 0:
                curr_size = self.ptm.tcache_bin_size(i)
                txt += "\n{:11} = ".format("entries[%d]" % i)
                txt += pu.color_value("{:#x}".format(self.entries[i]))
                txt += " (sz {:#x})".format(curr_size)
        return txt
Ejemplo n.º 5
0
    def __str__(self):
        """Pretty printer for the malloc_chunk
        """

        if self.prev_size == 0 and self.size == 0:
            return ""
        # XXX - since they all share the same prev_size/size and 2 chunk types
        # also share the fd/bk, we could refactor code here?
        elif self.type == pt.chunk_type.INUSE:

            title = "struct malloc_chunk @ 0x%x {" % self.address
            ret = pu.color_title(title)
            ret += "\n{:11} = ".format("prev_size")
            ret += pu.color_value("{:#x}".format(self.prev_size))
            ret += "\n{:11} = ".format("size")
            ret += pu.color_value("{:#x}".format(self.size & ~self.ptm.SIZE_BITS))

            if (
                self.ptm.prev_inuse(self)
                or self.ptm.chunk_is_mmapped(self)
                or self.ptm.chunk_non_main_arena(self)
            ):
                ret += " ("
                if self.ptm.prev_inuse(self):
                    ret += "PREV_INUSE|"
                if self.ptm.chunk_is_mmapped(self):
                    ret += "MMAPPED|"
                if self.ptm.chunk_non_main_arena(self):
                    ret += "NON_MAIN_ARENA|"
                ret += "\b)"
            return ret
        elif self.type == pt.chunk_type.FREE_TCACHE:
            title = "struct malloc_chunk @ 0x%x {" % self.address
            ret = pu.color_title(title)
            ret += "\n{:11} = ".format("prev_size")
            ret += pu.color_value("{:#x}".format(self.prev_size))
            ret += "\n{:11} = ".format("size")
            ret += pu.color_value("{:#x}".format(self.size & ~self.ptm.SIZE_BITS))
            flag_str = ""
            if self.ptm.prev_inuse(self):
                flag_str += "PREV_INUSE|"
            if self.ptm.chunk_is_mmapped(self):
                flag_str += "MMAPPED|"
            if self.ptm.chunk_non_main_arena(self):
                flag_str += "NON_MAIN_ARENA|"
            if len(flag_str) != 0:
                ret += " ("
                ret += flag_str
                ret += "\b)"
            title = "\nstruct tcache_entry @ 0x%x {" % (self.address + self.ptm.INUSE_HDR_SZ)
            ret += pu.color_title(title)
            ret += "\n{:11} = ".format("next")
            ret += pu.color_value("{:#x}".format(self.next))
            ret += "\n{:11} = ".format("key")
            ret += pu.color_value("{:#x}".format(self.key))
            return ret
        elif self.type == pt.chunk_type.FREE_FAST:
            title = "struct malloc_chunk @ 0x%x {" % self.address
            ret = pu.color_title(title)
            ret += "\n{:11} = ".format("prev_size")
            ret += pu.color_value("{:#x}".format(self.prev_size))
            ret += "\n{:11} = ".format("size")
            ret += pu.color_value("{:#x}".format(self.size & ~self.ptm.SIZE_BITS))
            flag_str = ""
            if self.ptm.prev_inuse(self):
                flag_str += "PREV_INUSE|"
            if self.ptm.chunk_is_mmapped(self):
                flag_str += "MMAPPED|"
            if self.ptm.chunk_non_main_arena(self):
                flag_str += "NON_MAIN_ARENA|"
            if len(flag_str) != 0:
                ret += " ("
                ret += flag_str
                ret += "\b)"
            ret += "\n{:11} = ".format("fd")
            ret += pu.color_value("{:#x}".format(self.fd))
            return ret
        elif self.type == pt.chunk_type.FREE_SMALL:
            ret = "struct malloc_chunk @ "
            ret += "{:#x} ".format(self.address)
            ret += "{"
            ret += "\n{:11} = ".format("prev_size")
            ret += "{:#x}".format(self.prev_size)
            ret += "\n{:11} = ".format("size")
            ret += "{:#x}".format(self.size & ~self.ptm.SIZE_BITS)
            ret += " ("
            if self.ptm.prev_inuse(self):
                ret += "PREV_INUSE|"
            if self.ptm.chunk_is_mmapped(self):
                ret += "MMAPPED|"
            if self.ptm.chunk_non_main_arena(self):
                ret += "NON_MAIN_ARENA|"
            ret += "\b)"
            ret += "\n{:11} = ".format("fd")
            ret += pu.color_value("{:#x}".format(self.fd))
            ret += "\n{:11} = ".format("bk")
            ret += pu.color_value("{:#x}".format(self.bk))
            return ret
        elif self.type == pt.chunk_type.FREE_LARGE:
            title = "struct malloc_chunk @ 0x%x {" % self.address
            ret = pu.color_title(title)
            ret += "\n{:11} = ".format("prev_size")
            ret += pu.color_value("{:#x}".format(self.prev_size))
            ret += "\n{:11} = ".format("size")
            ret += pu.color_value("{:#x}".format(self.size & ~self.ptm.SIZE_BITS))
            ret += " ("
            if self.ptm.prev_inuse(self):
                ret += "PREV_INUSE|"
            if self.ptm.chunk_is_mmapped(self):
                ret += "MMAPPED|"
            if self.ptm.chunk_non_main_arena(self):
                ret += "NON_MAIN_ARENA|"
            ret += "\b)"
            ret += "\n{:11} = ".format("fd")
            ret += pu.color_value("{:#x}".format(self.fd))
            ret += "\n{:11} = ".format("bk")
            ret += pu.color_value("{:#x}".format(self.bk))
            ret += "\n{:11} = ".format("fd_nextsize")
            ret += pu.color_value("{:#x}".format(self.fd_nextsize))
            ret += "\n{:11} = ".format("bk_nextsize")
            ret += pu.color_value("{:#x}".format(self.bk_nextsize))
            return ret
        else:
            pu.print_error("Error: unknown hdr_size. Should not happen")
            return ""