public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Support installing local source-highlight data directory
@ 2020-06-02  6:53 Stephanos Ioannidis
  2020-06-02  6:53 ` [PATCH 1/2] gdb: Install " Stephanos Ioannidis
  2020-06-02  6:53 ` [PATCH 2/2] gdb: Resolve " Stephanos Ioannidis
  0 siblings, 2 replies; 3+ messages in thread
From: Stephanos Ioannidis @ 2020-06-02  6:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Stephanos Ioannidis

The source-highlight data directory, which contains the input language and
output format definition files, is required for the source code syntax
highlighting feature to work properly.

This series includes the patches necessary to install the source-highlight
data directory under the gdb data directory and use it to perform source code
syntax highlighting even when the source-highlight library is not installed
and configured on the host system.

Stephanos Ioannidis (2):
  gdb: Install local source-highlight data directory
  gdb: Resolve local source-highlight data directory

 gdb/configure                  | 21 ++++++++++
 gdb/configure.ac               |  7 ++++
 gdb/data-directory/Makefile.in | 72 +++++++++++++++++++++++++++++++---
 gdb/source-cache.c             | 16 ++++++++
 4 files changed, 111 insertions(+), 5 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] gdb: Install local source-highlight data directory
  2020-06-02  6:53 [PATCH 0/2] Support installing local source-highlight data directory Stephanos Ioannidis
@ 2020-06-02  6:53 ` Stephanos Ioannidis
  2020-06-02  6:53 ` [PATCH 2/2] gdb: Resolve " Stephanos Ioannidis
  1 sibling, 0 replies; 3+ messages in thread
From: Stephanos Ioannidis @ 2020-06-02  6:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Stephanos Ioannidis

The source-highlight data directory, which contains the input language
and output format definition files, is required for source code syntax
highlighting feature to work properly.

This patch adds the installation targets necessary to copy the required
files under the automatically detected source-highlight data directory
to the gdb data directory.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
---
 gdb/configure                  | 21 ++++++++++
 gdb/configure.ac               |  7 ++++
 gdb/data-directory/Makefile.in | 72 +++++++++++++++++++++++++++++++---
 3 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index f659a4772b..5d6f48edcf 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -711,8 +711,11 @@ ALLOCA
 LTLIBIPT
 LIBIPT
 HAVE_LIBIPT
+HAVE_SOURCE_HIGHLIGHT_FALSE
+HAVE_SOURCE_HIGHLIGHT_TRUE
 SRCHIGH_CFLAGS
 SRCHIGH_LIBS
+SRCHIGH_PREFIX
 HAVE_GUILE_FALSE
 HAVE_GUILE_TRUE
 GUILE_LIBS
@@ -11319,6 +11322,7 @@ fi
 # Check for source highlight.  #
 # ---------------------------- #
 
+SRCHIGH_PREFIX=
 SRCHIGH_LIBS=
 SRCHIGH_CFLAGS=
 
@@ -11334,6 +11338,8 @@ else
 fi
 
 
+have_libsource_highlight=no
+
 if test "${enable_source_highlight}" != "no"; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the source-highlight library" >&5
 $as_echo_n "checking for the source-highlight library... " >&6; }
@@ -11345,8 +11351,10 @@ $as_echo "no - pkg-config not found" >&6; }
     fi
   else
     if ${pkg_config_prog_path} --exists source-highlight; then
+      SRCHIGH_PREFIX=`${pkg_config_prog_path} --variable=prefix source-highlight`
       SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight`
       SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight`
+      have_libsource_highlight=yes
 
 $as_echo "#define HAVE_SOURCE_HIGHLIGHT 1" >>confdefs.h
 
@@ -11364,6 +11372,15 @@ fi
 
 
 
