[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-21 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272288.
jackoalan marked an inline comment as done.
jackoalan added a comment.

Fix ternary to use corresponding float/double overloaded constructors of APFloat


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,12 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static const int ClassStaticConst = 8;
+CLASS-DAG: static const int ClassStaticConstexpr = 9;
+CLASS-DAG: static const float ClassStaticConstexprFloat = 10.F;
+CLASS-DAG: static const double ClassStaticConstexprDouble = 11.;
+CLASS-DAG: static const double ClassStaticConstexprLongDouble = 12.;
+CLASS-DAG: static const N0::N1::(anonymous namespace)::Enum ClassStaticConstEnum = 8;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 CLASS-DAG: {{(inline )?}}Class(N0::N1::(anonymous namespace)::Enum);
 CLASS-DAG

Re: [Lldb-commits] [lldb] 90c1af1 - [lldb][NFC] Add more test for builtin formats

2020-06-21 Thread Raphael “Teemperor” Isemann via lldb-commits
Sorry for that, it seems I overlooked those failure mails. Thanks!

> On 20 Jun 2020, at 23:22, Eric Christopher  wrote:
> 
> This is failing on some of the debian buildbots so I've temporarily reverted 
> it here:
> 
> commit 10b43541360efb35a1d33e9cf1e93023ebd69b15 (HEAD -> master, 
> origin/master, origin/HEAD)
> Author: Eric Christopher mailto:echri...@gmail.com>>
> Date:   Sat Jun 20 14:21:42 2020
> 
> Temporarily Revert "[lldb][NFC] Add more test for builtin formats"
> as it's failing on the debian buildbots:
> 
> http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/12531 
> 
> 
> This reverts commit 90c1af106a20785ffd01c0d6a41db8bc0160fd11.
> 
> buildbot link:
> 
> http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/12531 
> 
> 
> Sorry for any inconvenience.
> 
> -eric
> 
> On Sat, Jun 20, 2020 at 12:35 PM Raphael Isemann via lldb-commits 
> mailto:lldb-commits@lists.llvm.org>> wrote:
> 
> Author: Raphael Isemann
> Date: 2020-06-20T19:31:40+02:00
> New Revision: 90c1af106a20785ffd01c0d6a41db8bc0160fd11
> 
> URL: 
> https://github.com/llvm/llvm-project/commit/90c1af106a20785ffd01c0d6a41db8bc0160fd11
>  
> 
> DIFF: 
> https://github.com/llvm/llvm-project/commit/90c1af106a20785ffd01c0d6a41db8bc0160fd11.diff
>  
> 
> 
> LOG: [lldb][NFC] Add more test for builtin formats
> 
> The previous tests apparently missed a few code branches in DumpDataExtractor
> code. Also renames the 'test_instruction' which had the same name as another
> test (and Python therefore ignored the test entirely).
> 
> Added: 
> 
> 
> Modified: 
> 
> lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
> 
> Removed: 
> 
> 
> 
> 
> diff  --git 
> a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>  
> b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
> index 9fefae6bbf5c..1a413a13986a 100644
> --- 
> a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
> +++ 
> b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
> @@ -42,6 +42,9 @@ def test(self):
>  self.assertIn("= 0\n", self.getFormatted("float", "0"))
>  self.assertIn("= 2\n", self.getFormatted("float", "0x4000"))
>  self.assertIn("= NaN\n", self.getFormatted("float", "-1"))
> +# Checks the float16 code.
> +self.assertIn("= 2\n", self.getFormatted("float", 
> "(__UINT16_TYPE__)0x4000"))
> +self.assertIn("= error: unsupported byte size (1) for float 
> format\n", self.getFormatted("float", "'a'"))
> 
>  # enumeration
>  self.assertIn("= 0\n", self.getFormatted("enumeration", "0"))
> @@ -59,6 +62,13 @@ def test(self):
> 
>  # octal
>  self.assertIn("= 04553207\n", self.getFormatted("octal", "1234567"))
> +self.assertIn("= 0221505317046536757\n", self.getFormatted("octal", 
> "(__uint128_t)0x123456789ABDEFull"))
> +
> +# complex float
> +self.assertIn("= error: unsupported byte size (1) for complex float 
> format\n", self.getFormatted("complex float", "'a'"))
> +
> +# complex integer
> +self.assertIn("= error: unsupported byte size (1) for complex 
> integer format\n", self.getFormatted("complex integer", "'a'"))
> 
>  # hex
>  self.assertIn("= 0x00abc123\n", self.getFormatted("hex", "0xABC123"))
> @@ -86,6 +96,17 @@ def test(self):
>  self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', 
> self.getFormatted("OSType", "cstring"))
>  self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', 
> self.getFormatted("unicode8", "cstring"))
> 
> +# FIXME: Passing a 'const char *' will ignore any given format,
> +# so we have to repeat the tests with a void* casts to actually test 
> our formats.
> +self.assertIn('= \\x9a\\x0f\\0\\0\\x01\\0\\0\\0\n', 
> self.getFormatted("character array", "(void *)cstring"))
> +self.assertIn('= \\x9a\\x0f\\0\\0\\x01\\0\\0\\0\n', 
> self.getFormatted("character", "(void *)cstring"))
> +self.assertIn('= " \\e\\a\\b\\f\\n\\r\\t\\vaA09"\n', 
> self.getFormatted("c-string", "(void *)cstring"))
> +# FIXME: Ignores the printables characters at the end.
> +self.assertIn('= \n', self.getFormatted("printable 
> character", "(void *)cstring"))
> +self.assertIn('= \'\\0\\0\\0\\x01\\0\\0\\x0f\\x9a\'\n', 
> self.getFormatted("OSType", "(void *)cstring"))
> +# FIXME: This should print a string.
> +self.assertIn('= 0x00010f9a\n', 
>

Re: [Lldb-commits] [lldb] 90c1af1 - [lldb][NFC] Add more test for builtin formats

2020-06-21 Thread Eric Christopher via lldb-commits
No problem at all, happens to all of us :)

-eric

On Sun, Jun 21, 2020 at 12:56 AM Raphael “Teemperor” Isemann <
teempe...@gmail.com> wrote:

> Sorry for that, it seems I overlooked those failure mails. Thanks!
>
> On 20 Jun 2020, at 23:22, Eric Christopher  wrote:
>
> This is failing on some of the debian buildbots so I've temporarily
> reverted it here:
>
> commit 10b43541360efb35a1d33e9cf1e93023ebd69b15 (HEAD -> master,
> origin/master, origin/HEAD)
> Author: Eric Christopher 
> Date:   Sat Jun 20 14:21:42 2020
>
> Temporarily Revert "[lldb][NFC] Add more test for builtin formats"
> as it's failing on the debian buildbots:
>
> http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/12531
>
> This reverts commit 90c1af106a20785ffd01c0d6a41db8bc0160fd11.
>
> buildbot link:
>
> http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/12531
>
> Sorry for any inconvenience.
>
> -eric
>
> On Sat, Jun 20, 2020 at 12:35 PM Raphael Isemann via lldb-commits <
> lldb-commits@lists.llvm.org> wrote:
>
>>
>> Author: Raphael Isemann
>> Date: 2020-06-20T19:31:40+02:00
>> New Revision: 90c1af106a20785ffd01c0d6a41db8bc0160fd11
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/90c1af106a20785ffd01c0d6a41db8bc0160fd11
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/90c1af106a20785ffd01c0d6a41db8bc0160fd11.diff
>>
>> LOG: [lldb][NFC] Add more test for builtin formats
>>
>> The previous tests apparently missed a few code branches in
>> DumpDataExtractor
>> code. Also renames the 'test_instruction' which had the same name as
>> another
>> test (and Python therefore ignored the test entirely).
>>
>> Added:
>>
>>
>> Modified:
>>
>> lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git
>> a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>> b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>> index 9fefae6bbf5c..1a413a13986a 100644
>> ---
>> a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>> +++
>> b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
>> @@ -42,6 +42,9 @@ def test(self):
>>  self.assertIn("= 0\n", self.getFormatted("float", "0"))
>>  self.assertIn("= 2\n", self.getFormatted("float", "0x4000"))
>>  self.assertIn("= NaN\n", self.getFormatted("float", "-1"))
>> +# Checks the float16 code.
>> +self.assertIn("= 2\n", self.getFormatted("float",
>> "(__UINT16_TYPE__)0x4000"))
>> +self.assertIn("= error: unsupported byte size (1) for float
>> format\n", self.getFormatted("float", "'a'"))
>>
>>  # enumeration
>>  self.assertIn("= 0\n", self.getFormatted("enumeration", "0"))
>> @@ -59,6 +62,13 @@ def test(self):
>>
>>  # octal
>>  self.assertIn("= 04553207\n", self.getFormatted("octal",
>> "1234567"))
>> +self.assertIn("= 0221505317046536757\n",
>> self.getFormatted("octal", "(__uint128_t)0x123456789ABDEFull"))
>> +
>> +# complex float
>> +self.assertIn("= error: unsupported byte size (1) for complex
>> float format\n", self.getFormatted("complex float", "'a'"))
>> +
>> +# complex integer
>> +self.assertIn("= error: unsupported byte size (1) for complex
>> integer format\n", self.getFormatted("complex integer", "'a'"))
>>
>>  # hex
>>  self.assertIn("= 0x00abc123\n", self.getFormatted("hex",
>> "0xABC123"))
>> @@ -86,6 +96,17 @@ def test(self):
>>  self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n',
>> self.getFormatted("OSType", "cstring"))
>>  self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n',
>> self.getFormatted("unicode8", "cstring"))
>>
>> +# FIXME: Passing a 'const char *' will ignore any given format,
>> +# so we have to repeat the tests with a void* casts to actually
>> test our formats.
>> +self.assertIn('= \\x9a\\x0f\\0\\0\\x01\\0\\0\\0\n',
>> self.getFormatted("character array", "(void *)cstring"))
>> +self.assertIn('= \\x9a\\x0f\\0\\0\\x01\\0\\0\\0\n',
>> self.getFormatted("character", "(void *)cstring"))
>> +self.assertIn('= " \\e\\a\\b\\f\\n\\r\\t\\vaA09"\n',
>> self.getFormatted("c-string", "(void *)cstring"))
>> +# FIXME: Ignores the printables characters at the end.
>> +self.assertIn('= \n', self.getFormatted("printable
>> character", "(void *)cstring"))
>> +self.assertIn('= \'\\0\\0\\0\\x01\\0\\0\\x0f\\x9a\'\n',
>> self.getFormatted("OSType", "(void *)cstring"))
>> +# FIXME: This should print a string.
>> +self.assertIn('= 0x00010f9a\n',
>> self.getFormatted("unicode8", "(void *)cstring"))
>> +
>>  self.assertIn('= \\0\\0\\0\\0\\0\\0\\0\\0\n',
>> self.getFormatted("character array", "(__UINT64_TYPE__)0"

[Lldb-commits] [PATCH] D82272: [lldb/Lua] Recognize "quit" as a way to exit the interactive script interpreter.

2020-06-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, LLDB.

Add a way to quit the interactive script interpreter from a shell tests. 
Currently, the only way (that I know) to exit the interactive Lua interpreter 
is to send a EOF with CTRL-D. I noticed that the embedded Python script 
interpreter accepts `quit` (while the regular python interpreter doesn't). I've 
added a special case to the Lua interpreter to do the same.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D82272

Files:
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/test/Shell/ScriptInterpreter/Lua/quit.test


Index: lldb/test/Shell/ScriptInterpreter/Lua/quit.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/quit.test
@@ -0,0 +1,10 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2>&1 | FileCheck %s
+script
+print(95000 + 126)
+quit
+target list
+# CHECK: 95126
+# CHECK: No targets
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -39,6 +39,11 @@
 
   void IOHandlerInputComplete(IOHandler &io_handler,
   std::string &data) override {
+if (llvm::StringRef(data).rtrim() == "quit") {
+  io_handler.SetIsDone(true);
+  return;
+}
+
 if (llvm::Error error = m_script_interpreter.GetLua().Run(data)) {
   *GetOutputStreamFileSP() << llvm::toString(std::move(error));
 }


Index: lldb/test/Shell/ScriptInterpreter/Lua/quit.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/quit.test
@@ -0,0 +1,10 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2>&1 | FileCheck %s
+script
+print(95000 + 126)
+quit
+target list
+# CHECK: 95126
+# CHECK: No targets
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -39,6 +39,11 @@
 
   void IOHandlerInputComplete(IOHandler &io_handler,
   std::string &data) override {
+if (llvm::StringRef(data).rtrim() == "quit") {
+  io_handler.SetIsDone(true);
+  return;
+}
+
 if (llvm::Error error = m_script_interpreter.GetLua().Run(data)) {
   *GetOutputStreamFileSP() << llvm::toString(std::move(error));
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D82273: [lldb/Lua] Use the debugger's output and error file for Lua's I/O library.

2020-06-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, LLDB.

Add support for changing the stdout and stderr file in Lua's I/O library and 
hook it up with the debugger's output and error file respectively for the 
interactive Lua interpreter.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D82273

Files:
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/test/Shell/ScriptInterpreter/Lua/io.test


Index: lldb/test/Shell/ScriptInterpreter/Lua/io.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/io.test
@@ -0,0 +1,16 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2> %t.stderr > %t.stdout
+# RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
+# RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
+script
+file = lldb.SBFile(2, "w", false)
+lldb.debugger:SetOutputFile(file)
+io.write(95000 + 126, "\n")
+quit
+script
+io.write(95000 + 14, "\n")
+# STDOUT: 95126
+# STDOUT-NOT: 95014
+# STDERR: 95014
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -30,6 +30,9 @@
   ">>> ", "..> ", true, debugger.GetUseColor(), 0,
   *this, nullptr),
 m_script_interpreter(script_interpreter) {
+llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+debugger.GetOutputFile().GetStream(),
+debugger.GetErrorFile().GetStream()));
 llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
   }
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
@@ -38,6 +38,7 @@
 
   llvm::Error Run(llvm::StringRef buffer);
   llvm::Error LoadModule(llvm::StringRef filename);
+  llvm::Error ChangeIO(FILE *out = nullptr, FILE *err = nullptr);
 
 private:
   lua_State *m_lua_state;
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -57,3 +57,35 @@
   lua_setglobal(m_lua_state, module_name.GetCString());
   return llvm::Error::success();
 }
+
+llvm::Error Lua::ChangeIO(FILE *out, FILE *err) {
+  lua_getglobal(m_lua_state, "io");
+
+  if (out) {
+lua_pushstring(m_lua_state, "stdout");
+lua_gettable(m_lua_state, -2);
+luaL_Stream *s =
+static_cast(lua_touserdata(m_lua_state, -1));
+if (!s)
+  return llvm::make_error(
+  "could not get stdout", llvm::inconvertibleErrorCode());
+s->f = out;
+
+lua_pop(m_lua_state, 1);
+  }
+
+  if (err) {
+lua_pushstring(m_lua_state, "stderr");
+lua_gettable(m_lua_state, -2);
+luaL_Stream *s =
+static_cast(lua_touserdata(m_lua_state, -1));
+if (!s)
+  return llvm::make_error(
+  "could not get stderr", llvm::inconvertibleErrorCode());
+s->f = out;
+lua_pop(m_lua_state, 1);
+  }
+
+  lua_pop(m_lua_state, 1);
+  return llvm::Error::success();
+}


Index: lldb/test/Shell/ScriptInterpreter/Lua/io.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/io.test
@@ -0,0 +1,16 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2> %t.stderr > %t.stdout
+# RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
+# RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
+script
+file = lldb.SBFile(2, "w", false)
+lldb.debugger:SetOutputFile(file)
+io.write(95000 + 126, "\n")
+quit
+script
+io.write(95000 + 14, "\n")
+# STDOUT: 95126
+# STDOUT-NOT: 95014
+# STDERR: 95014
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -30,6 +30,9 @@
   ">>> ", "..> ", true, debugger.GetUseColor(), 0,
   *this, nullptr),
 m_script_interpreter(script_interpreter) {
+llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+debugger.GetOutputFile().GetStream(),
+debugger.GetErrorFile().GetStream()));
 llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
   }
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
=

[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-21 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272297.
jackoalan added a comment.

Apply formatting fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,12 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static const int ClassStaticConst = 8;
+CLASS-DAG: static const int ClassStaticConstexpr = 9;
+CLASS-DAG: static const float ClassStaticConstexprFloat = 10.F;
+CLASS-DAG: static const double ClassStaticConstexprDouble = 11.;
+CLASS-DAG: static const double ClassStaticConstexprLongDouble = 12.;
+CLASS-DAG: static const N0::N1::(anonymous namespace)::Enum ClassStaticConstEnum = 8;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 CLASS-DAG: {{(inline )?}}Class(N0::N1::(anonymous namespace)::Enum);
 CLASS-DAG: static {{(inline )?}}int StaticFunc(const N0::N1::Class &);
Index: lldb/test/Shell/Symbo

[Lldb-commits] [PATCH] D82273: [lldb/Lua] Use the debugger's output and error file for Lua's I/O library.

2020-06-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 272313.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82273/new/

https://reviews.llvm.org/D82273

Files:
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/test/Shell/ScriptInterpreter/Lua/io.test


Index: lldb/test/Shell/ScriptInterpreter/Lua/io.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/io.test
@@ -0,0 +1,16 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2> %t.stderr > %t.stdout
+# RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
+# RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
+script
+file = lldb.SBFile(2, "w", false)
+lldb.debugger:SetOutputFile(file)
+io.write(95000 + 126, "\n")
+quit
+script
+io.write(95000 + 14, "\n")
+# STDOUT: 95126
+# STDOUT-NOT: 95014
+# STDERR: 95014
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -30,6 +30,9 @@
   ">>> ", "..> ", true, debugger.GetUseColor(), 0,
   *this, nullptr),
 m_script_interpreter(script_interpreter) {
+llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+debugger.GetOutputFile().GetStream(),
+debugger.GetErrorFile().GetStream()));
 llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
   }
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
@@ -38,6 +38,7 @@
 
   llvm::Error Run(llvm::StringRef buffer);
   llvm::Error LoadModule(llvm::StringRef filename);
+  llvm::Error ChangeIO(FILE *out = nullptr, FILE *err = nullptr);
 
 private:
   lua_State *m_lua_state;
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -57,3 +57,38 @@
   lua_setglobal(m_lua_state, module_name.GetCString());
   return llvm::Error::success();
 }
+
+llvm::Error Lua::ChangeIO(FILE *out, FILE *err) {
+  lua_getglobal(m_lua_state, "io");
+
+  if (out) {
+lua_pushstring(m_lua_state, "stdout");
+lua_gettable(m_lua_state, -2);
+luaL_Stream *s =
+static_cast(lua_touserdata(m_lua_state, -1));
+if (!s) {
+  lua_pop(m_lua_state, 2);
+  return llvm::make_error(
+  "could not get stdout", llvm::inconvertibleErrorCode());
+}
+s->f = out;
+lua_pop(m_lua_state, 1);
+  }
+
+  if (err) {
+lua_pushstring(m_lua_state, "stderr");
+lua_gettable(m_lua_state, -2);
+luaL_Stream *s =
+static_cast(lua_touserdata(m_lua_state, -1));
+if (!s) {
+  lua_pop(m_lua_state, 2);
+  return llvm::make_error(
+  "could not get stderr", llvm::inconvertibleErrorCode());
+}
+s->f = out;
+lua_pop(m_lua_state, 1);
+  }
+
+  lua_pop(m_lua_state, 1);
+  return llvm::Error::success();
+}


Index: lldb/test/Shell/ScriptInterpreter/Lua/io.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/io.test
@@ -0,0 +1,16 @@
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2> %t.stderr > %t.stdout
+# RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
+# RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
+script
+file = lldb.SBFile(2, "w", false)
+lldb.debugger:SetOutputFile(file)
+io.write(95000 + 126, "\n")
+quit
+script
+io.write(95000 + 14, "\n")
+# STDOUT: 95126
+# STDOUT-NOT: 95014
+# STDERR: 95014
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -30,6 +30,9 @@
   ">>> ", "..> ", true, debugger.GetUseColor(), 0,
   *this, nullptr),
 m_script_interpreter(script_interpreter) {
+llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+debugger.GetOutputFile().GetStream(),
+debugger.GetErrorFile().GetStream()));
 llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
   }
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ lldb/source/Plugins/Script