This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch contains the changes to auto-load.c, auto-load.h, py-auto-load.c. struct script_language has been moved to extension-priv.h (and renamed to extension_language_defn). Variable script_language_python has been moved to python.c. Changes from v1: - updates for scripting -> extension renaming 2013-12-10 Doug Evans <xdje42@gmail.com> * auto-load.c: #include "extension.h". (GDB_AUTO_FILE_NAME): Delete. (auto_load_gdb_scripts_enabled): Make public. New arg extlang. (script_language_gdb): Delete, moved to extension.c and renamed to extension_language_gdb. (source_gdb_script_for_objfile): Delete. (auto_load_pspace_info): New member unsupported_script_warning_printed. (loaded_script): Change type of language member to struct extension_language_defn *. (init_loaded_scripts_info): Initialize unsupported_script_warning_printed. (maybe_add_script): Make static. Change type of language arg to struct extension_language_defn *. (clear_section_scripts): Reset unsupported_script_warning_printed. (auto_load_objfile_script_1): Rewrite to use extension language API. (auto_load_objfile_script): Make public. Remove support-compiled-in and auto-load-enabled checks, moved to auto_load_scripts_for_objfile. (source_section_scripts): Rewrite to use extension language API. (load_auto_scripts_for_objfile): Rewrite to use auto_load_scripts_for_objfile. (collect_matching_scripts_data): Change type of language member to struct extension_language_defn *. (auto_load_info_scripts): Change type of language arg to struct extension_language_defn *. (unsupported_script_warning_print): New function. (script_not_found_warning_print): Make static. (_initialize_auto_load): Rewrite construction of scripts-directory help. * auto-load.h (struct objfile): Add forward decl. (struct script_language): Delete. (struct auto_load_pspace_info): Add forward decl. (struct extension_language_defn): Add forward decl. (maybe_add_script): Delete. (auto_load_objfile_script): Declare. (script_not_found_warning_print): Delete. (auto_load_info_scripts): Update prototype. (auto_load_gdb_scripts_enabled): Declare. * python/py-auto-load.c (gdbpy_auto_load_enabled): Renamed from auto_load_python_scripts_enabled and made public. (script_language_python): Delete, moved to python.c. (gdbpy_script_language_defn): Delete. (info_auto_load_python_scripts): Update to use extension_language_python. diff --git a/gdb/auto-load.c b/gdb/auto-load.c index e516c6a..154fe40 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -20,7 +20,6 @@ #include "defs.h" #include "auto-load.h" #include "progspace.h" -#include "python/python.h" #include "gdb_regex.h" #include "ui-out.h" #include "filenames.h" @@ -40,6 +39,8 @@ #include "fnmatch.h" #include "top.h" #include "filestuff.h" +#include "extension.h" +#include "python/python.h" /* The section to look in for auto-loaded scripts (in file formats that support sections). @@ -49,12 +50,14 @@ followed by the path of a python script to load. */ #define AUTO_SECTION_NAME ".debug_gdb_scripts" -/* The suffix of per-objfile scripts to auto-load as non-Python command files. - E.g. When the program loads libfoo.so, look for libfoo-gdb.gdb. */ -#define GDB_AUTO_FILE_NAME "-gdb.gdb" +static int maybe_add_script (struct auto_load_pspace_info *pspace_info, + int loaded, const char *name, + const char *full_path, + const struct extension_language_defn *language); + +static int unsupported_script_warning_print (struct auto_load_pspace_info *); -static void source_gdb_script_for_objfile (struct objfile *objfile, FILE *file, - const char *filename); +static int script_not_found_warning_print (struct auto_load_pspace_info *); /* Value of the 'set debug auto-load' configuration variable. */ static int debug_auto_load = 0; @@ -90,8 +93,8 @@ show_auto_load_gdb_scripts (struct ui_file *file, int from_tty, /* Return non-zero if auto-loading gdb scripts is enabled. */ -static int -auto_load_gdb_scripts_enabled (void) +int +auto_load_gdb_scripts_enabled (const struct extension_language_defn *extlang) { return auto_load_gdb_scripts; } @@ -517,29 +520,6 @@ For more information about this security protection see the\n\ return 0; } -/* Definition of script language for GDB canned sequences of commands. */ - -static const struct script_language script_language_gdb = -{ - "gdb", - GDB_AUTO_FILE_NAME, - auto_load_gdb_scripts_enabled, - source_gdb_script_for_objfile -}; - -static void -source_gdb_script_for_objfile (struct objfile *objfile, FILE *file, - const char *filename) -{ - volatile struct gdb_exception e; - - TRY_CATCH (e, RETURN_MASK_ALL) - { - script_from_file (file, filename); - } - exception_print (gdb_stderr, e); -} - /* For scripts specified in .debug_gdb_scripts, multiple objfiles may load the same script. There's no point in loading the script multiple times, and there can be a lot of objfiles and scripts, so we keep track of scripts @@ -551,6 +531,10 @@ struct auto_load_pspace_info struct htab *loaded_scripts; /* Non-zero if we've issued the warning about an auto-load script not being + supported. We only want to issue this warning once. */ + int unsupported_script_warning_printed; + + /* Non-zero if we've issued the warning about an auto-load script not being found. We only want to issue this warning once. */ int script_not_found_warning_printed; }; @@ -569,7 +553,7 @@ struct loaded_script /* Non-zero if this script has been loaded. */ int loaded; - const struct script_language *language; + const struct extension_language_defn *language; }; /* Per-program-space data key. */ @@ -639,6 +623,7 @@ init_loaded_scripts_info (struct auto_load_pspace_info *pspace_info) eq_loaded_script_entry, xfree); + pspace_info->unsupported_script_warning_printed = FALSE; pspace_info->script_not_found_warning_printed = FALSE; } @@ -662,10 +647,10 @@ get_auto_load_pspace_data_for_loading (struct program_space *pspace) been found). FULL_PATH is NULL if the script wasn't found. The result is true if the script was already in the hash table. */ -int +static int maybe_add_script (struct auto_load_pspace_info *pspace_info, int loaded, const char *name, const char *full_path, - const struct script_language *language) + const struct extension_language_defn *language) { struct htab *htab = pspace_info->loaded_scripts; struct loaded_script **slot, entry; @@ -717,6 +702,7 @@ clear_section_scripts (void) { htab_delete (info->loaded_scripts); info->loaded_scripts = NULL; + info->unsupported_script_warning_printed = FALSE; info->script_not_found_warning_printed = FALSE; } } @@ -727,17 +713,18 @@ clear_section_scripts (void) static int auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, - const struct script_language *language) + const struct extension_language_defn *language) { char *filename, *debugfile; int len, retval; FILE *input; struct cleanup *cleanups; + const char *suffix = ext_lang_auto_load_suffix (language); len = strlen (realname); - filename = xmalloc (len + strlen (language->suffix) + 1); + filename = xmalloc (len + strlen (suffix) + 1); memcpy (filename, realname, len); - strcpy (filename + len, language->suffix); + strcpy (filename + len, suffix); cleanups = make_cleanup (xfree, filename); @@ -795,8 +782,8 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, = file_is_auto_load_safe (filename, _("auto-load: Loading %s script \"%s\"" " by extension for objfile \"%s\".\n"), - language->name, filename, - objfile_name (objfile)); + ext_lang_name (language), + filename, objfile_name (objfile)); /* Add this script to the hash table too so "info auto-load ${lang}-scripts" can print it. */ @@ -810,7 +797,16 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, and these scripts are required to be idempotent under multiple loads anyway. */ if (is_safe) - language->source_script_for_objfile (objfile, input, debugfile); + { + objfile_script_sourcer_func *sourcer + = ext_lang_objfile_script_sourcer (language); + + /* We shouldn't get here if support for the language isn't + compiled in. And the extension language is required to implement + this function. */ + gdb_assert (sourcer != NULL); + sourcer (language, objfile, input, debugfile); + } retval = 1; } @@ -824,21 +820,12 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load it. */ -static void +void auto_load_objfile_script (struct objfile *objfile, - const struct script_language *language) + const struct extension_language_defn *language) { - char *realname; - struct cleanup *cleanups; - - /* Skip this script if support has not been compiled in or - auto-loading it has been disabled. */ - if (language == NULL - || !language->auto_load_enabled ()) - return; - - realname = gdb_realpath (objfile_name (objfile)); - cleanups = make_cleanup (xfree, realname); + char *realname = gdb_realpath (objfile_name (objfile)); + struct cleanup *cleanups = make_cleanup (xfree, realname); if (!auto_load_objfile_script_1 (objfile, realname, language)) { @@ -893,7 +880,9 @@ source_section_scripts (struct objfile *objfile, const char *section_name, struct cleanup *back_to; /* At the moment we only support python scripts in .debug_gdb_scripts, but that can change. */ - const struct script_language *language = gdbpy_script_language_defn (); + const struct extension_language_defn *language + = &extension_language_python; + objfile_script_sourcer_func *sourcer; if (*p != 1) { @@ -923,10 +912,34 @@ source_section_scripts (struct objfile *objfile, const char *section_name, continue; } - /* Skip this script if support has not been compiled in or - auto-loading it has been disabled. */ - if (language == NULL - || !language->auto_load_enabled ()) + /* Until we support more types of records in .debug_gdb_scripts we do + all the processing here. The expectation is to add a new + extension_language_script_ops "method" that handles all the records + for the language. For now we can just use + extension_language_script_ops.objfile_script_sourcer. */ + + /* Skip this script if support is not compiled in. */ + sourcer = ext_lang_objfile_script_sourcer (language); + if (sourcer == NULL) + { + /* We don't throw an error, the program is still debuggable. */ + if (!unsupported_script_warning_print (pspace_info)) + { + warning (_("Unsupported auto-load scripts referenced in" + " %s section\n" + "of file %s.\n" + "Use `info auto-load %s-scripts [REGEXP]'" + " to list them."), + section_name, objfile_name (objfile), + ext_lang_name (language)); + } + /* We *could* still try to open it, but there's no point. */ + maybe_add_script (pspace_info, 0, file, NULL, language); + continue; + } + + /* Skip this script if auto-loading it has been disabled. */ + if (!ext_lang_auto_load_enabled (language)) { /* No message is printed, just skip it. */ continue; @@ -945,8 +958,8 @@ source_section_scripts (struct objfile *objfile, const char *section_name, _("auto-load: Loading %s script " "\"%s\" from section \"%s\" of " "objfile \"%s\".\n"), - language->name, full_path, section_name, - objfile_name (objfile))) + ext_lang_name (language), full_path, + section_name, objfile_name (objfile))) opened = 0; } else @@ -965,7 +978,8 @@ source_section_scripts (struct objfile *objfile, const char *section_name, warning (_("Missing auto-load scripts referenced in section %s\n\ of file %s\n\ Use `info auto-load %s-scripts [REGEXP]' to list them."), - section_name, objfile_name (objfile), language->name); + section_name, objfile_name (objfile), + ext_lang_name (language)); } in_hash_table = maybe_add_script (pspace_info, opened, file, full_path, @@ -973,10 +987,7 @@ Use `info auto-load %s-scripts [REGEXP]' to list them."), /* If this file is not currently loaded, load it. */ if (opened && !in_hash_table) - { - gdb_assert (language->source_script_for_objfile != NULL); - language->source_script_for_objfile (objfile, stream, full_path); - } + sourcer (language, objfile, stream, full_path); do_cleanups (back_to); } @@ -1021,9 +1032,9 @@ load_auto_scripts_for_objfile (struct objfile *objfile) if (!global_auto_load || (objfile->flags & OBJF_NOT_FILENAME) != 0) return; - /* Load any scripts for this objfile. e.g. foo-gdb.gdb, foo-gdb.py. */ - auto_load_objfile_script (objfile, &script_language_gdb); - auto_load_objfile_script (objfile, gdbpy_script_language_defn ()); + /* Load any extension language scripts for this objfile. + E.g., foo-gdb.gdb, foo-gdb.py. */ + auto_load_ext_lang_scripts_for_objfile (objfile); /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts). */ auto_load_section_scripts (objfile, AUTO_SECTION_NAME); @@ -1057,7 +1068,7 @@ struct collect_matching_scripts_data { VEC (loaded_script_ptr) **scripts_p; - const struct script_language *language; + const struct extension_language_defn *language; }; /* Traversal function for htab_traverse. @@ -1123,7 +1134,7 @@ char auto_load_info_scripts_pattern_nl[] = ""; void auto_load_info_scripts (char *pattern, int from_tty, - const struct script_language *language) + const struct extension_language_defn *language) { struct ui_out *uiout = current_uiout; struct auto_load_pspace_info *pspace_info; @@ -1206,7 +1217,7 @@ auto_load_info_scripts (char *pattern, int from_tty, static void info_auto_load_gdb_scripts (char *pattern, int from_tty) { - auto_load_info_scripts (pattern, from_tty, &script_language_gdb); + auto_load_info_scripts (pattern, from_tty, &extension_language_gdb); } /* Implement 'info auto-load local-gdbinit'. */ @@ -1224,11 +1235,25 @@ info_auto_load_local_gdbinit (char *args, int from_tty) auto_load_local_gdbinit_pathname); } +/* Return non-zero if UNSUPPORTED_SCRIPT_WARNING_PRINTED of PSPACE_INFO was + unset before calling this function. Always set + UNSUPPORTED_SCRIPT_WARNING_PRINTED of PSPACE_INFO. */ + +static int +unsupported_script_warning_print (struct auto_load_pspace_info *pspace_info) +{ + int retval = !pspace_info->unsupported_script_warning_printed; + + pspace_info->unsupported_script_warning_printed = 1; + + return retval; +} + /* Return non-zero if SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO was unset before calling this function. Always set SCRIPT_NOT_FOUND_WARNING_PRINTED of PSPACE_INFO. */ -int +static int script_not_found_warning_print (struct auto_load_pspace_info *pspace_info) { int retval = !pspace_info->script_not_found_warning_printed; @@ -1370,7 +1395,7 @@ void _initialize_auto_load (void) { struct cmd_list_element *cmd; - char *scripts_directory_help; + char *scripts_directory_help, *gdb_name_help, *python_name_help; auto_load_pspace_data = register_program_space_data_with_cleanup (NULL, @@ -1414,27 +1439,34 @@ Usage: info auto-load local-gdbinit"), auto_load_info_cmdlist_get ()); auto_load_dir = xstrdup (AUTO_LOAD_DIR); - scripts_directory_help = xstrprintf ( + + gdb_name_help + = xstrprintf (_("\ +GDB scripts: OBJFILE%s\n"), + ext_lang_auto_load_suffix (&extension_language_gdb)); + python_name_help = NULL; #ifdef HAVE_PYTHON - _("\ -Automatically loaded Python scripts (named OBJFILE%s) and GDB scripts\n\ -(named OBJFILE%s) are located in one of the directories listed by this\n\ -option.\n\ -%s"), - GDBPY_AUTO_FILE_NAME, -#else - _("\ -Automatically loaded GDB scripts (named OBJFILE%s) are located in one\n\ -of the directories listed by this option.\n\ -%s"), + python_name_help + = xstrprintf (_("\ +Python scripts: OBJFILE%s\n"), + ext_lang_auto_load_suffix (&extension_language_python)); #endif - GDB_AUTO_FILE_NAME, - _("\ + scripts_directory_help + = xstrprintf (_("\ +Automatically loaded scripts are located in one of the directories listed\n\ +by this option.\n\ +\n\ +Script names:\n\ +%s%s\ +\n\ This option is ignored for the kinds of scripts \ having 'set auto-load ... off'.\n\ Directories listed here need to be present also \ in the 'set auto-load safe-path'\n\ -option.")); +option."), + gdb_name_help, + python_name_help ? python_name_help : ""); + add_setshow_optional_filename_cmd ("scripts-directory", class_support, &auto_load_dir, _("\ Set the list of directories from which to load auto-loaded scripts."), _("\ @@ -1444,6 +1476,8 @@ Show the list of directories from which to load auto-loaded scripts."), auto_load_set_cmdlist_get (), auto_load_show_cmdlist_get ()); xfree (scripts_directory_help); + xfree (python_name_help); + xfree (gdb_name_help); auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH); auto_load_safe_path_vec_update (); diff --git a/gdb/auto-load.h b/gdb/auto-load.h index 2ddebc5..9b0395a 100644 --- a/gdb/auto-load.h +++ b/gdb/auto-load.h @@ -20,25 +20,10 @@ #ifndef AUTO_LOAD_H #define AUTO_LOAD_H 1 +struct objfile; struct program_space; - -struct script_language -{ - /* The name of the language, lowercase. */ - const char *name; - - /* The suffix added to objfiles to get their auto-load script. - E.g., "-gdb.py". */ - const char *suffix; - - /* Returns non-zero if auto-loading scripts in this language is enabled. */ - int (*auto_load_enabled) (void); - - /* Worker routine to load the script. It has already been opened and - deemed safe to load. */ - void (*source_script_for_objfile) (struct objfile *objfile, FILE *file, - const char *filename); -}; +struct auto_load_pspace_info; +struct extension_language_defn; extern int global_auto_load; @@ -48,16 +33,12 @@ extern int auto_load_local_gdbinit_loaded; extern struct auto_load_pspace_info * get_auto_load_pspace_data_for_loading (struct program_space *pspace); -extern int maybe_add_script (struct auto_load_pspace_info *pspace_info, - int loaded, const char *name, - const char *full_path, - const struct script_language *language); +extern void auto_load_objfile_script (struct objfile *objfile, + const struct extension_language_defn *); extern void load_auto_scripts_for_objfile (struct objfile *objfile); -extern int - script_not_found_warning_print (struct auto_load_pspace_info *pspace_info); extern char auto_load_info_scripts_pattern_nl[]; extern void auto_load_info_scripts (char *pattern, int from_tty, - const struct script_language *language); + const struct extension_language_defn *); extern struct cmd_list_element **auto_load_set_cmdlist_get (void); extern struct cmd_list_element **auto_load_show_cmdlist_get (void); @@ -66,4 +47,7 @@ extern struct cmd_list_element **auto_load_info_cmdlist_get (void); extern int file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...); +extern int auto_load_gdb_scripts_enabled + (const struct extension_language_defn *extlang); + #endif /* AUTO_LOAD_H */ diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c index d5450b3..82325c6 100644 --- a/gdb/python/py-auto-load.c +++ b/gdb/python/py-auto-load.c @@ -25,9 +25,6 @@ #include "objfiles.h" #include "python.h" #include "auto-load.h" - -#ifdef HAVE_PYTHON - #include "python-internal.h" /* User-settable option to enable/disable auto-loading of Python scripts: @@ -45,38 +42,21 @@ show_auto_load_python_scripts (struct ui_file *file, int from_tty, fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value); } -/* Return non-zero if auto-loading Python scripts is enabled. */ +/* Return non-zero if auto-loading Python scripts is enabled. + This is the extension_language_script_ops.auto_load_enabled "method". */ -static int -auto_load_python_scripts_enabled (void) +int +gdbpy_auto_load_enabled (const struct extension_language_defn *extlang) { return auto_load_python_scripts; } -/* Definition of script language for Python scripts. */ - -static const struct script_language script_language_python = -{ - "python", - GDBPY_AUTO_FILE_NAME, - auto_load_python_scripts_enabled, - source_python_script_for_objfile -}; - -/* Return the Python script language definition. */ - -const struct script_language * -gdbpy_script_language_defn (void) -{ - return &script_language_python; -} - /* Wrapper for "info auto-load python-scripts". */ static void info_auto_load_python_scripts (char *pattern, int from_tty) { - auto_load_info_scripts (pattern, from_tty, &script_language_python); + auto_load_info_scripts (pattern, from_tty, &extension_language_python); } int @@ -125,16 +105,3 @@ Print the list of automatically loaded Python scripts, deprecated.")); return 0; } - -#else /* ! HAVE_PYTHON */ - -/* Return the Python script language definition. - Since support isn't compiled in, return NULL. */ - -const struct script_language * -gdbpy_script_language_defn (void) -{ - return NULL; -} - -#endif /* ! HAVE_PYTHON */
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |