Initial import of lldb

Change-Id: Ib244e837bee349effa12b2ff6ffffbe3d730e929
This commit is contained in:
2014-09-29 14:52:42 +02:00
committed by Lionel Sambuc
parent 35b65c5af1
commit 41f05bd8d7
3541 changed files with 875157 additions and 0 deletions

View File

@@ -0,0 +1 @@
cmdline

View File

@@ -0,0 +1,5 @@
LEVEL = ../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,146 @@
"""
Test lldb Python commands.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class CmdPythonTestCase(TestBase):
mydir = os.path.join("functionalities", "command_script")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym (self):
self.buildDsym ()
self.pycmd_tests ()
@dwarf_test
def test_with_dwarf (self):
self.buildDwarf ()
self.pycmd_tests ()
def pycmd_tests (self):
exe = os.path.join (os.getcwd(), "a.out")
self.expect("file " + exe,
patterns = [ "Current executable set to .*a.out" ])
self.runCmd("command source py_import")
# This is the function to remove the custom commands in order to have a
# clean slate for the next test case.
def cleanup():
self.runCmd('command script delete welcome', check=False)
self.runCmd('command script delete targetname', check=False)
self.runCmd('command script delete longwait', check=False)
self.runCmd('command script delete mysto', check=False)
self.runCmd('command script delete tell_sync', check=False)
self.runCmd('command script delete tell_async', check=False)
self.runCmd('command script delete tell_curr', check=False)
self.runCmd('command script delete bug11569', check=False)
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)
# Interact with debugger in synchronous mode
self.setAsync(False)
# We don't want to display the stdout if not in TraceOn() mode.
if not self.TraceOn():
self.HideStdout()
self.expect('welcome Enrico',
substrs = ['Hello Enrico, welcome to LLDB']);
self.expect("help welcome",
substrs = ['Just a docstring for welcome_impl',
'A command that says hello to LLDB users'])
self.expect("help",
substrs = ['Run Python function welcome.welcome_impl',
'welcome'])
self.expect("help -a",
substrs = ['Run Python function welcome.welcome_impl',
'welcome'])
self.expect("help -u", matching=False,
substrs = ['Run Python function welcome.welcome_impl',
'welcome'])
self.runCmd("command script delete welcome");
self.expect('welcome Enrico', matching=False, error=True,
substrs = ['Hello Enrico, welcome to LLDB']);
self.expect('targetname',
substrs = ['a.out'])
self.expect('targetname fail', error=True,
substrs = ['a test for error in command'])
self.expect('command script list',
substrs = ['targetname',
'Run Python function welcome.target_name_impl'])
self.expect("help targetname",
substrs = ['Run Python function welcome.target_name_imp',
'This command takes','\'raw\' input',
'quote stuff'])
self.expect("longwait",
substrs = ['Done; if you saw the delays I am doing OK'])
self.runCmd("b main")
self.runCmd("run")
self.runCmd("mysto 3")
self.expect("frame variable array",
substrs = ['[0] = 79630','[1] = 388785018','[2] = 0'])
self.runCmd("mysto 3")
self.expect("frame variable array",
substrs = ['[0] = 79630','[4] = 388785018','[5] = 0'])
# we cannot use the stepover command to check for async execution mode since LLDB
# seems to get confused when events start to queue up
self.expect("tell_sync",
substrs = ['running sync'])
self.expect("tell_async",
substrs = ['running async'])
self.expect("tell_curr",
substrs = ['I am running sync'])
# Test that a python command can redefine itself
self.expect('command script add -f foobar welcome')
self.runCmd("command script clear")
# Test that re-defining an existing command works
self.runCmd('command script add my_command --function welcome.welcome_impl')
self.expect('my_command Blah', substrs = ['Hello Blah, welcome to LLDB'])
self.runCmd('command script add my_command --function welcome.target_name_impl')
self.expect('my_command', substrs = ['a.out'])
self.runCmd("command script clear")
self.expect('command script list', matching=False,
substrs = ['targetname',
'longwait'])
self.expect('command script add -f foobar frame', error=True,
substrs = ['cannot add command'])
# http://llvm.org/bugs/show_bug.cgi?id=11569
# LLDBSwigPythonCallCommand crashes when a command script returns an object
self.runCmd('command script add -f bug11569 bug11569')
# This should not crash.
self.runCmd('bug11569', check=False)
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()

View File

@@ -0,0 +1,7 @@
def bug11569(debugger, args, result, dict):
"""
http://llvm.org/bugs/show_bug.cgi?id=11569
LLDBSwigPythonCallCommand crashes when a command script returns an object.
"""
return ["return", "a", "non-string", "should", "not", "crash", "LLDB"];

View File

@@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
EXE := hello_world
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,76 @@
"""Test custom import command to import files by path."""
import os, sys, time
import unittest2
import lldb
from lldbtest import *
class ImportTestCase(TestBase):
mydir = os.path.join("functionalities", "command_script", "import")
@python_api_test
def test_import_command(self):
"""Import some Python scripts by path and test them"""
self.run_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def run_test(self):
"""Import some Python scripts by path and test them."""
# This is the function to remove the custom commands in order to have a
# clean slate for the next test case.
def cleanup():
self.runCmd('command script delete foo2cmd', check=False)
self.runCmd('command script delete foocmd', check=False)
self.runCmd('command script delete foobarcmd', check=False)
self.runCmd('command script delete barcmd', check=False)
self.runCmd('command script delete barothercmd', check=False)
self.runCmd('command script delete TPcommandA', check=False)
self.runCmd('command script delete TPcommandB', check=False)
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)
self.runCmd("command script import ./foo/foo.py --allow-reload")
self.runCmd("command script import ./foo/foo2.py --allow-reload")
self.runCmd("command script import ./foo/bar/foobar.py --allow-reload")
self.runCmd("command script import ./bar/bar.py --allow-reload")
self.expect("command script import ./nosuchfile.py",
error=True, startstr='error: module importing failed')
self.expect("command script import ./nosuchfolder/",
error=True, startstr='error: module importing failed')
self.expect("command script import ./foo/foo.py", error=False)
self.runCmd("command script import --allow-reload ./thepackage")
self.expect("TPcommandA",substrs=["hello world A"])
self.expect("TPcommandB",substrs=["hello world B"])
self.runCmd("script import dummymodule")
self.expect("command script import ./dummymodule.py", error=False)
self.expect("command script import --allow-reload ./dummymodule.py", error=False)
self.runCmd("command script add -f foo.foo_function foocmd")
self.runCmd("command script add -f foobar.foo_function foobarcmd")
self.runCmd("command script add -f bar.bar_function barcmd")
self.expect("foocmd hello",
substrs = ['foo says', 'hello'])
self.expect("foo2cmd hello",
substrs = ['foo2 says', 'hello'])
self.expect("barcmd hello",
substrs = ['barutil says', 'bar told me', 'hello'])
self.expect("barothercmd hello",
substrs = ['barutil says', 'bar told me', 'hello'])
self.expect("foobarcmd hello",
substrs = ['foobar says', 'hello'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()

View File

@@ -0,0 +1,10 @@
def bar_function(debugger, args, result, dict):
global UtilityModule
print >>result, (UtilityModule.barutil_function("bar told me " + args))
return None
def __lldb_init_module(debugger, session_dict):
global UtilityModule
UtilityModule = __import__("barutil")
debugger.HandleCommand("command script add -f bar.bar_function barothercmd")
return None

View File

@@ -0,0 +1,2 @@
def barutil_function(x):
return "barutil says: " + x

View File

@@ -0,0 +1,2 @@
def no_useful_code(foo):
return foo

View File

@@ -0,0 +1,3 @@
def foo_function(debugger, args, result, dict):
print >>result, ("foobar says " + args)
return None

View File

@@ -0,0 +1,3 @@
def foo_function(debugger, args, result, dict):
print >>result, ("foo says " + args)
return None

View File

@@ -0,0 +1,7 @@
def foo2_function(debugger, args, result, dict):
print >>result, ("foo2 says " + args)
return None
def __lldb_init_module(debugger, session_dict):
debugger.HandleCommand("command script add -f foo2.foo2_function foo2cmd")
return None

View File

@@ -0,0 +1,15 @@
#include <stdio.h>
int main(int argc, char const *argv[]) {
printf("Hello world.\n"); // Set break point at this line.
if (argc == 1)
return 0;
// Waiting to be attached by the debugger, otherwise.
char line[100];
while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached...
printf("input line=>%s\n", line);
}
printf("Exiting now\n");
}

View File

@@ -0,0 +1,3 @@
LEVEL = ../../../../make
include $(LEVEL)/Makefile.rules

View File

@@ -0,0 +1,33 @@
"""Check that we handle an ImportError in a special way when command script importing files."""
import os, sys, time
import unittest2
import lldb
from lldbtest import *
class Rdar12586188TestCase(TestBase):
mydir = os.path.join("functionalities", "command_script", "import", "rdar-12586188")
@python_api_test
def test_rdar12586188_command(self):
"""Check that we handle an ImportError in a special way when command script importing files."""
self.run_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def run_test(self):
"""Check that we handle an ImportError in a special way when command script importing files."""
self.expect("command script import ./fail12586188.py --allow-reload",
error=True, substrs = ['error: module importing failed: I do not want to be imported'])
self.expect("command script import ./fail212586188.py --allow-reload",
error=True, substrs = ['error: module importing failed: Python error raised while importing module: I do not want to be imported'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()

View File

@@ -0,0 +1,4 @@
def f(x):
return x + 1
raise ImportError("I do not want to be imported")

View File

@@ -0,0 +1,4 @@
def f(x):
return x + 1
raise ValueError("I do not want to be imported")

View File

@@ -0,0 +1,3 @@
def command(debugger, command, result, internal_dict):
result.PutCString(u"hello world A")
return None

View File

@@ -0,0 +1,3 @@
def command(debugger, command, result, internal_dict):
result.PutCString(u"hello world B")
return None

View File

@@ -0,0 +1,6 @@
import TPunitA
import TPunitB
def __lldb_init_module(debugger,*args):
debugger.HandleCommand("command script add -f thepackage.TPunitA.command TPcommandA")
debugger.HandleCommand("command script add -f thepackage.TPunitB.command TPcommandB")

View File

@@ -0,0 +1,70 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <iostream>
int
product (int x, int y)
{
int result = x * y;
return result;
}
int
sum (int a, int b)
{
int result = a + b;
return result;
}
int
strange_max (int m, int n)
{
if (m > n)
return m;
else if (n > m)
return n;
else
return 0;
}
int
foo (int i, int j)
{
if (strange_max (i, j) == i)
return product (i, j);
else if (strange_max (i, j) == j)
return sum (i, j);
else
return product (sum (i, i), sum (j, j));
}
int
main(int argc, char const *argv[])
{
int array[9];
memset(array,0,9*sizeof(int));
array[0] = foo (1238, 78392);
array[1] = foo (379265, 23674);
array[2] = foo (872934, 234);
array[3] = foo (1238, 78392);
array[4] = foo (379265, 23674);
array[5] = foo (872934, 234);
array[6] = foo (1238, 78392);
array[7] = foo (379265, 23674);
array[8] = foo (872934, 234);
return 0;
}

View File

@@ -0,0 +1,21 @@
import lldb
import sys
import os
import time
def StepOver(debugger, args, result, dict):
"""
Step over a given number of times instead of only just once
"""
arg_split = args.split(" ")
print type(arg_split)
count = int(arg_split[0])
for i in range(0,count):
debugger.GetSelectedTarget().GetProcess().GetSelectedThread().StepOver(lldb.eOnlyThisThread)
print "step<%d>"%i
def __lldb_init_module(debugger, session_dict):
# by default, --synchronicity is set to synchronous
debugger.HandleCommand("command script add -f mysto.StepOver mysto")
return None

View File

@@ -0,0 +1,11 @@
script import sys, os
script sys.path.append(os.path.join(os.getcwd(), os.pardir))
script import welcome
script import bug11569
command script add welcome --function welcome.welcome_impl
command script add targetname --function welcome.target_name_impl
command script add longwait --function welcome.print_wait_impl
command script import mysto.py --allow-reload
command script add tell_sync --function welcome.check_for_synchro --synchronicity sync
command script add tell_async --function welcome.check_for_synchro --synchronicity async
command script add tell_curr --function welcome.check_for_synchro --synchronicity curr

View File

@@ -0,0 +1,32 @@
import sys
def welcome_impl(debugger, args, result, dict):
"""
Just a docstring for welcome_impl
A command that says hello to LLDB users
"""
print >>result, ('Hello ' + args + ', welcome to LLDB');
return None;
def target_name_impl(debugger, args, result, dict):
target = debugger.GetSelectedTarget()
file = target.GetExecutable()
print >>result, ('Current target ' + file.GetFilename())
if args == 'fail':
result.SetError('a test for error in command')
def print_wait_impl(debugger, args, result, dict):
result.SetImmediateOutputFile(sys.stdout)
print >>result, ('Trying to do long task..')
import time
time.sleep(1)
print >>result, ('Still doing long task..')
time.sleep(1)
print >>result, ('Done; if you saw the delays I am doing OK')
def check_for_synchro(debugger, args, result, dict):
if debugger.GetAsync() == True:
print >>result, ('I am running async')
if debugger.GetAsync() == False:
print >>result, ('I am running sync')