summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-09 11:14:30 +0800
committerruki <[email protected]>2022-10-09 11:14:56 +0800
commit4eab4583144dd0319c33431a557a06905c811ef5 (patch)
tree99ff8a2502e2c2c0a0eec7f64ea6dd107f64a681
parent290921f5b54ff1529388644c296b65e405720f29 (diff)
add exclusive mode for debugger
-rw-r--r--core/src/xmake/process/openv.c21
-rw-r--r--xmake/core/base/os.lua9
-rw-r--r--xmake/modules/devel/debugger/run.lua9
3 files changed, 35 insertions, 4 deletions
diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c
index 5114e263c..fdb0a7f0f 100644
--- a/core/src/xmake/process/openv.c
+++ b/core/src/xmake/process/openv.c
@@ -30,6 +30,9 @@
*/
#include "prefix.h"
#include "../io/prefix.h"
+#if defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD)
+# include <signal.h>
+#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
@@ -105,6 +108,7 @@ tb_int_t xm_process_openv(lua_State* lua)
tb_process_attr_t attr = {0};
// get option arguments
+ tb_bool_t exclusive = tb_false;
tb_size_t envn = 0;
tb_char_t const* envs[1024] = {0};
tb_char_t const* inpath = tb_null;
@@ -125,6 +129,13 @@ tb_int_t xm_process_openv(lua_State* lua)
attr.flags |= TB_PROCESS_FLAG_DETACH;
lua_pop(lua, 1);
+ // is exclusive?
+ lua_pushstring(lua, "exclusive");
+ lua_gettable(lua, 3);
+ if (lua_toboolean(lua, -1))
+ exclusive = tb_true;
+ lua_pop(lua, 1);
+
// get curdir
lua_pushstring(lua, "curdir");
lua_gettable(lua, 3);
@@ -318,6 +329,16 @@ tb_int_t xm_process_openv(lua_State* lua)
// set the new environments
if (envn > 0) attr.envp = envs;
+ /* we need ignore SIGINT and SIGQUIT if we enter exclusive mode
+ * @see https://github.com/xmake-io/xmake/discussions/2893
+ */
+#if defined(SIGINT)
+ if (exclusive) signal(SIGINT, SIG_IGN);
+#endif
+#if defined(SIGQUIT)
+ if (exclusive) signal(SIGQUIT, SIG_IGN);
+#endif
+
// init process
tb_process_ref_t process = (tb_process_ref_t)tb_process_init(shellname, argv, &attr);
if (process) xm_lua_pushpointer(lua, (tb_pointer_t)process);
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 4a357085d..b28381ccd 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -797,7 +797,14 @@ function os.execv(program, argv, opt)
end
-- init open options
- local openopt = {envs = envs, stdin = opt.stdin, stdout = opt.stdout, stderr = opt.stderr, curdir = opt.curdir, detach = opt.detach}
+ local openopt = {
+ envs = envs,
+ stdin = opt.stdin,
+ stdout = opt.stdout,
+ stderr = opt.stderr,
+ curdir = opt.curdir,
+ detach = opt.detach,
+ exclusive = opt.exclusive}
-- open command
local ok = -1
diff --git a/xmake/modules/devel/debugger/run.lua b/xmake/modules/devel/debugger/run.lua
index 9f7bb28e7..d343aad12 100644
--- a/xmake/modules/devel/debugger/run.lua
+++ b/xmake/modules/devel/debugger/run.lua
@@ -35,6 +35,7 @@ import("detect.tools.find_vsjitdebugger")
function _run_gdb(program, argv, opt)
-- find gdb
+ opt = opt or {}
local gdb = find_gdb({program = config.get("debugger")})
if not gdb then
return false
@@ -46,7 +47,7 @@ function _run_gdb(program, argv, opt)
table.insert(argv, 1, "--args")
-- run it
- os.execv(gdb, argv, opt)
+ os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
end
@@ -54,6 +55,7 @@ end
function _run_cudagdb(program, argv, opt)
-- find cudagdb
+ opt = opt or {}
local gdb = find_cudagdb({program = config.get("debugger")})
if not gdb then
return false
@@ -65,7 +67,7 @@ function _run_cudagdb(program, argv, opt)
table.insert(argv, 1, "--args")
-- run it
- os.execv(gdb, argv, opt)
+ os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
end
@@ -73,6 +75,7 @@ end
function _run_lldb(program, argv, opt)
-- find lldb
+ opt = opt or {}
local lldb = find_lldb({program = config.get("debugger")})
if not lldb then
return false
@@ -91,7 +94,7 @@ function _run_lldb(program, argv, opt)
end
-- run it
- os.execv(names[1], argv, opt)
+ os.execv(names[1], argv, table.join(opt, {exclusive = true}))
return true
end