[PATCH v2 08/47] gdb, intelgt: add disassemble feature for the Intel GT architecture.

Tankut Baris Aktemur
2024-12-13T16:21:07Z

From: Albertano Caruso <albertano.caruso@intel.com>

Disassembly of Intel GT programs is done via the Intel Gen Assembler
library. Add this library as an optional dependency. If the library
is not found, disassembly is disabled.
---
gdb/Makefile.in | 6 +-
gdb/config.in | 3 +
gdb/configure | 537 ++++++++++++++++++++++++++++++++++++++++++++++++-
gdb/configure.ac | 40 ++++
gdb/disasm-selftests.c | 4 +
gdb/intelgt-tdep.c | 115 ++++++++++-
gdb/top.c | 10 +
7 files changed, 711 insertions(+), 4 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 05280c7787e467b2cb7b063d893b1c394b506c12..96b3abf9cd76db3bc99d9b4b7944d51f0811a8e7 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -250,6 +250,10 @@ CODESIGN_CERT = @CODESIGN_CERT@
# Flags to pass to gdb when invoked with "make run".
GDBFLAGS =

+# Where is libiga (i.e. the disassembler lib for the intelgt target)?
+# This will be empty if libiga was not available.
+LIBIGA = @LIBIGA64@
+
# Helper code from gnulib.
GNULIB_PARENT_DIR = ..
include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
@@ -680,7 +684,7 @@ CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) $(ZSTD_LIBS) \
$(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \
$(WIN32LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS) $(LIBICONV) \
$(GMPLIBS) $(SRCHIGH_LIBS) $(LIBXXHASH) $(PTHREAD_LIBS) \
- $(DEBUGINFOD_LIBS) $(LIBBABELTRACE_LIB)
+ $(DEBUGINFOD_LIBS) $(LIBBABELTRACE_LIB) $(LIBIGA)
CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(CTF_DEPS) \
$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU) \
$(LIBSUPPORT)
diff --git a/gdb/config.in b/gdb/config.in
index db63aeaec75a69573d21ec5da102eb422e58e9e8..c42755234dc7a12e5f942b2ee2d37d8190ebb8a2 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -271,6 +271,9 @@
/* Define to 1 if you have the `libiconvlist' function. */
#undef HAVE_LIBICONVLIST

+/* Define if you have the iga64 library. */
+#undef HAVE_LIBIGA64
+
/* Define if you have the ipt library. */
#undef HAVE_LIBIPT

diff --git a/gdb/configure b/gdb/configure
index de750f4fafee64900fc1a6d4a1d8aed2ead73657..f2be390c7d792dd4bfde45337b51f93f072aeb41 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -714,6 +714,9 @@ SYSTEM_GDBINIT
TARGET_SYSTEM_ROOT
CONFIG_LDFLAGS
RDYNAMIC
+LTLIBIGA64
+LIBIGA64
+HAVE_LIBIGA64
SRCHIGH_CFLAGS
SRCHIGH_LIBS
HAVE_GUILE_FALSE
@@ -956,6 +959,8 @@ with_python
with_python_libdir
with_guile
enable_source_highlight
+with_libiga64_prefix
+with_libiga64_type
with_sysroot
with_system_gdbinit
with_system_gdbinit_dir
@@ -1728,6 +1733,9 @@ Optional Packages:
search for python's libraries in DIR
--with-guile[=GUILE] include guile support
(auto/yes/no/<guile-version>/<pkg-config-program>)
+ --with-libiga64-prefix[=DIR] search for libiga64 in DIR/include and DIR/lib
+ --without-libiga64-prefix don't search for libiga64 in includedir and libdir
+ --with-libiga64-type=TYPE type of library to search for (auto/static/shared)
--with-sysroot[=DIR] search for usr/lib et al within DIR
--with-system-gdbinit=PATH
automatically load a system-wide gdbinit file
@@ -11499,7 +11507,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11502 "configure"
+#line 11510 "configure"
#include "confdefs.h"

