mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-10-15 05:19:41 -07:00
be more robust to user/project paths passed via command line to raddbg; do not interpret them as targets
This commit is contained in:
1 parent
87fa6b9239
commit
a85284793b
2 files changed
+114
-77
No files matched your search
@@ -494,83 +494,6 @@ entry_point(CmdLine *cmd_line)
|
||||
rd_init(cmd_line);
|
||||
}
|
||||
|
||||
//- rjf: setup initial target from command line args
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8List target_args = {0};
|
||||
{
|
||||
B32 after_first_non_flag = 0;
|
||||
for(U64 idx = 1; idx < cmd_line->argc; idx += 1)
|
||||
{
|
||||
String8 arg = str8_cstring(cmd_line->argv[idx]);
|
||||
if(!str8_match(str8_prefix(arg, 1), str8_lit("-"), 0) &&
|
||||
!str8_match(str8_prefix(arg, 1), str8_lit("--"), 0) &&
|
||||
!str8_match(str8_prefix(arg, 1), str8_lit("/"), 0))
|
||||
{
|
||||
after_first_non_flag = 1;
|
||||
}
|
||||
if(after_first_non_flag)
|
||||
{
|
||||
str8_list_push(scratch.arena, &target_args, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(target_args.node_count > 0 && target_args.first->string.size != 0)
|
||||
{
|
||||
//- rjf: unpack command line inputs
|
||||
String8 executable_name_string = {0};
|
||||
String8 arguments_string = {0};
|
||||
String8 working_directory_string = {0};
|
||||
{
|
||||
// rjf: unpack full executable path
|
||||
if(target_args.first->string.size != 0)
|
||||
{
|
||||
String8 exe_name = target_args.first->string;
|
||||
PathStyle style = path_style_from_str8(exe_name);
|
||||
if(style == PathStyle_Relative)
|
||||
{
|
||||
String8 current_path = os_get_current_path(scratch.arena);
|
||||
exe_name = push_str8f(scratch.arena, "%S/%S", current_path, exe_name);
|
||||
exe_name = path_normalized_from_string(scratch.arena, exe_name);
|
||||
}
|
||||
executable_name_string = exe_name;
|
||||
}
|
||||
|
||||
// rjf: unpack working directory
|
||||
if(target_args.first->string.size != 0)
|
||||
{
|
||||
String8 path_part_of_arg = str8_chop_last_slash(target_args.first->string);
|
||||
if(path_part_of_arg.size != 0)
|
||||
{
|
||||
String8 path = push_str8f(scratch.arena, "%S/", path_part_of_arg);
|
||||
working_directory_string = path;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: unpack arguments
|
||||
String8List passthrough_args_list = {0};
|
||||
for(String8Node *n = target_args.first->next; n != 0; n = n->next)
|
||||
{
|
||||
str8_list_push(scratch.arena, &passthrough_args_list, n->string);
|
||||
}
|
||||
StringJoin join = {str8_lit(""), str8_lit(" "), str8_lit("")};
|
||||
arguments_string = str8_list_join(scratch.arena, &passthrough_args_list, &join);
|
||||
}
|
||||
|
||||
//- rjf: build config tree
|
||||
RD_Cfg *command_line_root = rd_cfg_child_from_string(rd_state->root_cfg, str8_lit("command_line"));
|
||||
RD_Cfg *target = rd_cfg_new(command_line_root, str8_lit("target"));
|
||||
RD_Cfg *exe = rd_cfg_new(target, str8_lit("executable"));
|
||||
RD_Cfg *args = rd_cfg_new(target, str8_lit("arguments"));
|
||||
RD_Cfg *wdir = rd_cfg_new(target, str8_lit("working_directory"));
|
||||
rd_cfg_new(exe, executable_name_string);
|
||||
rd_cfg_new(args, arguments_string);
|
||||
rd_cfg_new(wdir, working_directory_string);
|
||||
rd_cmd(RD_CmdKind_SelectTarget, .cfg = target->id);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
//- rjf: set up shared resources for ipc to this instance; launch IPC signaler thread
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
|
||||
Reference in new issue
Block a user