+ if test "${have_libsource_highlight}" != no; then
+  HAVE_SOURCE_HIGHLIGHT_TRUE=
+  HAVE_SOURCE_HIGHLIGHT_FALSE='#'
+else
+  HAVE_SOURCE_HIGHLIGHT_TRUE='#'
+  HAVE_SOURCE_HIGHLIGHT_FALSE=
+fi
+
+
 
 # Check whether --with-intel_pt was given.
 if test "${with_intel_pt+set}" = set; then :
@@ -19122,6 +19139,10 @@ if test -z "${HAVE_GUILE_TRUE}" && test -z "${HAVE_GUILE_FALSE}"; then
   as_fn_error $? "conditional \"HAVE_GUILE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${HAVE_SOURCE_HIGHLIGHT_TRUE}" && test -z "${HAVE_SOURCE_HIGHLIGHT_FALSE}"; then
+  as_fn_error $? "conditional \"HAVE_SOURCE_HIGHLIGHT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 
 : "${CONFIG_STATUS=./config.status}"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 6d5526a516..589c725370 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1158,6 +1158,7 @@ AM_CONDITIONAL(HAVE_GUILE, test "${have_libguile}" != no)
 # Check for source highlight.  #
 # ---------------------------- #
 
+SRCHIGH_PREFIX=
 SRCHIGH_LIBS=
 SRCHIGH_CFLAGS=
 
@@ -1171,6 +1172,8 @@ AC_ARG_ENABLE(source-highlight,
 esac],
 [enable_source_highlight=auto])
 
+have_libsource_highlight=no
+
 if test "${enable_source_highlight}" != "no"; then
   AC_MSG_CHECKING([for the source-highlight library])
   if test "${pkg_config_prog_path}" = "missing"; then
@@ -1180,8 +1183,10 @@ if test "${enable_source_highlight}" != "no"; then
     fi
   else
     if ${pkg_config_prog_path} --exists source-highlight; then
+      SRCHIGH_PREFIX=`${pkg_config_prog_path} --variable=prefix source-highlight`
       SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight`
       SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight`
+      have_libsource_highlight=yes
       AC_DEFINE([HAVE_SOURCE_HIGHLIGHT], 1,
                 [Define to 1 if the source-highlight library is available])
       AC_MSG_RESULT([yes])
@@ -1193,8 +1198,10 @@ if test "${enable_source_highlight}" != "no"; then
     fi
   fi
 fi
+AC_SUBST(SRCHIGH_PREFIX)
 AC_SUBST(SRCHIGH_LIBS)
 AC_SUBST(SRCHIGH_CFLAGS)
