[debuginfo-tests] r190185 - Add an lldb wrapper script that implements gdb-compatible commands on top

Eric Christopher echristo at gmail.com
Wed Sep 18 15:39:14 PDT 2013


Looks like this broke the gdb version of these tests where the checks
aren't strict enough and are doing multiple matches.

-eric

sources/llvm/tools/clang/test/debuginfo-tests/sret.cpp:10:16: error:
CHECK-NEXT: is on the same line as previous match
// CHECK-NEXT: {{(_vptr\$A =)|(m_int = 12)}}
               ^
builds/build-llvm/tools/clang/test/debuginfo-tests/Output/sret.cpp.gdb.output:5:7:
note: 'next' match was here
$1 = {_vptr$A = 0x400b10 <vtable for A+16>, m_int = 12}
      ^
builds/build-llvm/tools/clang/test/debuginfo-tests/Output/sret.cpp.gdb.output:5:7:
note: previous match ended here
$1 = {_vptr$A = 0x400b10 <vtable for A+16>, m_int = 12}
      ^

and:

/sources/llvm/tools/clang/test/debuginfo-tests/aggregate-indirect-arg.cpp:9:16:
error: CHECK-NEXT: is on the same line as previous match
// CHECK-NEXT: Data = 0x0{{,|(0+$)}}
               ^
builds/build-llvm/tools/clang/test/debuginfo-tests/Output/aggregate-indirect-arg.cpp.gdb.output:5:7:
note: 'next' match was here
$1 = {Data = 0x0, Kind = 2142}
      ^
builds/build-llvm/tools/clang/test/debuginfo-tests/Output/aggregate-indirect-arg.cpp.gdb.output:5:7:
note: previous match ended here
$1 = {Data = 0x0, Kind = 2142}
      ^


