From e1007b276de87e5a6ce59cb7b245182540db1de6 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 24 Jun 2017 16:54:04 +0430 Subject: new command --- bruiser/bruiser.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h index 4c532b3..cf47924 100644 --- a/bruiser/bruiser.h +++ b/bruiser/bruiser.h @@ -131,10 +131,12 @@ help CMDHelp[] = { {"Structs()", "", "lists all available struct declarations", "none", "returns a string array of the structur declarations"}, {"Arrays()", "", "lists all available array declarations", "none", "returns a string array of the array declarations"}, {"Unions()", "", "lists all available union declarations", "none", "returns a string array of the union declarations"}, - {"make()", "", "runs your make command", "", ""}, + {"make()", "make(\"all\")", "runs your make command", "", ""}, {"historysize()", "historysize(200)", "sets the history size", "[uint history_size]", ""}, {"showsource()", "showsource(1,5,\"test.cpp\")", "shows the source code for the given range and filename", "[uint beginline, uint endline, string filename]", "returns a string array of the returned source file"}, - {"extractmutagen()", "extractmutagen(\"test.cpp\")", "runs m0 on the source(s)", "[string]", "pid"} + {"extractmutagen()", "extractmutagen(\"test.cpp\")", "runs m0 on the source(s)", "[string]", "pid"}, + {"strainrecognition()", "", "", "", ""}, + {"setmakepath()", "setmakepath(\"../../myproject\")", "tells bruiser where to execute the make command run from make()", "string", "child pid"} }; /**********************************************************************************************************************/ /** -- cgit v1.2.3 From f13dbdf568c3a44643b458ed72d48cdfaa597e77 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 24 Jun 2017 16:54:13 +0430 Subject: new command --- bruiser/bruiser-extra.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h index 73ffe3c..a4389f0 100644 --- a/bruiser/bruiser-extra.h +++ b/bruiser/bruiser-extra.h @@ -98,7 +98,6 @@ std::vector LUA_FUNCS = "version()", "clear()", "m0()", - "runlua", "Funcs()", "Vars()", "Arrays()", @@ -111,6 +110,8 @@ std::vector LUA_FUNCS = "showsource", "readxmlfile", "extractmutagen", + "strainrecognition()", + "setmakepath", "_G", "_VERSION", "assert", -- cgit v1.2.3 From b52b7e0c0c60cf47120ebce7b83f993dd7e1c59a Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 24 Jun 2017 16:54:25 +0430 Subject: a new example script --- bruiser/lua-scripts/mutation-example.lua | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 bruiser/lua-scripts/mutation-example.lua diff --git a/bruiser/lua-scripts/mutation-example.lua b/bruiser/lua-scripts/mutation-example.lua new file mode 100644 index 0000000..b863b71 --- /dev/null +++ b/bruiser/lua-scripts/mutation-example.lua @@ -0,0 +1,9 @@ +setmakepath("../test/bruisertest") +make("clean") +text = hijackmain() +file = io.open("../test/bruisertest/mutatant.cpp", "w") +print("------------------------------------------------------------------") +print(text) +print("------------------------------------------------------------------") +file:write(a) +file:close() -- cgit v1.2.3 From 229b8434a56acf77fd3b9b847465cde967f87ab5 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 24 Jun 2017 16:55:06 +0430 Subject: added a new command, fixed an old one --- bruiser/bruiser.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 7030377..f9e317d 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include #include #include +#include /*LLVM headers*/ #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" @@ -82,6 +83,7 @@ namespace std::vector PATH; std::vector SOURCE_FILES; + std::string MAKEPATH; }; struct ShellCache @@ -1092,22 +1094,49 @@ class LuaWrapper int BruiserLuaRunMake(lua_State* __ls) { - unsigned int result = 0U; unsigned int args = 0U; if ((args = lua_gettop(__ls)) != 1U) { PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help()."); - return 0; + lua_pushnumber(__ls, 1); + return 1; + } + + std::string makearg = lua_tostring(__ls , 1); + + if (ShellGlobalInstance.MAKEPATH == "") + { + PRINT_WITH_COLOR_LB(RED, "MAKEPATH is not set. set it using setmakepath or type help."); + lua_pushnumber(__ls, 1); + return 1; } - const char *makepath; - makepath = lua_tostring(__ls, 1); + pid_t pid = fork(); - result = dostring(__ls, makepath, "make"); + if (pid < 0) + { + PRINT_WITH_COLOR_LB(RED, "could not fork..."); + lua_pushnumber(__ls, EXIT_FAILURE); + } + + if (pid == 0) + { + std::cout << BLUE << "MAKEPATH: " << ShellGlobalInstance.MAKEPATH << NORMAL << "\n"; + std::cout << BLUE << "Running: " << "make -C " << ShellGlobalInstance.MAKEPATH << " " << makearg << NORMAL << "\n"; + int retval = execl("/usr/bin/make", "make", "-C", ShellGlobalInstance.MAKEPATH.c_str(), makearg.c_str(), NULL); + lua_pushnumber(__ls, retval); + exit(EXIT_SUCCESS); + } + + if (pid > 0) + { + int status; + pid_t returned; + returned = waitpid(pid, &status, 0); + lua_pushnumber(__ls, returned); + } - lua_pushnumber(__ls, result); - free((char*)makepath); return 1; } @@ -1220,6 +1249,28 @@ class LuaWrapper return 1; } + int BruiserLuaStrainRecognition(lua_State* __ls) + { + unsigned int numthreads = std::thread::hardware_concurrency(); + lua_pushnumber(__ls, numthreads); + return 1; + } + + int BruiserLuaSetMakePath(lua_State* __ls) + { + int numargs = lua_gettop(__ls); + + if (numargs != 1) + { + PRINT_WITH_COLOR_LB(RED, "wrong number of args. run help."); + return 0; + } + + ShellGlobalInstance.MAKEPATH = lua_tostring(__ls, 1); + + return 0; + } + #define LIST_GENERATOR(__x1) \ int List##__x1(lua_State* __ls)\ {\ @@ -1335,6 +1386,8 @@ int main(int argc, const char **argv) lua_register(LE.GetLuaState(), "historysize", &LuaDispatch<&LuaWrapper::BruiserLuaChangeHistorySize>); lua_register(LE.GetLuaState(), "showsource", &LuaDispatch<&LuaWrapper::BruiserLuaShowSourcecode>); lua_register(LE.GetLuaState(), "extractmutagen", &LuaDispatch<&LuaWrapper::BruiserLuaMutagenExtraction>); + lua_register(LE.GetLuaState(), "strainrecognition", &LuaDispatch<&LuaWrapper::BruiserLuaStrainRecognition>); + lua_register(LE.GetLuaState(), "setmakepath", &LuaDispatch<&LuaWrapper::BruiserLuaSetMakePath>); /*its just regisering the List function from LuaWrapper with X-macros.*/ #define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>); -- cgit v1.2.3