#if HAVE_DLFCN_H
@@ -11605,7 +11613,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11608 "configure"
+#line 11616 "configure"
#include "confdefs.h"

#if HAVE_DLFCN_H
@@ -29071,6 +29079,531 @@ fi

+# Check for Intel(R) Graphics Technology assembler library
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+
+
+
+
+
+
+
+ use_additional=yes
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+
+# Check whether --with-libiga64-prefix was given.
+if test "${with_libiga64_prefix+set}" = set; then :
+ withval=$with_libiga64_prefix;
+ if test "X$withval" = "Xno"; then
+ use_additional=no
+ else
+ if test "X$withval" = "X"; then
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+
+ eval additional_includedir=\"$includedir\"
+ eval additional_libdir=\"$libdir\"
+
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ else
+ additional_includedir="$withval/include"
+ additional_libdir="$withval/lib"
+ fi
+ fi
+
+fi
+
+
+# Check whether --with-libiga64-type was given.
+if test "${with_libiga64_type+set}" = set; then :
+ withval=$with_libiga64_type; with_libiga64_type=$withval
+else
+ with_libiga64_type=auto
+fi
+
+ lib_type=`eval echo \$with_libiga64_type`
+
+ LIBIGA64=
+ LTLIBIGA64=
+ INCIGA64=
+ rpathdirs=
+ ltrpathdirs=
+ names_already_handled=
+ names_next_round='iga64 '
+ while test -n "$names_next_round"; do
+ names_this_round="$names_next_round"
+ names_next_round=
+ for name in $names_this_round; do
+ already_handled=
+ for n in $names_already_handled; do
+ if test "$n" = "$name"; then
+ already_handled=yes
+ break
+ fi
+ done
+ if test -z "$already_handled"; then
+ names_already_handled="$names_already_handled $name"
+ uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+ eval value=\"\$HAVE_LIB$uppername\"
+ if test -n "$value"; then
+ if test "$value" = yes; then
+ eval value=\"\$LIB$uppername\"
+ test -z "$value" || LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$value"
+ eval value=\"\$LTLIB$uppername\"
+ test -z "$value" || LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }$value"
+ else
+ :
+ fi
+ else
+ found_dir=
+ found_la=
+ found_so=
+ found_a=
+ if test $use_additional = yes; then
+ if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
+ found_dir="$additional_libdir"
+ found_so="$additional_libdir/lib$name.$shlibext"
+ if test -f "$additional_libdir/lib$name.la"; then
+ found_la="$additional_libdir/lib$name.la"
+ fi
+ elif test x$lib_type != xshared; then
+ if test -f "$additional_libdir/lib$name.$libext"; then
+ found_dir="$additional_libdir"
+ found_a="$additional_libdir/lib$name.$libext"
+ if test -f "$additional_libdir/lib$name.la"; then
+ found_la="$additional_libdir/lib$name.la"
+ fi
+ fi
+ fi
+ fi
+ if test "X$found_dir" = "X"; then
+ for x in $LDFLAGS $LTLIBIGA64; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ case "$x" in
+ -L*)
+ dir=`echo "X$x" | sed -e 's/^X-L//'`
+ if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then
+ found_dir="$dir"
+ found_so="$dir/lib$name.$shlibext"
+ if test -f "$dir/lib$name.la"; then
+ found_la="$dir/lib$name.la"
+ fi
+ elif test x$lib_type != xshared; then
+ if test -f "$dir/lib$name.$libext"; then
+ found_dir="$dir"
+ found_a="$dir/lib$name.$libext"
+ if test -f "$dir/lib$name.la"; then
+ found_la="$dir/lib$name.la"
+ fi
+ fi
+ fi
+ ;;
+ esac
+ if test "X$found_dir" != "X"; then
+ break
+ fi
+ done
+ fi
+ if test "X$found_dir" != "X"; then
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }-L$found_dir -l$name"
+ if test "X$found_so" != "X"; then
+ if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$found_so"
+ else
+ haveit=
+ for x in $ltrpathdirs; do
+ if test "X$x" = "X$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ ltrpathdirs="$ltrpathdirs $found_dir"
+ fi
+ if test "$hardcode_direct" = yes; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$found_so"
+ else
+ if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$found_so"
+ haveit=
+ for x in $rpathdirs; do
+ if test "X$x" = "X$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ rpathdirs="$rpathdirs $found_dir"
+ fi
+ else
+ haveit=
+ for x in $LDFLAGS $LIBIGA64; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ if test "X$x" = "X-L$found_dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-L$found_dir"
+ fi
+ if test "$hardcode_minus_L" != no; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$found_so"
+ else
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-l$name"
+ fi
+ fi
+ fi
+ fi
+ else
+ if test "X$found_a" != "X"; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$found_a"
+ else
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-L$found_dir -l$name"
+ fi
+ fi
+ additional_includedir=
+ case "$found_dir" in
+ */lib | */lib/)
+ basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
+ additional_includedir="$basedir/include"
+ ;;
+ esac
+ if test "X$additional_includedir" != "X"; then
+ if test "X$additional_includedir" != "X/usr/include"; then
+ haveit=
+ if test "X$additional_includedir" = "X/usr/local/include"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux*) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ for x in $CPPFLAGS $INCIGA64; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ if test "X$x" = "X-I$additional_includedir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_includedir"; then
+ INCIGA64="${INCIGA64}${INCIGA64:+ }-I$additional_includedir"
+ fi
+ fi
+ fi
+ fi
+ fi
+ if test -n "$found_la"; then
+ save_libdir="$libdir"
+ case "$found_la" in
+ */* | *\\*) . "$found_la" ;;
+ *) . "./$found_la" ;;
+ esac
+ libdir="$save_libdir"
+ for dep in $dependency_libs; do
+ case "$dep" in
+ -L*)
+ additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+ if test "X$additional_libdir" != "X/usr/lib"; then
+ haveit=
+ if test "X$additional_libdir" = "X/usr/local/lib"; then
+ if test -n "$GCC"; then
+ case $host_os in
+ linux*) haveit=yes;;
+ esac
+ fi
+ fi
+ if test -z "$haveit"; then
+ haveit=
+ for x in $LDFLAGS $LIBIGA64; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ if test "X$x" = "X-L$additional_libdir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_libdir"; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-L$additional_libdir"
+ fi
+ fi
+ haveit=
+ for x in $LDFLAGS $LTLIBIGA64; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ if test "X$x" = "X-L$additional_libdir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ if test -d "$additional_libdir"; then
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }-L$additional_libdir"
+ fi
+ fi
+ fi
+ fi
+ ;;
+ -R*)
+ dir=`echo "X$dep" | sed -e 's/^X-R//'`
+ if test "$enable_rpath" != no; then
+ haveit=
+ for x in $rpathdirs; do
+ if test "X$x" = "X$dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ rpathdirs="$rpathdirs $dir"
+ fi
+ haveit=
+ for x in $ltrpathdirs; do
+ if test "X$x" = "X$dir"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ ltrpathdirs="$ltrpathdirs $dir"
+ fi
+ fi
+ ;;
+ -l*)
+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+ ;;
+ *.la)
+ names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+ ;;
+ *)
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$dep"
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }$dep"
+ ;;
+ esac
+ done
+ fi
+ else
+ if test "x$lib_type" = "xauto" || test "x$lib_type" = "xshared"; then
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-l$name"
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }-l$name"
+ else
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }-l:lib$name.$libext"
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }-l:lib$name.$libext"
+ fi
+ fi
+ fi
+ fi
+ done
+ done
+ if test "X$rpathdirs" != "X"; then
+ if test -n "$hardcode_libdir_separator"; then
+ alldirs=
+ for found_dir in $rpathdirs; do
+ alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
+ done
+ acl_save_libdir="$libdir"
+ libdir="$alldirs"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$flag"
+ else
+ for found_dir in $rpathdirs; do
+ acl_save_libdir="$libdir"
+ libdir="$found_dir"
+ eval flag=\"$hardcode_libdir_flag_spec\"
+ libdir="$acl_save_libdir"
+ LIBIGA64="${LIBIGA64}${LIBIGA64:+ }$flag"
+ done
+ fi
+ fi
+ if test "X$ltrpathdirs" != "X"; then
+ for found_dir in $ltrpathdirs; do
+ LTLIBIGA64="${LTLIBIGA64}${LTLIBIGA64:+ }-R$found_dir"
+ done
+ fi
+
+
+ ac_save_CPPFLAGS="$CPPFLAGS"
+
+ for element in $INCIGA64; do
+ haveit=
+ for x in $CPPFLAGS; do
+
+ acl_save_prefix="$prefix"
+ prefix="$acl_final_prefix"
+ acl_save_exec_prefix="$exec_prefix"
+ exec_prefix="$acl_final_exec_prefix"
+ eval x=\"$x\"
+ exec_prefix="$acl_save_exec_prefix"
+ prefix="$acl_save_prefix"
+
+ if test "X$x" = "X$element"; then
+ haveit=yes
+ break
+ fi
+ done
+ if test -z "$haveit"; then
+ CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+ fi
+ done
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libiga64" >&5
+$as_echo_n "checking for libiga64... " >&6; }
+if ${ac_cv_libiga64+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS $LIBIGA64"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include "assert.h"
+ #include "iga/iga.h"
+int
+main ()
+{
+iga_version_string();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+ ac_cv_libiga64=yes
+else
+ ac_cv_libiga64=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ LIBS="$ac_save_LIBS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libiga64" >&5
+$as_echo "$ac_cv_libiga64" >&6; }
+ if test "$ac_cv_libiga64" = yes; then
+ HAVE_LIBIGA64=yes
+
+$as_echo "#define HAVE_LIBIGA64 1" >>confdefs.h
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiga64" >&5
+$as_echo_n "checking how to link with libiga64... " >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBIGA64" >&5
+$as_echo "$LIBIGA64" >&6; }
+ else
+ HAVE_LIBIGA64=no
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ LIBIGA64=
+ LTLIBIGA64=
+ fi
+
+
+
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+intelgt_target=false
+
+for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'`
+do
+ if test "$targ_alias" = "all"; then
+ intelgt_target=true
+ else
+ case "$targ_alias" in
+ intelgt-*)
+ intelgt_target=true
+ ;;
+ esac
+ fi
+done
+
+case "${target}" in
+ intelgt-*)
+ intelgt_target=true
+ ;;
+esac
+
+if test x${intelgt_target} = xtrue; then
+ if test "$HAVE_LIBIGA64" != yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libiga64 is missing or unusable; some features may be unavailable." >&5
+$as_echo "$as_me: WARNING: libiga64 is missing or unusable; some features may be unavailable." >&2;}
+ fi
+else
+ # Do not link libiga64 spuriously
+ HAVE_LIBIGA64=no
+ LIBIGA64=
+ LTLIBIGA64=
+fi
+
# ------------------------- #
# Checks for header files. #
# ------------------------- #
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 230c0be79c7c51f64f748cfa5c446fc0d62b7520..c2b6fad04876a578a4ea28a6a6f30bf5e5d8686f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1289,6 +1289,46 @@ fi
AC_SUBST(SRCHIGH_LIBS)
AC_SUBST(SRCHIGH_CFLAGS)

+# Check for Intel(R) Graphics Technology assembler library
+AC_LANG_PUSH([C++])
+AC_LIB_HAVE_LINKFLAGS([iga64], [],
+ [#include "assert.h"
+ #include "iga/iga.h"],
+ [iga_version_string();])
+AC_LANG_POP([C++])
+
+intelgt_target=false
+
+for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'`
+do
+ if test "$targ_alias" = "all"; then
+ intelgt_target=true
+ else
+ case "$targ_alias" in
+ intelgt-*)
+ intelgt_target=true
+ ;;
+ esac
+ fi
+done
+
+case "${target}" in
+ intelgt-*)
+ intelgt_target=true
+ ;;
+esac
+
+if test x${intelgt_target} = xtrue; then
+ if test "$HAVE_LIBIGA64" != yes; then
+ AC_MSG_WARN([libiga64 is missing or unusable; some features may be unavailable.])
+ fi
+else
+ # Do not link libiga64 spuriously
+ HAVE_LIBIGA64=no
+ LIBIGA64=
+ LTLIBIGA64=
+fi
+
# ------------------------- #
# Checks for header files. #
# ------------------------- #
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 221b94f085135837510fa9062082702c76c5c802..941c09b84f10703ed932919ea2790b466833ffe8 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -115,6 +115,10 @@ get_test_insn (struct gdbarch *gdbarch, size_t *len)
*len = bplen;
}
break;
+ case bfd_arch_intelgt:
+ /* The intelgt architecture needs to initialize the gdbarch with
+ an IGA context to be able to use the disassembler. */
+ return insn;
case bfd_arch_i386:
{
const struct bfd_arch_info *info = gdbarch_bfd_arch_info (gdbarch);
diff --git a/gdb/intelgt-tdep.c b/gdb/intelgt-tdep.c
index 57c359bf355c5771db38b8d213f6681a043c2b33..7d0ae38480fe89b145c1c29be0e58c96480e3335 100755
--- a/gdb/intelgt-tdep.c
+++ b/gdb/intelgt-tdep.c
@@ -31,6 +31,10 @@
#include "inferior.h"
#include "user-regs.h"
#include <algorithm>
+#include "disasm.h"
+#if defined (HAVE_LIBIGA64)
+#include "iga/iga.h"
+#endif /* defined (HAVE_LIBIGA64) */

/* Global debug flag. */
static bool intelgt_debug = false;
@@ -119,6 +123,11 @@ struct intelgt_gdbarch_tdep : gdbarch_tdep_base
gdb_assert (regset_ranges[intelgt::REGSET_GRF].end > 1);
return regset_ranges[intelgt::REGSET_GRF].end - 1;
}
+
+#if defined (HAVE_LIBIGA64)
+ /* libiga context for disassembly. */
+ iga_context_t iga_ctx = nullptr;
+#endif
};

