hintonda updated this revision to Diff 109949.
hintonda added a comment.

- Use temp files instead of temp dir.


https://reviews.llvm.org/D36347

Files:
  CMakeLists.txt
  utils/CMakeLists.txt
  utils/run_lldb.sh.in

Index: utils/run_lldb.sh.in
===================================================================
--- /dev/null
+++ utils/run_lldb.sh.in
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+#
+# This script runs the given command in lldb and sets breakpoints on all reported diagnostics.
+
+function usage() {
+  cat <<EOF
+usage: run_lldb.sh <clang command line>
+EOF
+  exit 1
+}
+
+if [ $# -eq 0 ]; then
+  echo "Error: No arguments supplied"
+  usage
+fi
+
+cmd=""
+if [ "$2" == "-cc1" ]; then
+  cmd=`echo "$@" 2>&1 | sed -ne "s/\(.*\) -cc1/-f \1 -- -cc1/p"`
+else
+  cmd=`$@ -### 2>&1 | sed -ne "s/.*\"\(.*\)\" .*\-cc1\"/-f \1 -- -cc1/p"`
+fi
+
+tmpdir=/tmp/run_lldb
+test ! -d $tmpdir && mkdir $tmpdir
+
+indexfile=$(mktemp $tmpdir/diag.idx.XXXXXX)
+cd @CLANG_SOURCE_DIR@
+find lib include tools \( -name \*.cpp -or -name \*.h \) -exec grep -nHE 'diag::(err_|warn_|ext_)[a-z_]+' \{\} \; |\
+  sed -e 's/^\(.*:[0-9]*:\).*diag::\([a-z_]*\).*/\2:\1/' | \
+  sort > $indexfile
+cd - > /dev/null
+
+root=$(mktemp $tmpdir/diagXXXXXX) && rm $root
+module=$(basename $root)
+script=$root.py
+cat << EOF > $script
+import lldb
+import re
+from subprocess import check_output as qx;
+
+def setDiagBreakpoint(frame):
+  id = frame.FindVariable("DiagID").GetValue()
+  if id is None:
+    return False
+
+  name = qx(["@CMAKE_RUNTIME_OUTPUT_DIRECTORY@/diagtool", "find-diagnostic-id", id]).rstrip();
+  target = frame.GetThread().GetProcess().GetTarget()
+
+  file = open("$indexfile", "r")
+  for line in file:
+    if re.search(name, line):
+      i = filter(None, re.split(r'.*:.*/(\w.*):(\w.*):.*\n', line))
+      bp = target.BreakpointCreateByLocation(i[0], int(i[1]))
+      bp.SetEnabled(False)
+
+  return False
+EOF
+
+PYTHONPATH=$PYTHONPATH:$tmpdir lldb \
+  -o "breakpoint set -n DiagnosticsEngine::Report" \
+  -o "break command add -s p -o 'import $module; return $module.setDiagBreakpoint(frame)'" \
+  -o "run" \
+  -o "breakpoint delete -f 1" \
+  -o "breakpoint enable" \
+  -o "run" \
+  $cmd
+
+rm $indexfile
+rm $script
Index: utils/CMakeLists.txt
===================================================================
--- /dev/null
+++ utils/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+set(FILENAME run_lldb.sh)
+# Configure to a temparary directory
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}.in
+  ${CMAKE_CURRENT_BINARY_DIR}/.tmp/${FILENAME}
+  @ONLY
+  )
+# Copy temparary file to real destination and set permissions/
+file(COPY
+  ${CMAKE_CURRENT_BINARY_DIR}/.tmp/${FILENAME}
+  DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+  FILE_PERMISSIONS
+    OWNER_READ OWNER_WRITE OWNER_EXECUTE
+    GROUP_READ GROUP_EXECUTE
+    WORLD_READ WORLD_EXECUTE
+    )
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -408,6 +408,8 @@
 
 add_subdirectory(utils/TableGen)
 
+add_subdirectory(utils)
+
 add_subdirectory(include)
 
 # All targets below may depend on all tablegen'd files.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to