683e84e
commit 9ad9480c3a380a04b3dbe869c0675d6bba37247b
683e84e
Author: Kamil Rytarowski <n54@gmx.com>
683e84e
Date:   Thu May 25 20:12:30 2017 +0000
683e84e
683e84e
    Fix bug #28898
683e84e
    lldb: libedit produces garbled, unusable input on Linux
683e84e
    
683e84e
    Apply patch from Christos Zoulas, upstream libedit developer.
683e84e
    It has been tested on NetBSD/amd64.
683e84e
    
683e84e
    New code supports combination of wide libedit and disabled
683e84e
    LLDB_EDITLINE_USE_WCHAR, which was the popular case on Linux
683e84e
    systems.
683e84e
    
683e84e
    
683e84e
    git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@303907 91177308-0d34-0410-b5e6-96231b3b80d8
683e84e
683e84e
diff --git a/include/lldb/Host/Editline.h b/include/lldb/Host/Editline.h
683e84e
index 2b1a8e0..0b75e9c 100644
683e84e
--- a/include/lldb/Host/Editline.h
683e84e
+++ b/include/lldb/Host/Editline.h
683e84e
@@ -82,8 +82,14 @@ using EditLineStringStreamType = std::stringstream;
683e84e
 using EditLineCharType = char;
683e84e
 #endif
683e84e
 
683e84e
+#ifdef EL_CLIENTDATA	/* editline with wide support + wide char read function */
683e84e
+using EditLineGetCharType = wchar_t;
683e84e
+#else
683e84e
+using EditLineGetCharType = char;
683e84e
+#endif
683e84e
+
683e84e
 typedef int (*EditlineGetCharCallbackType)(::EditLine *editline,
683e84e
-                                           EditLineCharType *c);
683e84e
+                                           EditLineGetCharType *c);
683e84e
 typedef unsigned char (*EditlineCommandCallbackType)(::EditLine *editline,
683e84e
                                                      int ch);
683e84e
 typedef const char *(*EditlinePromptCallbackType)(::EditLine *editline);
683e84e
@@ -270,7 +276,7 @@ private:
683e84e
 
683e84e
   /// Character reading implementation for EditLine that supports our multi-line
683e84e
   /// editing trickery.
683e84e
-  int GetCharacter(EditLineCharType *c);
683e84e
+  int GetCharacter(EditLineGetCharType *c);
683e84e
 
683e84e
   /// Prompt implementation for EditLine.
683e84e
   const char *Prompt();
683e84e
@@ -323,7 +329,7 @@ private:
683e84e
   /// single or multi-line editing.
683e84e
   void ConfigureEditor(bool multiline);
683e84e
 
683e84e
-  bool CompleteCharacter(char ch, EditLineCharType &out;;
683e84e
+  bool CompleteCharacter(char ch, EditLineGetCharType &out;;
683e84e
 
683e84e
 private:
683e84e
 #if LLDB_EDITLINE_USE_WCHAR
683e84e
diff --git a/source/Host/common/Editline.cpp b/source/Host/common/Editline.cpp
683e84e
index 7d4b398..7b580dd 100644
683e84e
--- a/source/Host/common/Editline.cpp
683e84e
+++ b/source/Host/common/Editline.cpp
683e84e
@@ -474,7 +474,7 @@ unsigned char Editline::RecallHistory(bool earlier) {
683e84e
   return CC_NEWLINE;
683e84e
 }
683e84e
 
683e84e
-int Editline::GetCharacter(EditLineCharType *c) {
683e84e
+int Editline::GetCharacter(EditLineGetCharType *c) {
683e84e
   const LineInfoW *info = el_wline(m_editline);
683e84e
 
683e84e
   // Paint a faint version of the desired prompt over the version libedit draws
683e84e
@@ -969,7 +969,7 @@ void Editline::ConfigureEditor(bool multiline) {
683e84e
          }));
683e84e
 
683e84e
   el_wset(m_editline, EL_GETCFN, (EditlineGetCharCallbackType)([](
683e84e
-                                     EditLine *editline, EditLineCharType *c) {
683e84e
+                                     EditLine *editline, EditLineGetCharType *c) {
683e84e
             return Editline::InstanceFor(editline)->GetCharacter(c);
683e84e
           }));
683e84e
 
683e84e
@@ -1360,12 +1360,12 @@ void Editline::PrintAsync(Stream *stream, const char *s, size_t len) {
683e84e
   }
683e84e
 }
683e84e
 
683e84e
-bool Editline::CompleteCharacter(char ch, EditLineCharType &out) {
683e84e
+bool Editline::CompleteCharacter(char ch, EditLineGetCharType &out) {
683e84e
 #if !LLDB_EDITLINE_USE_WCHAR
683e84e
   if (ch == (char)EOF)
683e84e
     return false;
683e84e
 
683e84e
-  out = ch;
683e84e
+  out = (unsigned char)ch;
683e84e
   return true;
683e84e
 #else
683e84e
   std::codecvt_utf8<wchar_t> cvt;