[Lldb-commits] [lldb] r343471 - [Interpreter] Escape backticks when dumping format entities.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 1 06:22:24 PDT 2018


Author: jdevlieghere
Date: Mon Oct  1 06:22:24 2018
New Revision: 343471

URL: http://llvm.org/viewvc/llvm-project?rev=343471&view=rev
Log:
[Interpreter] Escape backticks when dumping format entities.

Currently we reject our own default disassembly-format string because it
contains two backticks which causes everything in between to be
interpreter as an expression by the command interpreter. This patch
fixes that by escaping backticks when dumping format strings.

Added:
    lldb/trunk/lit/Settings/TestDisassemblyFormat.test
Modified:
    lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp

Added: lldb/trunk/lit/Settings/TestDisassemblyFormat.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/TestDisassemblyFormat.test?rev=343471&view=auto
==============================================================================
--- lldb/trunk/lit/Settings/TestDisassemblyFormat.test (added)
+++ lldb/trunk/lit/Settings/TestDisassemblyFormat.test Mon Oct  1 06:22:24 2018
@@ -0,0 +1,2 @@
+# RUN: %lldb -x -b -o "settings show disassembly-format" | FileCheck %s
+# CHECK: disassembly-format (format-string) = "{${function.initial-function}{${module.file.basename}\`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}\`}{${function.name-without-args}}:\n}{${current-pc-arrow} }${addr-file-or-load}{ <${function.concrete-only-addr-offset-no-padding}>}: "

Modified: lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp?rev=343471&r1=343470&r2=343471&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp Mon Oct  1 06:22:24 2018
@@ -41,6 +41,20 @@ bool OptionValueFormatEntity::Clear() {
   return true;
 }
 
+static void EscapeBackticks(llvm::StringRef str, std::string &dst) {
+  dst.clear();
+  dst.reserve(str.size());
+
+  for (size_t i = 0, e = str.size(); i != e; ++i) {
+    char c = str[i];
+    if (c == '`') {
+      if (i == 0 || str[i - 1] != '\\')
+        dst += '\\';
+    }
+    dst += c;
+  }
+}
+
 void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
                                         Stream &strm, uint32_t dump_mask) {
   if (dump_mask & eDumpOptionType)
@@ -48,7 +62,9 @@ void OptionValueFormatEntity::DumpValue(
   if (dump_mask & eDumpOptionValue) {
     if (dump_mask & eDumpOptionType)
       strm.PutCString(" = \"");
-    strm << m_current_format.c_str() << '"';
+    std::string escaped;
+    EscapeBackticks(m_current_format, escaped);
+    strm << escaped << '"';
   }
 }
 




More information about the lldb-commits mailing list