mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 11:39:35 +00:00
<rdar://problem/12500212> Test case for the new plugin feature
llvm-svn: 166453
This commit is contained in:
parent
c2d984c823
commit
bc08ab450a
@ -827,6 +827,9 @@ def setupSysPath():
|
||||
print relPath + ', or ' + baiPath
|
||||
sys.exit(-1)
|
||||
|
||||
# If tests need to find LLDB_FRAMEWORK, now they can do it
|
||||
os.environ["LLDB_FRAMEWORK"] = os.path.dirname(os.path.dirname(lldbPath))
|
||||
|
||||
# This is to locate the lldb.py module. Insert it right after sys.path[0].
|
||||
sys.path[1:1] = [lldbPath]
|
||||
if dumpSysPath:
|
||||
|
11
lldb/test/functionalities/plugins/commands/Makefile
Normal file
11
lldb/test/functionalities/plugins/commands/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
all: foo.dylib
|
||||
|
||||
CWD := $(shell pwd)
|
||||
|
||||
all: foo.dylib
|
||||
|
||||
foo.dylib:
|
||||
clang++ -O0 -g -stdlib=libc++ -dynamiclib -o plugin.dylib plugin.cpp -framework LLDB -F $(LLDB_FRAMEWORK)/..
|
||||
|
||||
clean:
|
||||
rm -rf plugin.dylib plugin.dylib.dSYM/* plugin.dylib.dSYM
|
@ -0,0 +1,57 @@
|
||||
"""
|
||||
Test that plugins that load commands work correctly.
|
||||
"""
|
||||
|
||||
import os, time
|
||||
import re
|
||||
import unittest2
|
||||
import lldb
|
||||
from lldbtest import *
|
||||
import lldbutil
|
||||
|
||||
class PluginCommandTestCase(TestBase):
|
||||
|
||||
mydir = os.path.join("functionalities", "plugins", "commands")
|
||||
|
||||
def setUp(self):
|
||||
# Call super's setUp().
|
||||
TestBase.setUp(self)
|
||||
|
||||
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
||||
def test_load_plugin(self):
|
||||
"""Test that plugins that load commands work correctly."""
|
||||
|
||||
# Invoke the default build rule.
|
||||
self.buildDefault()
|
||||
|
||||
debugger = lldb.SBDebugger.Create()
|
||||
|
||||
retobj = lldb.SBCommandReturnObject()
|
||||
|
||||
retval = debugger.GetCommandInterpreter().HandleCommand("plugin load plugin.dylib",retobj)
|
||||
|
||||
retobj.Clear()
|
||||
|
||||
retval = debugger.GetCommandInterpreter().HandleCommand("plugin_loaded_command child abc def ghi",retobj)
|
||||
|
||||
if self.TraceOn():
|
||||
print retobj.GetOutput()
|
||||
|
||||
self.expect(retobj,substrs = ['abc def ghi'], exe=False)
|
||||
|
||||
retobj.Clear()
|
||||
|
||||
# check that abbreviations work correctly in plugin commands.
|
||||
retval = debugger.GetCommandInterpreter().HandleCommand("plugin_loaded_ ch abc def ghi",retobj)
|
||||
|
||||
if self.TraceOn():
|
||||
print retobj.GetOutput()
|
||||
|
||||
self.expect(retobj,substrs = ['abc def ghi'], exe=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import atexit
|
||||
lldb.SBDebugger.Initialize()
|
||||
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
||||
unittest2.main()
|
56
lldb/test/functionalities/plugins/commands/plugin.cpp
Normal file
56
lldb/test/functionalities/plugins/commands/plugin.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//===-- fooplugin.cpp -------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/*
|
||||
An example plugin for LLDB that provides a new foo command with a child subcommand
|
||||
Compile this into a dylib foo.dylib and load by placing in appropriate locations on disk or
|
||||
by typing plugin load foo.dylib at the LLDB command line
|
||||
*/
|
||||
|
||||
#include <LLDB/SBCommandInterpreter.h>
|
||||
#include <LLDB/SBCommandReturnObject.h>
|
||||
#include <LLDB/SBDebugger.h>
|
||||
|
||||
namespace lldb {
|
||||
bool
|
||||
PluginInitialize (lldb::SBDebugger debugger);
|
||||
}
|
||||
|
||||
class ChildCommand : public lldb::SBCommandPluginInterface
|
||||
{
|
||||
public:
|
||||
virtual bool
|
||||
DoExecute (lldb::SBDebugger debugger,
|
||||
char** command,
|
||||
lldb::SBCommandReturnObject &result)
|
||||
{
|
||||
if (command)
|
||||
{
|
||||
const char* arg = *command;
|
||||
while (arg)
|
||||
{
|
||||
result.Printf("%s ",arg);
|
||||
arg = *(++command);
|
||||
}
|
||||
result.Printf("\n");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
bool
|
||||
lldb::PluginInitialize (lldb::SBDebugger debugger)
|
||||
{
|
||||
lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
|
||||
lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL);
|
||||
foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command");
|
||||
return true;
|
||||
}
|
@ -1184,6 +1184,9 @@ class TestBase(Base):
|
||||
"Command '" + str + "' is expected to fail!")
|
||||
else:
|
||||
# No execution required, just compare str against the golden input.
|
||||
if isinstance(str,lldb.SBCommandReturnObject):
|
||||
output = str.GetOutput()
|
||||
else:
|
||||
output = str
|
||||
with recording(self, trace) as sbuf:
|
||||
print >> sbuf, "looking at:", output
|
||||
|
Loading…
Reference in New Issue
Block a user