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]

[PATCH v1 03/36] Guile extension language: auto-load.c changes


This patch has auto-load.c additions and the new section-scripts.h header,
as well as the change to the py-section-script.c test to use it.

2013-12-24  Doug Evans  <xdje42@gmail.com>

	include/gdb/
	* section-scripts.h: New file.

	* auto-load.c: Remove #include "python/python.h".  Add #include
	"gdb/section-scripts.h".
	(source_section_scripts): Handle Guile scripts.
	(_initialize_auto_load): Add name of Guile objfile script to
	scripts-directory help text.

	testsuite/
	* gdb.python/py-section-script.c: #include "symcat.h",
	"gdb/section-scripts.h".
	(DEFINE_GDB_SCRIPT): Use SECTION_SCRIPT_ID_PYTHON_FILE instead of
	magic number.
	* gdb.python/py-section-script.exp: Pass -I${srcdir}/../../include
	to gcc.

diff --git a/include/gdb/section-scripts.h b/include/gdb/section-scripts.h
new file mode 100644
index 0000000..94419a0
--- /dev/null
+++ b/include/gdb/section-scripts.h
@@ -0,0 +1,50 @@
+/* Definition of kinds of records in section .debug_gdb_scripts.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_SECTION_SCRIPTS_H
+#define GDB_SECTION_SCRIPTS_H
+
+/* Each entry in section .debug_gdb_scripts begins with a byte that is used to
+   identify the entry.  This byte is to use as we choose.
+   0 is reserved so that it is never used (to catch errors).
+   It is recommended to avoid ASCII values 32-127 to help catch (most) cases
+   of forgetting to include this byte.
+   Other unused values needn't specify different scripting languages,
+   but we have no need for anything else at the moment.
+
+   Future extension: Include the contents of the script in the section.
+
+   These values are defined as macros so that they can be used in embedded
+   asms and assembler source files.  */
+
+/* Reserved.  */
+#define SECTION_SCRIPT_ID_NEVER_USE 0
+
+/* The record is a nul-terminated file name to load as a python file.  */
+#define SECTION_SCRIPT_ID_PYTHON_FILE 1
+
+/* Native GDB scripts are not currently supported in .debug_gdb_scripts,
+   but we reserve a value for it.  */
+/*#define SECTION_SCRIPT_ID_GDB_FILE 2*/
+
+/* The record is a nul-terminated file name to load as a guile(scheme)
+   file.  */
+#define SECTION_SCRIPT_ID_SCHEME_FILE 3
+
+#endif /* GDB_SECTION_SCRIPTS_H */
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 154fe40..4e9df98 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -40,7 +40,7 @@
 #include "top.h"
 #include "filestuff.h"
 #include "extension.h"
-#include "python/python.h"
+#include "gdb/section-scripts.h"
 
 /* The section to look in for auto-loaded scripts (in file formats that
    support sections).
@@ -878,18 +878,22 @@ source_section_scripts (struct objfile *objfile, const char *section_name,
       char *full_path;
       int opened, in_hash_table;
       struct cleanup *back_to;
-      /* At the moment we only support python scripts in .debug_gdb_scripts,
-	 but that can change.  */
-      const struct extension_language_defn *language
-	= &extension_language_python;
+      const struct extension_language_defn *language;
       objfile_script_sourcer_func *sourcer;
 
-      if (*p != 1)
+      switch (*p)
 	{
+	case SECTION_SCRIPT_ID_PYTHON_FILE:
+	  language = get_ext_lang_defn (EXT_LANG_PYTHON);
+	  break;
+	case SECTION_SCRIPT_ID_SCHEME_FILE:
+	  language = get_ext_lang_defn (EXT_LANG_GUILE);
+	  break;
+	default:
 	  warning (_("Invalid entry in %s section"), section_name);
 	  /* We could try various heuristics to find the next valid entry,
 	     but it's safer to just punt.  */
-	  break;
+	  return;
 	}
       file = ++p;
 