/* The 'register_type' gdbarch method. */
@@ -511,13 +520,77 @@ intelgt_sw_breakpoint_from_kind (gdbarch *gdbarch, int kind, int *size)
return nullptr;
}

+#if defined (HAVE_LIBIGA64)
+/* Map CORE_ADDR to symbol names for jump labels in an IGA disassembly. */
+
+static const char *
+intelgt_disasm_sym_cb (int addr, void *ctx)
+{
+ disassemble_info *info = (disassemble_info *) ctx;
+ symbol *sym = find_pc_function (addr + (uintptr_t) info->private_data);
+ return sym ? sym->linkage_name () : nullptr;
+}
+#endif /* defined (HAVE_LIBIGA64) */
+
/* Print one instruction from MEMADDR on INFO->STREAM. */

static int
intelgt_print_insn (bfd_vma memaddr, struct disassemble_info *info)
{
- /* Disassembler is to be added in a later patch. */
+ unsigned int full_length = intelgt::inst_length_full ();
+ unsigned int compact_length = intelgt::inst_length_compacted ();
+
+ std::unique_ptr<bfd_byte[]> insn (new bfd_byte[full_length]);
+
+ int status = (*info->read_memory_func) (memaddr, insn.get (),
+ compact_length, info);
+ if (status != 0)
+ {
+ /* Aborts disassembling with a memory_error exception. */
+ (*info->memory_error_func) (status, memaddr, info);
+ return -1;
+ }
+ if (!intelgt::is_compacted_inst (gdb::make_array_view (insn.get (),
+ compact_length)))
+ {
+ status = (*info->read_memory_func) (memaddr, insn.get (),
+ full_length, info);
+ if (status != 0)
+ {
+ /* Aborts disassembling with a memory_error exception. */
+ (*info->memory_error_func) (status, memaddr, info);
+ return -1;
+ }
+ }
+
+#if defined (HAVE_LIBIGA64)
+ char *dbuf;
+ iga_disassemble_options_t dopts = IGA_DISASSEMBLE_OPTIONS_INIT ();
+ gdb_disassemble_info *di
+ = static_cast<gdb_disassemble_info *>(info->application_data);
+ struct gdbarch *gdbarch = di->arch ();
+
+ iga_context_t iga_ctx
+ = gdbarch_tdep<intelgt_gdbarch_tdep> (gdbarch)->iga_ctx;
+ iga_status_t iga_status
+ = iga_context_disassemble_instruction (iga_ctx, &dopts, insn.get (),
+ intelgt_disasm_sym_cb,
+ info, &dbuf);
+ if (iga_status != IGA_SUCCESS)
+ return -1;
+
+ (*info->fprintf_func) (info->stream, "%s", dbuf);
+
+ if (intelgt::is_compacted_inst (gdb::make_array_view (insn.get (),
+ full_length)))
+ return compact_length;
+ else
+ return full_length;
+#else
+ gdb_printf (_("\nDisassemble feature not available: libiga64 "
+ "is missing.\n"));
return -1;
+#endif /* defined (HAVE_LIBIGA64) */
}

