'Run \'python -c SOURCE\' under gdb with a breakpoint.
Support injecting commands after the breakpoint is reached
Returns the stdout from gdb
cmds_after_breakpoint: if provided, a list of strings: gdb commands'

def get_stack_trace(self, source=None, script=None, breakpoint='PyObject_Print', cmds_after_breakpoint=None, import_site=False):

    commands = ['set    breakpoint    pending    yes', ('break    %s' % breakpoint), 'run']
    if cmds_after_breakpoint:
        commands += cmds_after_breakpoint
    else:
        commands += ['backtrace']
    args = ['gdb', '--batch']
    args += [('--eval-command=%s' % cmd) for cmd in commands]
    args += ['--args', sys.executable]
    if (not import_site):
        args += ['-S']
    if source:
        args += ['-c', source]
    elif script:
        args += [script]
    (out, err) = self.run_gdb(*args)
    err = err.replace(('Function    "%s"    not    defined.\n' % breakpoint), '')
    err = err.replace("warning:    Unable    to    find    libthread_db    matching    inferior's    thread    library,    thread    debugging    will    not    be    available.\n", '')
    err = err.replace('warning:    Cannot    initialize    thread    debugging    library:    Debugger    service    failed\n', '')
    self.assertEqual(err, '')
    return out
