'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=BREAKPOINT_FN, 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', '-nx']
    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) = run_gdb(PYTHONHASHSEED=PYTHONHASHSEED, *args)
    errlines = err.splitlines()
    unexpected_errlines = []
    ignore_patterns = (('Function    "%s"    not    defined.' % breakpoint), 'warning:    no    loadable    sections    found    in    added    symbol-file    system-supplied    DSO', "warning:    Unable    to    find    libthread_db    matching    inferior's    thread    library,    thread    debugging    will    not    be    available.", 'warning:    Cannot    initialize    thread    debugging    library:    Debugger    service    failed', 'warning:    Could    not    load    shared    library    symbols    for    linux-vdso.so', 'warning:    Could    not    load    shared    library    symbols    for    linux-gate.so', 'Do    you    need    "set    solib-search-path"    or    "set    sysroot"?', 'warning:    Source    file    is    more    recent    than    executable.', 'Missing    separate    debuginfo    for    ', 'Try:    zypper    install    -C    ')
    for line in errlines:
        if (not line.startswith(ignore_patterns)):
            unexpected_errlines.append(line)
    self.assertEqual(unexpected_errlines, [])
    return out
