void smuggle_dyld_settings(struct gdb_environ *e) { /* The list of DYLD_* names was gleaned from dyld's src/dyld.cpp: */ struct dyld_smuggle_pairs env_names[] = { { "DYLD_FRAMEWORK_PATH", "GDB_DYLD_FRAMEWORK_PATH" }, { "DYLD_FALLBACK_FRAMEWORK_PATH", "GDB_DYLD_FALLBACK_FRAMEWORK_PATH" }, { "DYLD_LIBRARY_PATH", "GDB_DYLD_LIBRARY_PATH" }, { "DYLD_FALLBACK_LIBRARY_PATH", "GDB_DYLD_FALLBACK_LIBRARY_PATH" }, { "DYLD_ROOT_PATH", "GDB_DYLD_ROOT_PATH" }, { "DYLD_PATHS_ROOT", "GDB_DYLD_PATHS_ROOT" }, { "DYLD_IMAGE_SUFFIX", "GDB_DYLD_IMAGE_SUFFIX" }, { "DYLD_INSERT_LIBRARIES", "GDB_DYLD_INSERT_LIBRARIES" }, { NULL, NULL } }; int i; for (i = 0; env_names[i].real_name != NULL; i++) { const char *real_val = get_in_environ(e, env_names[i].real_name); const char *smuggled_val = get_in_environ(e, env_names[i].smuggled_name); if ((real_val == NULL) && (smuggled_val == NULL)) continue; if (smuggled_val == NULL) continue; /* Is the value of the DYLD_* env var truncated to ""? */ if ((real_val != NULL) && (real_val[0] != '\0')) continue; /* real_val has a value and it looks legitimate - do NOT overwrite it * with the smuggled version: */ if (real_val != NULL) continue; set_in_environ(e, env_names[i].real_name, smuggled_val); } }
void _initialize_mi_cmd_env (void) { char *env; /* We want original execution path to reset to, if desired later. */ env = get_in_environ (inferior_environ, path_var_name); /* Can be null if path is not set. */ if (!env) env = ""; orig_path = xstrdup (env); }
void _initialize_mi_cmd_env (void) { struct gdb_environ *environment; char *env; /* We want original execution path to reset to, if desired later. At this point, current inferior is not created, so cannot use current_inferior ()->environment. Also, there's no obvious place where this code can be moved suchs that it surely run before any code possibly mangles original PATH. */ environment = make_environ (); init_environ (environment); env = get_in_environ (environment, path_var_name); /* Can be null if path is not set. */ if (!env) env = ""; orig_path = xstrdup (env); }
/* Add one or more directories to start of executable search path. */ enum mi_cmd_result mi_cmd_env_path (char *command, char **argv, int argc) { char *exec_path; char *env; int reset = 0; int optind = 0; int i; char *optarg; enum opt { RESET_OPT }; static struct mi_opt opts[] = { {"r", RESET_OPT, 0}, 0 }; dont_repeat (); if (mi_version (uiout) < 2) { for (i = argc - 1; i >= 0; --i) env_execute_cli_command ("path", argv[i]); return MI_CMD_DONE; } /* Otherwise the mi level is 2 or higher. */ while (1) { int opt = mi_getopt ("mi_cmd_env_path", argc, argv, opts, &optind, &optarg); if (opt < 0) break; switch ((enum opt) opt) { case RESET_OPT: reset = 1; break; } } argv += optind; argc -= optind; if (reset) { /* Reset implies resetting to original path first. */ exec_path = xstrdup (orig_path); } else { /* Otherwise, get current path to modify. */ env = get_in_environ (inferior_environ, path_var_name); /* Can be null if path is not set. */ if (!env) env = ""; exec_path = xstrdup (env); } for (i = argc - 1; i >= 0; --i) env_mod_path (argv[i], &exec_path); set_in_environ (inferior_environ, path_var_name, exec_path); xfree (exec_path); env = get_in_environ (inferior_environ, path_var_name); ui_out_field_string (uiout, "path", env); return MI_CMD_DONE; }