'Only used for debugging purposes.
Return the current stack info in formatted string. If depth is None, the
current stack frame (from sp to bp) will be printed out.'

def dbg_print_stack(self, depth=None, sp=None):

    var_size = (self.arch.bits / 8)
    sp_sim = self.regs._sp
    bp_sim = self.regs._bp
    if (self.se.symbolic(sp_sim) and (sp is None)):
        result = 'SP    is    SYMBOLIC'
    elif (self.se.symbolic(bp_sim) and (depth is None)):
        result = 'BP    is    SYMBOLIC'
    else:
        sp_value = (sp if (sp is not None) else self.se.any_int(sp_sim))
        if self.se.symbolic(bp_sim):
            result = ('SP    =    0x%08x,    BP    is    symbolic\n' % sp_value)
            bp_value = None
        else:
            bp_value = self.se.any_int(bp_sim)
            result = ('SP    =    0x%08x,    BP    =    0x%08x\n' % (sp_value, bp_value))
        if (depth is None):
            depth = (((bp_value - sp_value) / var_size) + 1)
        pointer_value = sp_value
        for i in xrange(depth):
            stack_values = []
            if (o.ABSTRACT_MEMORY in self.options):
                sp = self.regs._sp
                segment_sizes = self.memory.get_segments((sp + (i * var_size)), var_size)
                pos = (i * var_size)
                for segment_size in segment_sizes:
                    stack_values.append(self.stack_read(pos, segment_size, bp=False))
                    pos += segment_size
            else:
                stack_values.append(self.stack_read((i * var_size), var_size, bp=False))
            val = self._stack_values_to_string(stack_values)
            if (pointer_value == sp_value):
                line = ('(sp)%    16x    |    %s' % (pointer_value, val))
            elif (pointer_value == bp_value):
                line = ('(bp)%    16x    |    %s' % (pointer_value, val))
            else:
                line = ('%    20x    |    %s' % (pointer_value, val))
            pointer_value += var_size
            result += (line + '\n')
    return result