On Fri, Sep 6, 2013 at 11:10 AM, Adrian Prantl <aprantl at apple.com> wrote:
> Author: adrian
> Date: Fri Sep  6 13:10:44 2013
> New Revision: 190185
>
> URL: http://llvm.org/viewvc/llvm-project?rev=190185&view=rev
> Log:
> Add an lldb wrapper script that implements gdb-compatible commands on top
> of lldb. This will be the new default method for executing the tests in
> this repository on Darwin.
> There is also a related patch for llvm/utils/test_debuginfo.pl coming.
>
> I also relaxed some of the checks to work with both gdb's and lldb's
> output.
>
> Added:
>     debuginfo-tests/trunk/llgdb.py
> Modified:
>     debuginfo-tests/trunk/aggregate-indirect-arg.cpp
>     debuginfo-tests/trunk/nested-struct.cpp
>     debuginfo-tests/trunk/sret.cpp
>
> Modified: debuginfo-tests/trunk/aggregate-indirect-arg.cpp
> URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/aggregate-indirect-arg.cpp?rev=190185&r1=190184&r2=190185&view=diff
> ==============================================================================
> --- debuginfo-tests/trunk/aggregate-indirect-arg.cpp (original)
> +++ debuginfo-tests/trunk/aggregate-indirect-arg.cpp Fri Sep  6 13:10:44 2013
> @@ -5,9 +5,9 @@
>  // DEBUGGER: break 22
>  // DEBUGGER: r
>  // DEBUGGER: p v
> -// CHECK: $1 = {
> -// CHECK:  Data = 0x0,
> -// CHECK:  Kind = 2142
> +// CHECK: ${{[0-9]+}} = {
> +// CHECK-NEXT:  Data = 0x0{{,|(0+$)}}
> +// CHECK-NEXT:  Kind = 2142
>
>  class SVal {
>  public:
>
> Added: debuginfo-tests/trunk/llgdb.py
> URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/llgdb.py?rev=190185&view=auto
> ==============================================================================
> --- debuginfo-tests/trunk/llgdb.py (added)
> +++ debuginfo-tests/trunk/llgdb.py Fri Sep  6 13:10:44 2013
> @@ -0,0 +1,137 @@
> +#!/bin/env python
> +"""
> +A gdb-compatible frontend for lldb that implements just enough
> +commands to run the tests in the debuginfo-tests repository with lldb.
> +"""
> +
> +# ----------------------------------------------------------------------
> +# Auto-detect lldb python module.
> +import commands, platform, os,  sys
> +try:
> +    # Just try for LLDB in case PYTHONPATH is already correctly setup.
> +    import lldb
> +except ImportError:
> +    lldb_python_dirs = list()
> +    # lldb is not in the PYTHONPATH, try some defaults for the current platform.
> +    platform_system = platform.system()
> +    if platform_system == 'Darwin':
> +        # On Darwin, try the currently selected Xcode directory
> +        xcode_dir = commands.getoutput("xcode-select --print-path")
> +        if xcode_dir:
> +            lldb_python_dirs.append(os.path.realpath(xcode_dir +
> +'/../SharedFrameworks/LLDB.framework/Resources/Python'))
> +            lldb_python_dirs.append(xcode_dir +
> +'/Library/PrivateFrameworks/LLDB.framework/Resources/Python')
> +        lldb_python_dirs.append(
> +'/System/Library/PrivateFrameworks/LLDB.framework/Resources/Python')
> +    success = False
> +    for lldb_python_dir in lldb_python_dirs:
> +        if os.path.exists(lldb_python_dir):
> +            if not (sys.path.__contains__(lldb_python_dir)):
> +                sys.path.append(lldb_python_dir)
> +                try:
> +                    import lldb
> +                except ImportError:
> +                    pass
> +                else:
> +                    print 'imported lldb from: "%s"' % (lldb_python_dir)
> +                    success = True
> +                    break
> +    if not success:
> +        print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
> +        sys.exit(1)
> +# ----------------------------------------------------------------------
> +
> +# Command line option handling.
> +import argparse
> +parser = argparse.ArgumentParser(description=__doc__)
> +parser.add_argument('--quiet', '-q', action="store_true", help='ignored')
> +parser.add_argument('-batch', action="store_true",
> +                    help='exit after processing comand line')
> +parser.add_argument('-n', action="store_true", help='ignore .lldb file')
> +parser.add_argument('-x', dest='script', type=file, help='execute commands from file')
> +parser.add_argument("target", help="the program to debug")
> +args = parser.parse_args()
> +
> +
> +# Create a new debugger instance.
> +debugger = lldb.SBDebugger.Create()
> +debugger.SkipLLDBInitFiles(args.n)
> +
> +# Don't return from lldb function calls until the process stops.
> +debugger.SetAsync(False)
> +
> +# Create a target from a file and arch.
> +target = debugger.CreateTargetWithFileAndArch(args.target, lldb.LLDB_ARCH_DEFAULT)
> +
> +if not target:
> +    print "Could not create target", args.target
> +    sys.exit(1)
> +
> +if not args.script:
> +    print "Interactive mode is not implemented."
> +    sys.exit(1)
> +
> +import re
> +for command in args.script:
> +    # Strip newline and whitespaces and split into words.
> +    cmd = command[:-1].strip().split()
> +    if not cmd:
> +        continue
> +
> +    print '> %s'% command
> +
> +    try:
> +        if re.match('^r|(run)$', cmd[0]):
> +            error = lldb.SBError()
> +            launchinfo = lldb.SBLaunchInfo([])
> +            launchinfo.SetWorkingDirectory(os.getcwd())
> +            process = target.Launch(launchinfo, error)
> +            if not process or error.fail:
> +                print error
> +                state = process.GetState()
> +                print "State = %d" % state
> +                print "Could not launch process."
> +                sys.exit(1)
> +
> +        elif re.match('^b|(break)$', cmd[0]) and len(cmd) == 2:
> +            if re.match('[0-9]+', cmd[1]):
> +                # b line
> +                mainfile = target.FindFunctions('main')[0].compile_unit.file
> +                print target.BreakpointCreateByLocation(mainfile, int(cmd[1]))
> +            else:
> +                # b file:line
> +                file, line = cmd.split(':')
> +                print target.BreakpointCreateByLocation(file, int(line))
> +
> +        elif re.match('^ptype$', cmd[0]) and len(cmd) == 2:
> +            # GDB's ptype has multiple incarnations depending on its
> +            # argument (global variable, function, type).  The definition
> +            # here is for looking up the signature of a function and only
> +            # if that fails it looks for a type with that name.
> +            # Type lookup in LLDB would be "image lookup --type".
> +            for elem in target.FindFunctions(cmd[1]):
> +                print elem.function.type
> +                continue
> +            print target.FindFirstType(cmd[1])
> +
> +        elif re.match('^po$', cmd[0]) and len(cmd) > 1:
> +            opts = lldb.SBExpressionOptions()
> +            opts.SetFetchDynamicValue(True)
> +            opts.SetCoerceResultToId(True)
> +            print target.EvaluateExpression(' '.join(cmd[1:]), opts)
> +
> +        elif re.match('^p|(print)$', cmd[0]) and len(cmd) > 1:
> +            opts = lldb.SBExpressionOptions()
> +            print target.EvaluateExpression(' '.join(cmd[1:]), opts)
> +
> +        elif re.match('^q|(quit)$', cmd[0]):
> +            sys.exit(0)
> +
> +        else:
> +            print debugger.HandleCommand(' '.join(cmd))
> +
> +    except SystemExit, e: raise e
> +    except:
> +        print 'Could not handle the command "%s"' % ' '.join(cmd)
> +
>
> Modified: debuginfo-tests/trunk/nested-struct.cpp
> URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/nested-struct.cpp?rev=190185&r1=190184&r2=190185&view=diff
> ==============================================================================
> --- debuginfo-tests/trunk/nested-struct.cpp (original)
> +++ debuginfo-tests/trunk/nested-struct.cpp Fri Sep  6 13:10:44 2013
> @@ -6,7 +6,7 @@
>  // gdb crashes in such cases.
>
>  // DEBUGGER: ptype foo
> -// CHECK: type = int (void)
> +// CHECK: int (void)
>
>  int foo() {
>    struct Local {
>
> Modified: debuginfo-tests/trunk/sret.cpp
> URL: http://llvm.org/viewvc/llvm-project/debuginfo-tests/trunk/sret.cpp?rev=190185&r1=190184&r2=190185&view=diff
> ==============================================================================
> --- debuginfo-tests/trunk/sret.cpp (original)
> +++ debuginfo-tests/trunk/sret.cpp Fri Sep  6 13:10:44 2013
> @@ -5,9 +5,10 @@
>  // DEBUGGER: break 62
>  // DEBUGGER: r
>  // DEBUGGER: p a
> -// CHECK: $1 = {
> -// CHECK:  _vptr$A =
> -// CHECK:  m_int = 12
> +// CHECK: ${{[0-9]+}} = {
> +// LLDB does not print artificial members.
> +// CHECK-NEXT:  {{(_vptr\$A =)|(m_int = 12)}}
> +// CHECK-NEXT:  {{(m_int = 12)|(})}}
>
>  class A
>  {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list