/* Utility function to look up the pseudo-register number by name. Exact
@@ -864,6 +937,46 @@ intelgt_gdbarch_init (gdbarch_info info, gdbarch_list *arches)
intelgt_gdbarch_tdep *data
= gdbarch_tdep<intelgt_gdbarch_tdep> (gdbarch);

+#if defined (HAVE_LIBIGA64)
+ iga_gen_t iga_version = IGA_GEN_INVALID;
+
+ if (tdesc != nullptr)
+ {
+ const tdesc_device *device_info = tdesc_device_info (tdesc);
+ if (!(device_info->vendor_id.has_value ()
+ && device_info->target_id.has_value ()))
+ {
+ warning (_("Device vendor id and target id not found."));
+ gdbarch_free (gdbarch);
+ return nullptr;
+ }
+
+ uint32_t vendor_id = *device_info->vendor_id;
+ uint32_t device_id = *device_info->target_id;
+ if (vendor_id != 0x8086)
+ {
+ warning (_("Device not recognized: vendor id=0x%04x,"
+ " device id=0x%04x"), vendor_id, device_id);
+ gdbarch_free (gdbarch);
+ return nullptr;
+ }
+ else
+ {
+ iga_version = (iga_gen_t) get_xe_version (device_id);
+ if (iga_version == IGA_GEN_INVALID)
+ warning (_("Intel GT device id is unrecognized: ID 0x%04x"),
+ device_id);
+ }
+ }
+
+ /* Take the best guess in case IGA_VERSION is still invalid. */
+ if (iga_version == IGA_GEN_INVALID)
+ iga_version = IGA_XE_HPC;
+
+ const iga_context_options_t options = IGA_CONTEXT_OPTIONS_INIT (iga_version);
+ iga_context_create (&options, &data->iga_ctx);
+#endif
+
/* Initialize register info. */
set_gdbarch_num_regs (gdbarch, 0);
set_gdbarch_register_name (gdbarch, tdesc_register_name);
diff --git a/gdb/top.c b/gdb/top.c
index d750f3305f2eef7c5a30cef7f647537916a80499..c27f7d60254a4d384dfd770ce98eb4f0923dee49 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1523,6 +1523,16 @@ This GDB was configured as follows:\n\
"));
#endif

+#ifdef HAVE_LIBIGA64
+ gdb_printf (stream, _("\
+ --with-libiga64\n\
+"));
+#else
+ gdb_printf (stream, _("\
+ --without-libiga64\n\
+"));
+#endif
+
#if HAVE_SOURCE_HIGHLIGHT
gdb_printf (stream, _("\
--enable-source-highlight\n\