From 7ff06b5ef803c86881f593e9b44349d33cdce384 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Thu, 9 Nov 2017 22:57:18 +0100 Subject: [PATCH] New way of loading the debugger. --- Moose Development/Debugger/connect.lua | 56 +++++++++++++++++++++++++ Moose Development/Debugger/debugger.lua | 16 ++----- Moose Development/Moose/Moose.lua | 6 --- 3 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 Moose Development/Debugger/connect.lua diff --git a/Moose Development/Debugger/connect.lua b/Moose Development/Debugger/connect.lua new file mode 100644 index 000000000..868088dfc --- /dev/null +++ b/Moose Development/Debugger/connect.lua @@ -0,0 +1,56 @@ + +-- If you want to use the debugger, move these 3 lines into MissionScripting.lua of DCS world. + + + +--------------------------------------------------------------------------------------------------------------------------- +-- MissionScripting.lua modifications +--------------------------------------------------------------------------------------------------------------------------- + +-- --Initialization script for the Mission lua Environment (SSE) +-- +-- dofile('Scripts/ScriptingSystem.lua') +-- +-- package.path = package.path..";.\\LuaSocket\\?.lua;" +-- local initconnection = require("debugger") +-- initconnection( "127.0.0.1", 10000, "dcsserver", nil, "win", "" ) +-- +-- --Sanitize Mission Scripting environment +-- --This makes unavailable some unsecure functions. +-- --Mission downloaded from server to client may contain potentialy harmful lua code that may use these functions. +-- --You can remove the code below and make availble these functions at your own risk. +-- +-- local function sanitizeModule(name) +-- _G[name] = nil +-- package.loaded[name] = nil +-- end +-- +-- do +-- sanitizeModule('os') +-- sanitizeModule('io') +-- sanitizeModule('lfs') +-- require = nil +-- loadlib = nil +-- end + +--------------------------------------------------------------------------------------------------------------------------- +--------------------------------------------------------------------------------------------------------------------------- + + + +-- So for clarity, these are the three lines of code that matter! + +-- Add LuaSocket to the LUAPATH, so that it can be found. +package.path = package.path..";.\\LuaSocket\\?.lua;" + +-- Connect to the debugger, first require it. +local initconnection = require("debugger") + +-- Now make the connection.. +-- "127.0.0.1" is the localhost. +-- 10000 is the port. If you wanna use another port in LDT, change this number too! +-- "dcsserver" is the name of the server. If you wanna use another name, change the name here too! +-- nil (is for transport protocol, but not using this) +-- "win" don't touch. But is important to indicate that we are in a windows environment to the debugger script. +initconnection( "127.0.0.1", 10000, "dcsserver", nil, "win" ) + diff --git a/Moose Development/Debugger/debugger.lua b/Moose Development/Debugger/debugger.lua index a03dcb68b..e92e1b2b5 100644 --- a/Moose Development/Debugger/debugger.lua +++ b/Moose Development/Debugger/debugger.lua @@ -724,7 +724,6 @@ end --TODO dynamic code handling -- The DBGp specification is not clear about the line number meaning, this implementation is 1-based and numbers are inclusive function M.source(self, args) - BASE:E( { self = self, args = args } ) local path if args.f then path = platform.get_path(args.f) @@ -733,16 +732,13 @@ function M.source(self, args) assert(path:sub(1,1) == "@") path = path:sub(2) end - BASE:E( { path = path } ) local file, err = io.open(path) if not file then - BASE:E( { "Not found" } ) dbgp.error(100, err, { success = 0 }) end - BASE:E( { "Found" } ) + -- Commented out by FlightControl. Not working in DCS. -- Try to identify compiled files --if file:read(1) == "\033" then dbgp.error(100, args.f.." is bytecode", { success = 0 }) end - BASE:E( { file = file } ) --file:seek("set", 0) @@ -2178,9 +2174,7 @@ function M.init(executionplatform,workingdirectory) -- define current platform -------------------------- -- check parameter - - BASE:E({executionplatform=executionplatform, workingdirectory=workingdirectory}) - + if executionplatform and executionplatform ~= "unix" and executionplatform ~="win" then error("Unable to initialize platform module : execution platform should be 'unix' or 'win'.") end @@ -2248,7 +2242,6 @@ function M.init(executionplatform,workingdirectory) if p then local res = p:read("*l") p:close() - BASE:E( { res = res } ) return M.normalize(res) end end @@ -2787,6 +2780,8 @@ end local debug = require "debug" +local io = io + -- To avoid cyclic dependency, internal state of the debugger that must be accessed -- elsewhere (in commands most likely) will be stored in a fake module "debugger.core" local core = { } @@ -3089,7 +3084,6 @@ end local function debugger_loop(self, async_packet) self.skt:settimeout(nil) -- set socket blocking - BASE:E( "in debugger loop" ) -- in async mode, the debugger does not wait for another command before continuing and does not modify previous_context local async_mode = async_packet ~= nil @@ -3117,9 +3111,7 @@ local function debugger_loop(self, async_packet) -- invoke function local func = commands[cmd] if func then - BASE:E( "before call" ) local ok, cont = xpcall(function() return func(self, args, data) end, debug.traceback) - BASE:E( { "after call", ok } ) if not ok then -- internal exception local code, msg, attr if type(cont) == "table" and getmetatable(cont) == dbgp.DBGP_ERR_METATABLE then diff --git a/Moose Development/Moose/Moose.lua b/Moose Development/Moose/Moose.lua index cef97254c..25308e705 100644 --- a/Moose Development/Moose/Moose.lua +++ b/Moose Development/Moose/Moose.lua @@ -11,9 +11,3 @@ _DATABASE = DATABASE:New() -- Core.Database#DATABASE _SETTINGS = SETTINGS:Set() -package.path = package.path..";.\\LuaSocket\\?.lua;" - -local initconnection = require("debugger") -initconnection( "127.0.0.1", 10000, "dcsserver", nil, "win", "" ) - -print("Debugger is configured!")