mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-08 23:08:08 +00:00
torture_dbg: reuse Windows env-var expander in the harness compile/link/launch steps
This commit is contained in:
committed by
Ryan Fleury
parent
96e20759d5
commit
58fc57f6a3
@@ -243,3 +243,37 @@ lnk_data_from_cmd_line(Arena *arena, LNK_CmdLine cmd_line)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_expand_env_vars_windows(Arena *arena, HashTable *env_vars, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
String8List list = {0};
|
||||
for (U64 i = 0; i < string.size; ) {
|
||||
U64 open = str8_find_needle(string, i, str8_lit("%"), 0);
|
||||
U64 close = str8_find_needle(string, open+1, str8_lit("%"), 0);
|
||||
|
||||
String8 text = str8_substr(string, rng_1u64(i, open));
|
||||
str8_list_push(scratch.arena, &list, text);
|
||||
i += text.size;
|
||||
|
||||
if (open < close) {
|
||||
String8 env_var_name = str8_substr(string, rng_1u64(open+1, close));
|
||||
BucketNode *match = hash_table_search_path(env_vars, env_var_name);
|
||||
if (match) {
|
||||
str8_list_push(scratch.arena, &list, match->v.value_string);
|
||||
i = close+1;
|
||||
} else {
|
||||
str8_list_pushf(scratch.arena, &list, "%%%S", env_var_name);
|
||||
i = close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String8 result = str8_list_join(arena, &list, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,3 +32,5 @@ internal void lnk_cmd_line_concat_in_place(LNK_CmdLine *list, LNK_CmdLine *to_co
|
||||
|
||||
internal String8List lnk_data_from_cmd_line(Arena *arena, LNK_CmdLine cmd_line);
|
||||
|
||||
internal String8 lnk_expand_env_vars_windows(Arena *arena, HashTable *env_vars, String8 string);
|
||||
|
||||
|
||||
@@ -1069,39 +1069,6 @@ lnk_print_help(void)
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_expand_env_vars_windows(Arena *arena, HashTable *env_vars, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
String8List list = {0};
|
||||
for (U64 i = 0; i < string.size; ) {
|
||||
U64 open = str8_find_needle(string, i, str8_lit("%"), 0);
|
||||
U64 close = str8_find_needle(string, open+1, str8_lit("%"), 0);
|
||||
|
||||
String8 text = str8_substr(string, rng_1u64(i, open));
|
||||
str8_list_push(scratch.arena, &list, text);
|
||||
i += text.size;
|
||||
|
||||
if (open < close) {
|
||||
String8 env_var_name = str8_substr(string, rng_1u64(open+1, close));
|
||||
BucketNode *match = hash_table_search_path(env_vars, env_var_name);
|
||||
if (match) {
|
||||
str8_list_push(scratch.arena, &list, match->v.value_string);
|
||||
i = close+1;
|
||||
} else {
|
||||
str8_list_pushf(scratch.arena, &list, "%%%S", env_var_name);
|
||||
i = close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String8 result = str8_list_join(arena, &list, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8List
|
||||
lnk_unwrap_rsp(Arena *arena, String8List arg_list)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,17 @@
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
||||
// TODO: linux: -no-pie crashes the tracer
|
||||
//
|
||||
// TODO: crashes
|
||||
// compile: "-O0 -g foo.c -fPIC -shared -o libfoo.so"
|
||||
// compile: "-O0 -g main.c -L. -lfoo -o main -Wl,-rpath,%CWD%"
|
||||
// ...
|
||||
// dw_compute_cfa dwarf_unwind.c:261:5
|
||||
// d_establish_frame_unwind_context__dwarf dbg_engine_ctrl.c:1946:25
|
||||
// d_unwind_from_thread dbg_engine_ctrl.c:2913:30
|
||||
// ...
|
||||
|
||||
/// file: "foo.c"
|
||||
|
||||
|
||||
@@ -667,6 +667,10 @@ T_RunSig(dbg_script_runner)
|
||||
}
|
||||
}
|
||||
|
||||
// compiler vars
|
||||
HashTable *script_vars = hash_table_init(arena, 1000);
|
||||
hash_table_push_path_string(arena, script_vars, str8_lit("CWD"), g_wdir);
|
||||
|
||||
// run compilers
|
||||
for EachNode(directive, T_DbgScriptDirective, script.directives[OperatingSystem_CURRENT][T_DbgScriptDirectiveKind_Compile].first) {
|
||||
T_Compiler compiler = directive->compile.compiler;
|
||||
@@ -689,8 +693,9 @@ T_RunSig(dbg_script_runner)
|
||||
}
|
||||
|
||||
// invoke compiler with arguments from directive
|
||||
if (t_invoke(compiler_path, directive->args, max_U64) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to launch compiler: \"%.*s %.*s\"\n", str8_varg(compiler_path), str8_varg(directive->args));
|
||||
String8 expanded_args = lnk_expand_env_vars_windows(arena, script_vars, directive->args);
|
||||
if (t_invoke(compiler_path, expanded_args, max_U64) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to launch compiler: \"%.*s %.*s\"\n", str8_varg(compiler_path), str8_varg(expanded_args));
|
||||
T_Ok(0);
|
||||
}
|
||||
if (g_last_exit_code) {
|
||||
@@ -704,15 +709,17 @@ T_RunSig(dbg_script_runner)
|
||||
// run linkers
|
||||
String8 linker_path = t_radlink_path();
|
||||
for EachNode(directive, T_DbgScriptDirective, script.directives[OperatingSystem_CURRENT][T_DbgScriptDirectiveKind_Link].first) {
|
||||
if (t_invoke(linker_path, directive->args, max_U64) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to launch linker: \"%.*s %.*s\"\n", str8_varg(linker_path), str8_varg(directive->args));
|
||||
String8 expanded_args = lnk_expand_env_vars_windows(arena, script_vars, directive->args);
|
||||
if (t_invoke(linker_path, expanded_args, max_U64) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to launch linker: \"%.*s %.*s\"\n", str8_varg(linker_path), str8_varg(expanded_args));
|
||||
T_Ok(0);
|
||||
}
|
||||
}
|
||||
|
||||
// launch targets
|
||||
for EachNode(directive, T_DbgScriptDirective, script.directives[OperatingSystem_CURRENT][T_DbgScriptDirectiveKind_Launch].first) {
|
||||
String8 cmdl = str8f(arena, "--user:%S.raddbg_user %S", t_make_file_path(arena, str8_lit("temp")), directive->args);
|
||||
String8 expanded_args = lnk_expand_env_vars_windows(arena, script_vars, directive->args);
|
||||
String8 cmdl = str8f(arena, "--user:%S.raddbg_user %S", t_make_file_path(arena, str8_lit("temp")), expanded_args);
|
||||
if (t_dbg_launch(cmdl, T_Dbg_DefaultTimeout) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to launch debugger with command line \"%.*s %.*s\"; work dir \"%.*s\"\n", str8_varg(t_raddbg_path()), str8_varg(cmdl), str8_varg(g_wdir));
|
||||
T_Ok(0);
|
||||
|
||||
Reference in New Issue
Block a user