@@ -1396,6 +1400,8 @@ _initialize_auto_load (void)
 {
   struct cmd_list_element *cmd;
   char *scripts_directory_help, *gdb_name_help, *python_name_help;
+  char *guile_name_help;
+  const char *suffix;
 
   auto_load_pspace_data
     = register_program_space_data_with_cleanup (NULL,
@@ -1440,16 +1446,26 @@ Usage: info auto-load local-gdbinit"),
 
   auto_load_dir = xstrdup (AUTO_LOAD_DIR);
 
+  suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB));
   gdb_name_help
     = xstrprintf (_("\
 GDB scripts:    OBJFILE%s\n"),
-		  ext_lang_auto_load_suffix (&extension_language_gdb));
+		  suffix);
   python_name_help = NULL;
 #ifdef HAVE_PYTHON
+  suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_PYTHON));
   python_name_help
     = xstrprintf (_("\
 Python scripts: OBJFILE%s\n"),
-		  ext_lang_auto_load_suffix (&extension_language_python));
+		  suffix);
+#endif
+  guile_name_help = NULL;
+#ifdef HAVE_GUILE
+  suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GUILE));
+  guile_name_help
+    = xstrprintf (_("\
+Guile scripts:  OBJFILE%s\n"),
+		  suffix);
 #endif
   scripts_directory_help
     = xstrprintf (_("\
@@ -1457,7 +1473,7 @@ Automatically loaded scripts are located in one of the directories listed\n\
 by this option.\n\
 \n\
 Script names:\n\
-%s%s\
+%s%s%s\
 \n\
 This option is ignored for the kinds of scripts \
 having 'set auto-load ... off'.\n\
@@ -1465,7 +1481,8 @@ Directories listed here need to be present also \
 in the 'set auto-load safe-path'\n\
 option."),
 		  gdb_name_help,
-		  python_name_help ? python_name_help : "");
+		  python_name_help ? python_name_help : "",
+		  guile_name_help ? guile_name_help : "");
 
   add_setshow_optional_filename_cmd ("scripts-directory", class_support,
 				     &auto_load_dir, _("\
@@ -1478,6 +1495,7 @@ Show the list of directories from which to load auto-loaded scripts."),
   xfree (scripts_directory_help);
   xfree (python_name_help);
   xfree (gdb_name_help);
+  xfree (guile_name_help);
 
   auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
   auto_load_safe_path_vec_update ();
diff --git a/gdb/testsuite/gdb.python/py-section-script.c b/gdb/testsuite/gdb.python/py-section-script.c
index db1daea..e39deab 100644
--- a/gdb/testsuite/gdb.python/py-section-script.c
+++ b/gdb/testsuite/gdb.python/py-section-script.c
@@ -15,13 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "symcat.h"
+#include "gdb/section-scripts.h"
+
 /* Put the path to the pretty-printer script in .debug_gdb_scripts so
    gdb will automagically loaded it.  */
 
 #define DEFINE_GDB_SCRIPT(script_name) \
   asm("\
 .pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n\
-.byte 1\n\
+.byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_FILE) "\n\
 .asciz \"" script_name "\"\n\
 .popsection \n\
 ");
diff --git a/gdb/testsuite/gdb.python/py-section-script.exp b/gdb/testsuite/gdb.python/py-section-script.exp
index 66f1117..c17c2d8 100644
--- a/gdb/testsuite/gdb.python/py-section-script.exp
+++ b/gdb/testsuite/gdb.python/py-section-script.exp
@@ -39,7 +39,7 @@ set remote_python_file [gdb_remote_download host \
 set quoted_name "\"$remote_python_file\""
 
 if {[build_executable $testfile.exp $testfile $srcfile \
-	 [list debug additional_flags=-DSCRIPT_FILE=$quoted_name]] == -1} {
+	[list debug "additional_flags=-I${srcdir}/../../include -DSCRIPT_FILE=$quoted_name"]] == -1} {
     return -1
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]