summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-15 09:38:28 +0800
committerruki <[email protected]>2016-07-15 09:38:28 +0800
commit58cff8a86ee90990a3fc5c82ec0c9048403350ed (patch)
treec3d22d8c963c9398cb1405b08aa529959bd37579
parentdfe578f0d1ffc49f280a6b60724cf8c69674d451 (diff)
add debugger for macosx
-rwxr-xr-xxmake/actions/config/xmake.lua3
-rwxr-xr-xxmake/actions/run/main.lua13
-rwxr-xr-xxmake/actions/run/xmake.lua1
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/debugger.lua48
-rw-r--r--xmake/core/tool/debugger.lua86
-rw-r--r--xmake/platforms/linux/checker.lua1
-rw-r--r--xmake/platforms/macosx/checker.lua2
-rw-r--r--xmake/tools/gdb.lua48
-rw-r--r--xmake/tools/lldb.lua59
9 files changed, 257 insertions, 4 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 424889004..882250b4e 100755
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -145,6 +145,9 @@ task("config")
, {}
, {nil, "sh", "kv", nil, "The Shared Library Linker" }
, {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" }
+
+ , {}
+ , {nil, "debugger", "kv", "auto", "The Debugger" }
-- show platform menu options
, function ()
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index fd1ce1888..65ff7658a 100755
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -27,12 +27,21 @@ import("core.project.config")
import("core.project.global")
import("core.project.project")
import("core.platform.platform")
+import("core.tool.debugger")
-- run binary target
function _run_binary(target)
- -- execute it
- os.execv(target:targetfile(), option.get("arguments"))
+ -- debugging?
+ if option.get("debug") then
+
+ -- debug it
+ debugger.run(target:targetfile(), option.get("arguments"))
+ else
+
+ -- run it
+ os.execv(target:targetfile(), option.get("arguments"))
+ end
end
-- run target
diff --git a/xmake/actions/run/xmake.lua b/xmake/actions/run/xmake.lua
index 5a63a69f5..42f7f0836 100755
--- a/xmake/actions/run/xmake.lua
+++ b/xmake/actions/run/xmake.lua
@@ -44,7 +44,6 @@ task("run")
, options =
{
{'d', "debug", "k", nil, "Run and debug the given target." }
- , {nil, "debugger", "kv", "auto", "Set the debugger path." }
, {}
, {nil, "target", "v", nil, "Run the given target." }
diff --git a/xmake/core/sandbox/modules/import/core/tool/debugger.lua b/xmake/core/sandbox/modules/import/core/tool/debugger.lua
new file mode 100644
index 000000000..cee1b8daf
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/tool/debugger.lua
@@ -0,0 +1,48 @@
+--!The Make-like Build Utility based on Lua
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file debugger.lua
+--
+
+-- define module
+local sandbox_core_tool_debugger = sandbox_core_tool_debugger or {}
+
+-- load modules
+local platform = require("platform/platform")
+local debugger = require("tool/debugger")
+local raise = require("sandbox/modules/raise")
+
+-- run the debugged program with arguments
+function sandbox_core_tool_debugger.run(shellname, argv)
+
+ -- get the debugger instance
+ local instance, errors = debugger.load()
+ if not instance then
+ raise(errors)
+ end
+
+ -- extract it
+ local ok, errors = instance:run(shellname, argv)
+ if not ok then
+ raise(errors)
+ end
+end
+
+-- return module
+return sandbox_core_tool_debugger
diff --git a/xmake/core/tool/debugger.lua b/xmake/core/tool/debugger.lua
new file mode 100644
index 000000000..619494974
--- /dev/null
+++ b/xmake/core/tool/debugger.lua
@@ -0,0 +1,86 @@
+--!The Make-like Build Utility based on Lua
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file debugger.lua
+--
+
+-- define module
+local debugger = debugger or {}
+
+-- load modules
+local io = require("base/io")
+local path = require("base/path")
+local utils = require("base/utils")
+local table = require("base/table")
+local string = require("base/string")
+local config = require("project/config")
+local sandbox = require("sandbox/sandbox")
+local platform = require("platform/platform")
+local tool = require("tool/tool")
+
+-- get the current tool
+function debugger:_tool()
+
+ -- get it
+ return self._TOOL
+end
+
+-- load the debugger
+function debugger.load()
+
+ -- get it directly from cache dirst
+ if debugger._INSTANCE then
+ return debugger._INSTANCE
+ end
+
+ -- new instance
+ local instance = table.inherit(debugger)
+
+ -- load the debugger tool
+ local result, errors = tool.load("dd")
+ if not result then
+ return nil, errors
+ end
+
+ -- save tool
+ instance._TOOL = result
+
+ -- save this instance
+ debugger._INSTANCE = instance
+
+ -- ok
+ return instance
+end
+
+-- get properties of the tool
+function debugger:get(name)
+
+ -- get it
+ return self:_tool().get(name)
+end
+
+-- run the debugged program with arguments
+function debugger:run(shellname, argv)
+
+ -- run it
+ return sandbox.load(self:_tool().run, shellname, argv)
+end
+
+-- return module
+return debugger
diff --git a/xmake/platforms/linux/checker.lua b/xmake/platforms/linux/checker.lua
index b0eb88dc1..17556f44c 100644
--- a/xmake/platforms/linux/checker.lua
+++ b/xmake/platforms/linux/checker.lua
@@ -71,6 +71,7 @@ function _check_toolchains(config)
checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver")
checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor")
checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker")
+ checker.check_toolchain(config, "dd", cross, "gdb", "the debugger")
end
-- init it
diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua
index dcd3a963e..519e1aae0 100644
--- a/xmake/platforms/macosx/checker.lua
+++ b/xmake/platforms/macosx/checker.lua
@@ -42,7 +42,7 @@ function _check_toolchains(config)
checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang++", "the shared library linker")
checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang", "the shared library linker")
checker.check_toolchain(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler")
-
+ checker.check_toolchain(config, "dd", "xcrun -sdk macosx ", "lldb", "the debugger")
end
-- init it
diff --git a/xmake/tools/gdb.lua b/xmake/tools/gdb.lua
new file mode 100644
index 000000000..db6b1f707
--- /dev/null
+++ b/xmake/tools/gdb.lua
@@ -0,0 +1,48 @@
+--!The Make-like Build Utility based on Lua
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file gdb.lua
+--
+
+-- init it
+function init(shellname)
+
+ -- save name
+ _g.shellname = shellname or "gdb"
+
+end
+
+-- get the property
+function get(name)
+
+ -- get it
+ return _g[name]
+end
+
+-- run the debugged program with arguments
+function run(shellname, argv)
+
+end
+
+-- check the given flags
+function check(flags)
+
+ -- check it
+ os.run("%s %s -h", _g.shellname, ifelse(flags, flags, ""))
+end
diff --git a/xmake/tools/lldb.lua b/xmake/tools/lldb.lua
new file mode 100644
index 000000000..ff62c3b56
--- /dev/null
+++ b/xmake/tools/lldb.lua
@@ -0,0 +1,59 @@
+--!The Make-like Build Utility based on Lua
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file lldb.lua
+--
+
+-- init it
+function init(shellname)
+
+ -- save name
+ _g.shellname = shellname or "lldb"
+
+end
+
+-- get the property
+function get(name)
+
+ -- get it
+ return _g[name]
+end
+
+-- run the debugged program with arguments
+function run(shellname, argv)
+
+ -- attempt to split shellname, .e.g xcrun -sdk macosx lldb
+ local shellnames = _g.shellname:split("%s")
+
+ -- patch arguments
+ table.insert(argv, 1, shellname)
+ for i = #shellnames, 2, -1 do
+ table.insert(argv, 1, shellnames[i])
+ end
+
+ -- run it
+ os.execv(shellnames[1], argv)
+end
+
+-- check the given flags
+function check(flags)
+
+ -- check it
+ os.run("%s %s -h", _g.shellname, ifelse(flags, flags, ""))
+end