Adding GDB PrettyPrinter for mlir::Identifier.

This is the first bit from D73546. Primarily setting up the corresponding test. Will add more pretty printers in a separate revision.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D86937

GitOrigin-RevId: 9e9e6e698d8ef5dc5b7576058f2022aab2534a52
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3ac0a4..3750f2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,12 @@
 )
 target_link_libraries(check-gdb-llvm-support PRIVATE LLVMSupport)
 
+add_llvm_executable(check-gdb-mlir-support
+        llvm-prettyprinters/gdb/mlir-support.cpp
+)
+target_include_directories(check-gdb-mlir-support PRIVATE ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include)
+target_link_libraries(check-gdb-mlir-support PRIVATE MLIRIR)
+
 set(DEBUGINFO_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(DEBUGINFO_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
@@ -19,6 +25,7 @@
   llvm-config
   llvm-objdump
   check-gdb-llvm-support
+  check-gdb-mlir-support
   not
   )
 
diff --git a/lit.cfg.py b/lit.cfg.py
index 4c45b72..ba09b1f 100644
--- a/lit.cfg.py
+++ b/lit.cfg.py
@@ -46,6 +46,7 @@
         config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')),
     ToolSubst("%llvm_src_root", config.llvm_src_root),
     ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
+    ToolSubst("%mlir_src_root", config.mlir_src_root),
 ]
 
 def get_required_attr(config, attr_name):
diff --git a/lit.site.cfg.py.in b/lit.site.cfg.py.in
index d5893f5..4ed49b8 100644
--- a/lit.site.cfg.py.in
+++ b/lit.site.cfg.py.in
@@ -20,6 +20,8 @@
 config.host_arch = "@HOST_ARCH@"
 config.is_msvc = lit.util.pythonize_bool("@MSVC@")
 
+config.mlir_src_root = "@MLIR_SOURCE_DIR@"
+
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 
 config.python3_executable = "@Python3_EXECUTABLE@"
diff --git a/llvm-prettyprinters/gdb/mlir-support.cpp b/llvm-prettyprinters/gdb/mlir-support.cpp
new file mode 100644
index 0000000..d38fc3d
--- /dev/null
+++ b/llvm-prettyprinters/gdb/mlir-support.cpp
@@ -0,0 +1,8 @@
+#include "mlir/IR/Identifier.h"
+#include "mlir/IR/MLIRContext.h"
+
+mlir::MLIRContext Context;
+
+auto Identifier = mlir::Identifier::get("foo", &Context);
+
+int main() { return 0; }
diff --git a/llvm-prettyprinters/gdb/mlir-support.gdb b/llvm-prettyprinters/gdb/mlir-support.gdb
new file mode 100644
index 0000000..cca435e
--- /dev/null
+++ b/llvm-prettyprinters/gdb/mlir-support.gdb
@@ -0,0 +1,8 @@
+# RUN: gdb -q -batch -n -iex 'source %mlir_src_root/utils/gdb-scripts/prettyprinters.py' -x %s %llvm_tools_dir/check-gdb-mlir-support | FileCheck %s --dump-input=fail
+# REQUIRES: debug-info
+
+break main
+run
+
+# CHECK: "foo"
+p Identifier