This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit 1/2] Move processing of .debug_gdb_scripts to auto-load.c
- From: Doug Evans <dje at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 29 Nov 2013 21:44:09 -0800
- Subject: [commit 1/2] Move processing of .debug_gdb_scripts to auto-load.c
- Authentication-results: sourceware.org; auth=none
Hi.
This is the first of two patches that does two cleanups:
---
1) Move processing of .debug_gdb_scripts to auto-load.c.
.debug_gdb_scripts is intended to handle more than just python scripts,
e.g., gdb scripts, so a better place for the code to process it is
auto-load.c. This patch set moves the support there from py-auto-load.c.
2) Simplify handling of ${objfile}-${suffix} scripts.
[e.g. foo-gdb.gdb, libfoo-gdb.py]
There's no need for the gdb version and the python version to both
perform the administrivia of is-this-safe-to-load checking, and
recording the script with maybe_add_script.
The second patch in this series simplifies them by moving the support
to the caller.
---
What this patch does is just move some things from py-auto-load.c
to auto-load.c, and makes minimal other changes.
The second patch then finishes things up.
2013-11-29 Doug Evans <xdje42@gmail.com>
* auto-load.c (AUTO_SECTION_NAME): Moved here and renamed from
py-auto-load.c, GDBPY_AUTO_SECTION_NAME.
(source_section_scripts): Moved here from py-auto-load.c.
(auto_load_section_scripts): Ditto.
* python/py-auto-load.c (GDBPY_AUTO_SECTION_NAME): Moved to
auto-load.c, renamed AUTO_SECTION_NAME.
(source_section_scripts, auto_load_section_scripts): Moved to
auto-load.c.
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 2c534c7..2a74e90 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -40,6 +40,14 @@
#include "top.h"
#include "filestuff.h"
+/* The section to look in for auto-loaded scripts (in file formats that
+ support sections).
+ Each entry in this section is a record that begins with a leading byte
+ identifying the record type.
+ At the moment we only support one record type: A leading byte of 1,
+ 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"
@@ -831,6 +839,138 @@ auto_load_objfile_script (struct objfile *objfile,
do_cleanups (cleanups);
}
+/* Load scripts specified in OBJFILE.
+ START,END delimit a buffer containing a list of nul-terminated
+ file names.
+ SOURCE_NAME is used in error messages.
+
+ Scripts are found per normal "source -s" command processing.
+ First the script is looked for in $cwd. If not found there the
+ source search path is used.
+
+ The section contains a list of path names of files containing
+ python code to load. Each path is null-terminated. */
+
+static void
+source_section_scripts (struct objfile *objfile, const char *source_name,
+ const char *start, const char *end)
+{
+ const char *p;
+ struct auto_load_pspace_info *pspace_info;
+
+ pspace_info = get_auto_load_pspace_data_for_loading (current_program_space);
+
+ for (p = start; p < end; ++p)
+ {
+ const char *file;
+ FILE *stream;
+ char *full_path;
+ int opened, in_hash_table;
+ struct cleanup *back_to;
+
+ if (*p != 1)
+ {
+ warning (_("Invalid entry in %s section"), AUTO_SECTION_NAME);
+ /* We could try various heuristics to find the next valid entry,
+ but it's safer to just punt. */
+ break;
+ }
+ file = ++p;
+
+ while (p < end && *p != '\0')
+ ++p;
+ if (p == end)
+ {
+ char *buf = alloca (p - file + 1);
+
+ memcpy (buf, file, p - file);
+ buf[p - file] = '\0';
+ warning (_("Non-null-terminated path in %s: %s"),
+ source_name, buf);
+ /* Don't load it. */
+ break;
+ }
+ if (p == file)
+ {
+ warning (_("Empty path in %s"), source_name);
+ continue;
+ }
+
+ opened = find_and_open_script (file, 1 /*search_path*/,
+ &stream, &full_path);
+
+ back_to = make_cleanup (null_cleanup, NULL);
+ if (opened)
+ {
+ make_cleanup_fclose (stream);
+ make_cleanup (xfree, full_path);
+
+ if (!file_is_auto_load_safe (full_path,
+ _("auto-load: Loading Python script "
+ "\"%s\" from section \"%s\" of "
+ "objfile \"%s\".\n"),
+ full_path, AUTO_SECTION_NAME,
+ objfile_name (objfile)))
+ opened = 0;
+ }
+ else
+ {
+ full_path = NULL;
+
+ /* If one script isn't found it's not uncommon for more to not be
+ found either. We don't want to print a message for each script,
+ too much noise. Instead, we print the warning once and tell the
+ user how to find the list of scripts that weren't loaded.
+ We don't throw an error, the program is still debuggable.
+
+ IWBN if complaints.c were more general-purpose. */
+
+ if (script_not_found_warning_print (pspace_info))
+ warning (_("Missing auto-load scripts referenced in section %s\n\
+of file %s\n\
+Use `info auto-load python [REGEXP]' to list them."),
+ AUTO_SECTION_NAME, objfile_name (objfile));
+ }
+
+ in_hash_table = maybe_add_script (pspace_info, opened, file, full_path,
+ &script_language_python);
+
+ /* If this file is not currently loaded, load it. */
+ if (opened && !in_hash_table)
+ source_python_script_for_objfile (objfile, stream, full_path);
+
+ do_cleanups (back_to);
+ }
+}
+
+/* Load scripts specified in section SECTION_NAME of OBJFILE. */
+
+static void
+auto_load_section_scripts (struct objfile *objfile, const char *section_name)
+{
+ bfd *abfd = objfile->obfd;
+ asection *scripts_sect;
+ bfd_byte *data = NULL;
+
+ scripts_sect = bfd_get_section_by_name (abfd, section_name);
+ if (scripts_sect == NULL)
+ return;
+
+ if (!bfd_get_full_section_contents (abfd, scripts_sect, &data))
+ warning (_("Couldn't read %s section of %s"),
+ section_name, bfd_get_filename (abfd));
+ else
+ {
+ struct cleanup *cleanups;
+ char *p = (char *) data;
+
+ cleanups = make_cleanup (xfree, p);
+ source_section_scripts (objfile, section_name, p,
+ p + bfd_get_section_size (scripts_sect));
+ do_cleanups (cleanups);
+ }
+}
+
/* Load any auto-loaded scripts for OBJFILE. */
void
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index 827918a..0d498f8 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -31,13 +31,6 @@
#include "python-internal.h"
-/* The section to look for Python auto-loaded scripts (in file formats that
- support sections).
- Each entry in this section is a byte of value 1, and then the nul-terminated
- name of the script. The script name may include a directory.
- The leading byte is to allow upward compatible extensions. */
-#define GDBPY_AUTO_SECTION_NAME ".debug_gdb_scripts"
-
/* User-settable option to enable/disable auto-loading of Python scripts:
set auto-load python-scripts on|off
This is true if we should auto-load associated Python scripts when an
@@ -86,138 +79,6 @@ gdbpy_load_auto_script_for_objfile (struct objfile *objfile, FILE *file,
source_python_script_for_objfile (objfile, file, filename);
}
-/* Load scripts specified in OBJFILE.
- START,END delimit a buffer containing a list of nul-terminated
- file names.
- SOURCE_NAME is used in error messages.
-
- Scripts are found per normal "source -s" command processing.
- First the script is looked for in $cwd. If not found there the
- source search path is used.
-
- The section contains a list of path names of files containing
- python code to load. Each path is null-terminated. */
-
-static void
-source_section_scripts (struct objfile *objfile, const char *source_name,
- const char *start, const char *end)
-{
- const char *p;
- struct auto_load_pspace_info *pspace_info;
-
- pspace_info = get_auto_load_pspace_data_for_loading (current_program_space);
-
- for (p = start; p < end; ++p)
- {
- const char *file;
- FILE *stream;
- char *full_path;
- int opened, in_hash_table;
- struct cleanup *back_to;
-
- if (*p != 1)
- {
- warning (_("Invalid entry in %s section"), GDBPY_AUTO_SECTION_NAME);
- /* We could try various heuristics to find the next valid entry,
- but it's safer to just punt. */
- break;
- }
- file = ++p;
-
- while (p < end && *p != '\0')
- ++p;
- if (p == end)
- {
- char *buf = alloca (p - file + 1);
-
- memcpy (buf, file, p - file);
- buf[p - file] = '\0';
- warning (_("Non-null-terminated path in %s: %s"),
- source_name, buf);
- /* Don't load it. */
- break;
- }
- if (p == file)
- {
- warning (_("Empty path in %s"), source_name);
- continue;
- }
-
- opened = find_and_open_script (file, 1 /*search_path*/,
- &stream, &full_path);
-
- back_to = make_cleanup (null_cleanup, NULL);
- if (opened)
- {
- make_cleanup_fclose (stream);
- make_cleanup (xfree, full_path);
-
- if (!file_is_auto_load_safe (full_path,
- _("auto-load: Loading Python script "
- "\"%s\" from section \"%s\" of "
- "objfile \"%s\".\n"),
- full_path, GDBPY_AUTO_SECTION_NAME,
- objfile_name (objfile)))
- opened = 0;
- }
- else
- {
- full_path = NULL;
-
- /* If one script isn't found it's not uncommon for more to not be
- found either. We don't want to print a message for each script,
- too much noise. Instead, we print the warning once and tell the
- user how to find the list of scripts that weren't loaded.
- We don't throw an error, the program is still debuggable.
-
- IWBN if complaints.c were more general-purpose. */
-
- if (script_not_found_warning_print (pspace_info))
- warning (_("Missing auto-load scripts referenced in section %s\n\
-of file %s\n\
-Use `info auto-load python [REGEXP]' to list them."),
- GDBPY_AUTO_SECTION_NAME, objfile_name (objfile));
- }
-
- in_hash_table = maybe_add_script (pspace_info, opened, file, full_path,
- &script_language_python);
-
- /* If this file is not currently loaded, load it. */
- if (opened && !in_hash_table)
- source_python_script_for_objfile (objfile, stream, full_path);
-
- do_cleanups (back_to);
- }
-}
-
-/* Load scripts specified in section SECTION_NAME of OBJFILE. */
-
-static void
-auto_load_section_scripts (struct objfile *objfile, const char *section_name)
-{
- bfd *abfd = objfile->obfd;
- asection *scripts_sect;
- bfd_byte *data = NULL;
-
- scripts_sect = bfd_get_section_by_name (abfd, section_name);
- if (scripts_sect == NULL)
- return;
-
- if (!bfd_get_full_section_contents (abfd, scripts_sect, &data))
- warning (_("Couldn't read %s section of %s"),
- section_name, bfd_get_filename (abfd));
- else
- {
- struct cleanup *cleanups;
- char *p = (char *) data;
-
- cleanups = make_cleanup (xfree, p);
- source_section_scripts (objfile, section_name, p,
- p + bfd_get_section_size (scripts_sect));
- do_cleanups (cleanups);
- }
-}
-
/* Load any Python auto-loaded scripts for OBJFILE. */
void