+AM_CONDITIONAL(HAVE_SOURCE_HIGHLIGHT, test "${have_libsource_highlight}" != no)
 
 AC_ARG_WITH(intel_pt,
   AS_HELP_STRING([--with-intel-pt], [include Intel Processor Trace support (auto/yes/no)]),
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 68b794a353..0dd0625af3 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -23,8 +23,9 @@ srcdir = @srcdir@
 SYSCALLS_SRCDIR = $(srcdir)/../syscalls
 PYTHON_SRCDIR = $(srcdir)/../python/lib
 GUILE_SRCDIR = $(srcdir)/../guile/lib
+SOURCE_HIGHLIGHT_SRCDIR = @SRCHIGH_PREFIX@/share/source-highlight
 SYSTEM_GDBINIT_SRCDIR = $(srcdir)/../system-gdbinit
-VPATH = $(srcdir):$(SYSCALLS_SRCDIR):$(PYTHON_SRCDIR):$(GUILE_SRCDIR):$(SYSTEM_GDBINIT_SRCDIR)
+VPATH = $(srcdir):$(SYSCALLS_SRCDIR):$(PYTHON_SRCDIR):$(GUILE_SRCDIR):$(SOURCE_HIGHLIGHT_SRCDIR):$(SYSTEM_GDBINIT_SRCDIR)
 XSLTPROC = @XSLTPROC@
 
 top_srcdir = @top_srcdir@
@@ -133,6 +134,24 @@ GUILD_COMPILE_FLAGS = \
 	-Warity-mismatch -Wformat -Wunused-toplevel \
 	-L .
 
+SOURCE_HIGHLIGHT_DIR = source-highlight
+SOURCE_HIGHLIGHT_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(SOURCE_HIGHLIGHT_DIR)
+
+SOURCE_HIGHLIGHT_FILE_LIST = \
+	lang.map \
+	outlang.map \
+	style.defaults \
+	*.lang \
+	*.outlang \
+	*.style
+
+SOURCE_HIGHLIGHT_FILE_LIST_EXPANDED = \
+	$(patsubst $(SOURCE_HIGHLIGHT_SRCDIR)/%,%,$(wildcard $(addprefix \
+	$(SOURCE_HIGHLIGHT_SRCDIR)/,$(SOURCE_HIGHLIGHT_FILE_LIST))))
+
+@HAVE_SOURCE_HIGHLIGHT_TRUE@SOURCE_HIGHLIGHT_FILES = $(SOURCE_HIGHLIGHT_FILE_LIST_EXPANDED)
+@HAVE_SOURCE_HIGHLIGHT_FALSE@SOURCE_HIGHLIGHT_FILES =
+
 SYSTEM_GDBINIT_DIR = system-gdbinit
 SYSTEM_GDBINIT_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(SYSTEM_GDBINIT_DIR)
 SYSTEM_GDBINIT_FILES = \
@@ -172,7 +191,8 @@ FLAGS_TO_PASS = \
 	"RUNTESTFLAGS=$(RUNTESTFLAGS)"
 
 .PHONY: all
-all: stamp-syscalls stamp-python stamp-guile stamp-system-gdbinit
+all: stamp-syscalls stamp-python stamp-guile stamp-source-highlight \
+	stamp-system-gdbinit
 
 %.xml: @MAINTAINER_MODE_TRUE@ %.xml.in apply-defaults.xsl linux-defaults.xml.in
 	$(XSLTPROC) -o $(SYSCALLS_SRCDIR)/$@ $(SYSCALLS_SRCDIR)/apply-defaults.xsl\
@@ -327,6 +347,47 @@ uninstall-guile:
 	  done ; \
 	fi
 
+stamp-source-highlight: Makefile $(SOURCE_HIGHLIGHT_FILES)
+	rm -rf ./$(SOURCE_HIGHLIGHT_DIR)
+	mkdir ./$(SOURCE_HIGHLIGHT_DIR)
+	files='$(SOURCE_HIGHLIGHT_FILES)' ; \
+	for file in $$files ; do \
+	  f=$(SOURCE_HIGHLIGHT_SRCDIR)/$$file ; \
+	  if test -f $$f ; then \
+	    $(INSTALL_DATA) $$f ./$(SOURCE_HIGHLIGHT_DIR) ; \
+	  fi ; \
+	done
+	touch $@
+
+.PHONY: clean-source-highlight
+clean-source-highlight:
+	rm -rf $(SOURCE_HIGHLIGHT_DIR)
+	rm -f stamp-source-highlight
+
+.PHONY: install-source-highlight
+install-source-highlight:
+	$(INSTALL_DIR) $(SOURCE_HIGHLIGHT_INSTALL_DIR)
+	files='$(SOURCE_HIGHLIGHT_FILES)' ; \
+	for file in $$files; do \
+	  f=$(SOURCE_HIGHLIGHT_SRCDIR)/$$file ; \
+	  if test -f $$f ; then \
+	    $(INSTALL_DATA) $$f $(SOURCE_HIGHLIGHT_INSTALL_DIR) ; \
+	  fi ; \
+	done
+
+.PHONY: uninstall-source-highlight
+uninstall-source-highlight:
+	files='$(SOURCE_HIGHLIGHT_FILES)' ; \
+	for file in $$files ; do \
+	  slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'` ; \
+	  rm -f $(SOURCE_HIGHLIGHT_INSTALL_DIR)/$$file ; \
+	  while test "x$$file" != "x$$slashdir" ; do \
+	    rmdir 2>/dev/null "$(SOURCE_HIGHLIGHT_INSTALL_DIR)$$slashdir" ; \
+	    file="$$slashdir" ; \
+	    slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'` ; \
+	  done \
+	done
+
 stamp-system-gdbinit: Makefile $(SYSTEM_GDBINIT_FILES)
 	rm -rf ./$(SYSTEM_GDBINIT_DIR)
 	mkdir ./$(SYSTEM_GDBINIT_DIR)
@@ -379,14 +440,15 @@ install: all
 
 .PHONY: install-only
 install-only: install-syscalls install-python install-guile \
-	install-system-gdbinit
+	install-source-highlight install-system-gdbinit
 
 .PHONY: uninstall
 uninstall: uninstall-syscalls uninstall-python uninstall-guile \
-	uninstall-system-gdbinit
+	uninstall-source-highlight uninstall-system-gdbinit
 
 .PHONY: clean
-clean: clean-syscalls clean-python clean-guile clean-system-gdbinit
+clean: clean-syscalls clean-python clean-guile clean-source-highlight \
+	clean-system-gdbinit
 
 .PHONY: maintainer-clean realclean distclean
 maintainer-clean realclean distclean: clean
-- 
2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] gdb: Resolve local source-highlight data directory
  2020-06-02  6:53 [PATCH 0/2] Support installing local source-highlight data directory Stephanos Ioannidis
  2020-06-02  6:53 ` [PATCH 1/2] gdb: Install " Stephanos Ioannidis
@ 2020-06-02  6:53 ` Stephanos Ioannidis
  1 sibling, 0 replies; 3+ messages in thread
From: Stephanos Ioannidis @ 2020-06-02  6:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Stephanos Ioannidis

The source-highlight data directory, which contains the input language
and output format definition files, is currently resolved by the
source-highlight library as one of the following:

 * Path specified by the environment variable SOURCE_HIGHLIGHT_DATADIR
 * Path specified by the source-highlight configuration file under HOME
 * Internally hard-coded path based on the installation prefix

This is less than ideal because users need to install a copy of the
source-highlight program on their system, and either manually set the
SOURCE_HIGHLIGHT_DATADIR environment variable to the path of the
directory containing the source-highlight data files or provide a
source-highlight configuration file under HOME that specifies the data
directory path.

This patch adds the logic to resolve, when exists, the path of the
source-highlight data directory embedded in the gdb data directory,
such that the source code syntax highlighting feature can function
independent of the host system dependencies and configurations.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
---
 gdb/source-cache.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 0561a26737..aa1b5b3dc7 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -35,6 +35,7 @@
 #undef close
 #include <sstream>
 #include <srchilite/sourcehighlight.h>
+#include <srchilite/settings.h>
 #include <srchilite/langmap.h>
 #endif
 
@@ -194,6 +195,21 @@ source_cache::ensure (struct symtab *s)
 	    {
 	      if (highlighter == nullptr)
 		{
+		  /* Configure source-highlight data directory path to the GDB
+		   * local data directory path unless it is missing */
+		  std::string datadir = gdb_datadir + "/source-highlight";
+
+		  struct stat st;
+		  static srchilite::Settings settings;
+
+		  if (stat (datadir.c_str (), &st) == 0
+		      && S_ISDIR (st.st_mode))
+		    {
+		      settings.setGlobalDataDir(datadir);
+		    }
+
+		  /* Create a highlighter instance that outputs the ANSI
+		   * escape code-based color output */
 		  highlighter = new srchilite::SourceHighlight ("esc.outlang");
 		  highlighter->setStyleFile ("esc.style");
 		}
-- 
2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-02  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02  6:53 [PATCH 0/2] Support installing local source-highlight data directory Stephanos Ioannidis
2020-06-02  6:53 ` [PATCH 1/2] gdb: Install " Stephanos Ioannidis
2020-06-02  6:53 ` [PATCH 2/2] gdb: Resolve " Stephanos Ioannidis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).