[Lldb-commits] [lldb] e9c3461 - [LLDB][LoongArch] Add LoongArch ArchSpec and subtype detection

2022-11-01 Thread Weining Lu via lldb-commits

Author: Tiezhu Yang
Date: 2022-11-01T17:06:04+08:00
New Revision: e9c34618c904e0b22b6c9fec1f4a410e7484b8d3

URL: 
https://github.com/llvm/llvm-project/commit/e9c34618c904e0b22b6c9fec1f4a410e7484b8d3
DIFF: 
https://github.com/llvm/llvm-project/commit/e9c34618c904e0b22b6c9fec1f4a410e7484b8d3.diff

LOG: [LLDB][LoongArch] Add LoongArch ArchSpec and subtype detection

Define LoongArch architecture subtypes, add the LoongArch ArchSpec bits,
and inspect the ELF header to detect the right subtype based on ELF class.

Here is a simple test:

```
[loongson@linux ~]$ cat hello.c

int main()
{
printf("Hello, World!\n");
return 0;
}
[loongson@linux ~]$ clang hello.c -g -o hello
```

Without this patch:

```
[loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello
(lldb) target create "hello"
error: '/home/loongson/hello' doesn't contain any 'host' platform 
architectures: unknown
```

With this patch:

```
[loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello
(lldb) target create "hello"
Current executable set to '/home/loongson/hello' (loongarch64).
(lldb) run
Process 735167 launched: '/home/loongson/hello' (loongarch64)
Hello, World!
Process 735167 exited with status = 0 (0x)
(lldb) quit
[loongson@linux ~]$ llvm-project/llvm/build/bin/llvm-lit 
llvm-project/lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml
llvm-lit: /home/loongson/llvm-project/llvm/utils/lit/lit/llvm/config.py:456: 
note: using clang: /home/loongson/llvm-project/llvm/build/bin/clang
-- Testing: 1 tests, 1 workers --
PASS: lldb-shell :: ObjectFile/ELF/loongarch-arch.yaml (1 of 1)

Testing Time: 0.09s
  Passed: 1
```

Reviewed By: SixWeining, xen0n, DavidSpickett

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

Added: 
lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml

Modified: 
lldb/include/lldb/Utility/ArchSpec.h
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/source/Utility/ArchSpec.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/ArchSpec.h 
b/lldb/include/lldb/Utility/ArchSpec.h
index ae210a6d7bf17..371607175b1dd 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -108,6 +108,12 @@ class ArchSpec {
 eRISCVSubType_riscv64,
   };
 
+  enum LoongArchSubType {
+eLoongArchSubType_unknown,
+eLoongArchSubType_loongarch32,
+eLoongArchSubType_loongarch64,
+  };
+
   enum Core {
 eCore_arm_generic,
 eCore_arm_armv4,
@@ -204,6 +210,9 @@ class ArchSpec {
 eCore_riscv32,
 eCore_riscv64,
 
+eCore_loongarch32,
+eCore_loongarch64,
+
 eCore_uknownMach32,
 eCore_uknownMach64,
 

diff  --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index af1b0930c1b7f..cf1b375001d62 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -320,6 +320,18 @@ static uint32_t ppc64VariantFromElfFlags(const 
elf::ELFHeader &header) {
 return ArchSpec::eCore_ppc64_generic;
 }
 
+static uint32_t loongarchVariantFromElfFlags(const elf::ELFHeader &header) {
+  uint32_t fileclass = header.e_ident[EI_CLASS];
+  switch (fileclass) {
+  case llvm::ELF::ELFCLASS32:
+return ArchSpec::eLoongArchSubType_loongarch32;
+  case llvm::ELF::ELFCLASS64:
+return ArchSpec::eLoongArchSubType_loongarch64;
+  default:
+return ArchSpec::eLoongArchSubType_unknown;
+  }
+}
+
 static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
   if (header.e_machine == llvm::ELF::EM_MIPS)
 return mipsVariantFromElfFlags(header);
@@ -327,6 +339,8 @@ static uint32_t subTypeFromElfHeader(const elf::ELFHeader 
&header) {
 return ppc64VariantFromElfFlags(header);
   else if (header.e_machine == llvm::ELF::EM_RISCV)
 return riscvVariantFromElfFlags(header);
+  else if (header.e_machine == llvm::ELF::EM_LOONGARCH)
+return loongarchVariantFromElfFlags(header);
 
   return LLDB_INVALID_CPUTYPE;
 }

diff  --git a/lldb/source/Utility/ArchSpec.cpp 
b/lldb/source/Utility/ArchSpec.cpp
index 0850e49b87307..126bedc209232 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -220,6 +220,11 @@ static const CoreDefinition g_core_definitions[] = {
 {eByteOrderLittle, 8, 2, 4, llvm::Triple::riscv64, ArchSpec::eCore_riscv64,
  "riscv64"},
 
+{eByteOrderLittle, 4, 4, 4, llvm::Triple::loongarch32,
+ ArchSpec::eCore_loongarch32, "loongarch32"},
+{eByteOrderLittle, 8, 4, 4, llvm::Triple::loongarch64,
+ ArchSpec::eCore_loongarch64, "loongarch64"},
+
 {eByteOrderLittle, 4, 4, 4, llvm::Triple::UnknownArch,
  ArchSpec::eCore_uknownMach32, "unknown-mach-32"},
 {eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch,
@@ -406,6 +411,12 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
  ArchSpec::eRISCVSubType_riscv32, 0xu, 0xu

[Lldb-commits] [PATCH] D137057: [LLDB][LoongArch] Add LoongArch ArchSpec and subtype detection

2022-11-01 Thread Lu Weining via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9c34618c904: [LLDB][LoongArch] Add LoongArch ArchSpec and 
subtype detection (authored by seehearfeel, committed by SixWeining).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137057

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml

Index: lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml
@@ -0,0 +1,24 @@
+# RUN: yaml2obj --docnum=1 %s > %t32
+# RUN: yaml2obj --docnum=2 %s > %t64
+# RUN: lldb-test object-file %t32 | FileCheck --check-prefix=CHECK-LA32 %s
+# RUN: lldb-test object-file %t64 | FileCheck --check-prefix=CHECK-LA64 %s
+
+# CHECK-LA32: Architecture: loongarch32--
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_LOONGARCH
+...
+
+# CHECK-LA64: Architecture: loongarch64--
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_LOONGARCH
+...
Index: lldb/source/Utility/ArchSpec.cpp
===
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -220,6 +220,11 @@
 {eByteOrderLittle, 8, 2, 4, llvm::Triple::riscv64, ArchSpec::eCore_riscv64,
  "riscv64"},
 
+{eByteOrderLittle, 4, 4, 4, llvm::Triple::loongarch32,
+ ArchSpec::eCore_loongarch32, "loongarch32"},
+{eByteOrderLittle, 8, 4, 4, llvm::Triple::loongarch64,
+ ArchSpec::eCore_loongarch64, "loongarch64"},
+
 {eByteOrderLittle, 4, 4, 4, llvm::Triple::UnknownArch,
  ArchSpec::eCore_uknownMach32, "unknown-mach-32"},
 {eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch,
@@ -406,6 +411,12 @@
  ArchSpec::eRISCVSubType_riscv32, 0xu, 0xu}, // riscv32
 {ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV,
  ArchSpec::eRISCVSubType_riscv64, 0xu, 0xu}, // riscv64
+{ArchSpec::eCore_loongarch32, llvm::ELF::EM_LOONGARCH,
+ ArchSpec::eLoongArchSubType_loongarch32, 0xu,
+ 0xu}, // loongarch32
+{ArchSpec::eCore_loongarch64, llvm::ELF::EM_LOONGARCH,
+ ArchSpec::eLoongArchSubType_loongarch64, 0xu,
+ 0xu}, // loongarch64
 };
 
 static const ArchDefinition g_elf_arch_def = {
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -320,6 +320,18 @@
 return ArchSpec::eCore_ppc64_generic;
 }
 
+static uint32_t loongarchVariantFromElfFlags(const elf::ELFHeader &header) {
+  uint32_t fileclass = header.e_ident[EI_CLASS];
+  switch (fileclass) {
+  case llvm::ELF::ELFCLASS32:
+return ArchSpec::eLoongArchSubType_loongarch32;
+  case llvm::ELF::ELFCLASS64:
+return ArchSpec::eLoongArchSubType_loongarch64;
+  default:
+return ArchSpec::eLoongArchSubType_unknown;
+  }
+}
+
 static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
   if (header.e_machine == llvm::ELF::EM_MIPS)
 return mipsVariantFromElfFlags(header);
@@ -327,6 +339,8 @@
 return ppc64VariantFromElfFlags(header);
   else if (header.e_machine == llvm::ELF::EM_RISCV)
 return riscvVariantFromElfFlags(header);
+  else if (header.e_machine == llvm::ELF::EM_LOONGARCH)
+return loongarchVariantFromElfFlags(header);
 
   return LLDB_INVALID_CPUTYPE;
 }
Index: lldb/include/lldb/Utility/ArchSpec.h
===
--- lldb/include/lldb/Utility/ArchSpec.h
+++ lldb/include/lldb/Utility/ArchSpec.h
@@ -108,6 +108,12 @@
 eRISCVSubType_riscv64,
   };
 
+  enum LoongArchSubType {
+eLoongArchSubType_unknown,
+eLoongArchSubType_loongarch32,
+eLoongArchSubType_loongarch64,
+  };
+
   enum Core {
 eCore_arm_generic,
 eCore_arm_armv4,
@@ -204,6 +210,9 @@
 eCore_riscv32,
 eCore_riscv64,
 
+eCore_loongarch32,
+eCore_loongarch64,
+
 eCore_uknownMach32,
 eCore_uknownMach64,
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137045: [lldb] Don't crash when printing static enum members with bool as underlying type

2022-11-01 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:7612
+  ->getIntegerType()
+  ->isSpecificBuiltinType(BuiltinType::Bool)) &&
  "only boolean supported");

aeubanks wrote:
> DavidSpickett wrote:
> > Can you call `TypeSystemClang::IsBooleanType` from here instead?
> better?
Much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137045

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 6c89956 - Add formatting support for VSCode logpoints message

2022-11-01 Thread Jeffrey Tan via lldb-commits

Author: Jeffrey Tan
Date: 2022-11-01T08:43:30-07:00
New Revision: 6c8995649afac04a9eb0e71affd997e493c9b93a

URL: 
https://github.com/llvm/llvm-project/commit/6c8995649afac04a9eb0e71affd997e493c9b93a
DIFF: 
https://github.com/llvm/llvm-project/commit/6c8995649afac04a9eb0e71affd997e493c9b93a.diff

LOG: Add formatting support for VSCode logpoints message

https://reviews.llvm.org/D127702 adds the initial logpoints support in
lldb-vscode. This patch further improves it by:
1. Adding a newline at the end of each log message
2. Support most of the format specifiers like \t, \n, \x etc..

The implementation is borrowed from FormatEntity::ParseInternal(). Future
patch should merge these two implementations.

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

Added: 


Modified: 
lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
lldb/tools/lldb-vscode/BreakpointBase.cpp
lldb/tools/lldb-vscode/BreakpointBase.h

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py 
b/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
index a63ea01384c2d..9f47d3c07ae9f 100644
--- a/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
+++ b/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
@@ -49,8 +49,7 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-# Trailing newline is needed for splitlines()
-logMessage = logMessage_prefix + "{i + 3}\n"
+logMessage = logMessage_prefix + "{i + 3}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -109,8 +108,7 @@ def test_logmessage_advanced(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-# Trailing newline is needed for splitlines()
-logMessage = logMessage_prefix + "{int y = 0; if (i % 3 == 0) { y = i 
+ 3;} else {y = i * 3;} y}\n"
+logMessage = logMessage_prefix + "{int y = 0; if (i % 3 == 0) { y = i 
+ 3;} else {y = i * 3;} y}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -138,3 +136,130 @@ def test_logmessage_advanced(self):
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3 if idx % 3 == 0 else idx * 3
 self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+
+@skipIfWindows
+@skipIfRemote
+def test_logmessage_format(self):
+'''
+Tests breakpoint logmessage functionality with format.
+'''
+before_loop_line = line_number('main.cpp', '// before loop')
+loop_line = line_number('main.cpp', '// break loop')
+after_loop_line = line_number('main.cpp', '// after loop')
+
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+
+# Set a breakpoint at a line before loop
+before_loop_breakpoint_ids = self.set_source_breakpoints(
+self.main_path,
+[before_loop_line])
+self.assertEquals(len(before_loop_breakpoint_ids), 1, "expect one 
breakpoint")
+
+self.vscode.request_continue()
+
+# Verify we hit the breakpoint before loop line
+self.verify_breakpoint_hit(before_loop_breakpoint_ids)
+
+# Swallow old console output
+self.get_console()
+
+# Set two breakpoints:
+# 1. First at the loop line with logMessage
+# 2. Second guard breakpoint at a line after loop
+logMessage_prefix = "This is log message for -- "
+logMessage_with_format = "part1\tpart2\bpart3\x64part4"
+logMessage_with_format_raw = r"part1\tpart2\bpart3\x64part4"
+logMessage = logMessage_prefix + logMessage_with_format_raw + "{i - 1}"
+[loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
+self.main_path,
+[loop_line, after_loop_line],
+[{'logMessage': logMessage}, {}]
+)
+
+# Continue to trigger the breakpoint with log messages
+self.vscode.request_continue()
+
+# Verify we hit the breakpoint after loop line
+self.verify_breakpoint_hit([post_loop_breakpoint_id])
+
+output = self.get_console()
+lines = output.splitlines()
+logMessage_output = []
+for line in lines:
+if line.startswith(logMessage_prefix):
+logMessage_output.append(line)
+
+# Verify logMessage count
+loop_count = 10
+ 

[Lldb-commits] [PATCH] D136697: Add formatting support for VSCode logpoints message

2022-11-01 Thread jeffrey tan via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c8995649afa: Add formatting support for VSCode logpoints 
message (authored by yinghuitan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136697

Files:
  lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
  lldb/tools/lldb-vscode/BreakpointBase.cpp
  lldb/tools/lldb-vscode/BreakpointBase.h

Index: lldb/tools/lldb-vscode/BreakpointBase.h
===
--- lldb/tools/lldb-vscode/BreakpointBase.h
+++ lldb/tools/lldb-vscode/BreakpointBase.h
@@ -22,7 +22,7 @@
   struct LogMessagePart {
 LogMessagePart(llvm::StringRef text, bool is_expr)
 : text(text), is_expr(is_expr) {}
-llvm::StringRef text;
+std::string text;
 bool is_expr;
   };
   // An optional expression for conditional breakpoints.
@@ -45,6 +45,13 @@
   void SetHitCondition();
   void SetLogMessage();
   void UpdateBreakpoint(const BreakpointBase &request_bp);
+
+  // Format \param text and return formatted text in \param formatted.
+  // \return any formatting failures.
+  lldb::SBError FormatLogText(llvm::StringRef text, std::string &formatted);
+  lldb::SBError AppendLogMessagePart(llvm::StringRef part, bool is_expr);
+  void NotifyLogMessageError(llvm::StringRef error);
+
   static const char *GetBreakpointLabel();
   static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process,
 lldb::SBThread &thread,
Index: lldb/tools/lldb-vscode/BreakpointBase.cpp
===
--- lldb/tools/lldb-vscode/BreakpointBase.cpp
+++ lldb/tools/lldb-vscode/BreakpointBase.cpp
@@ -25,6 +25,144 @@
 bp.SetIgnoreCount(hitCount - 1);
 }
 
+lldb::SBError BreakpointBase::AppendLogMessagePart(llvm::StringRef part,
+   bool is_expr) {
+  if (is_expr) {
+logMessageParts.emplace_back(part, is_expr);
+  } else {
+std::string formatted;
+lldb::SBError error = FormatLogText(part, formatted);
+if (error.Fail())
+  return error;
+logMessageParts.emplace_back(formatted, is_expr);
+  }
+  return lldb::SBError();
+}
+
+// TODO: consolidate this code with the implementation in
+// FormatEntity::ParseInternal().
+lldb::SBError BreakpointBase::FormatLogText(llvm::StringRef text,
+std::string &formatted) {
+  lldb::SBError error;
+  while (!text.empty()) {
+size_t backslash_pos = text.find_first_of('\\');
+if (backslash_pos == std::string::npos) {
+  formatted += text.str();
+  return error;
+}
+
+formatted += text.substr(0, backslash_pos).str();
+// Skip the characters before and including '\'.
+text = text.drop_front(backslash_pos + 1);
+
+if (text.empty()) {
+  error.SetErrorString(
+  "'\\' character was not followed by another character");
+  return error;
+}
+
+const char desens_char = text[0];
+text = text.drop_front(); // Skip the desensitized char character
+switch (desens_char) {
+case 'a':
+  formatted.push_back('\a');
+  break;
+case 'b':
+  formatted.push_back('\b');
+  break;
+case 'f':
+  formatted.push_back('\f');
+  break;
+case 'n':
+  formatted.push_back('\n');
+  break;
+case 'r':
+  formatted.push_back('\r');
+  break;
+case 't':
+  formatted.push_back('\t');
+  break;
+case 'v':
+  formatted.push_back('\v');
+  break;
+case '\'':
+  formatted.push_back('\'');
+  break;
+case '\\':
+  formatted.push_back('\\');
+  break;
+case '0':
+  // 1 to 3 octal chars
+  {
+if (text.empty()) {
+  error.SetErrorString("missing octal number following '\\0'");
+  return error;
+}
+
+// Make a string that can hold onto the initial zero char, up to 3
+// octal digits, and a terminating NULL.
+char oct_str[5] = {0, 0, 0, 0, 0};
+
+size_t i;
+for (i = 0;
+ i < text.size() && i < 4 && (text[i] >= '0' && text[i] <= '7');
+ ++i) {
+  oct_str[i] = text[i];
+}
+
+text = text.drop_front(i);
+unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
+if (octal_value <= UINT8_MAX) {
+  formatted.push_back((char)octal_value);
+} else {
+  error.SetErrorString("octal number is larger than a single byte");
+  return error;
+}
+  }
+  break;
+
+case 'x': {
+  if (text.empty()) {
+error.SetErrorString("missing hex number following '\\x'");
+return error;
+  }
+  // hex number in the text
+  if (isxdigit(text[0])) {
+// Make a string that can hold onto two hex chars plus a
+// NULL terminator
+ 

[Lldb-commits] [PATCH] D135622: [lldb] Add a "diagnostics dump" command

2022-11-01 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

The newly added test is failing on the windows buildbot: 
https://lab.llvm.org/buildbot/#/builders/83/builds/25446


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135622

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] a715b1b - [lldb] Don't crash when printing static enum members with bool as underlying type

2022-11-01 Thread Arthur Eubanks via lldb-commits

Author: Arthur Eubanks
Date: 2022-11-01T09:28:54-07:00
New Revision: a715b1bde91077b313b9c36d9ecbc0c83a0edac2

URL: 
https://github.com/llvm/llvm-project/commit/a715b1bde91077b313b9c36d9ecbc0c83a0edac2
DIFF: 
https://github.com/llvm/llvm-project/commit/a715b1bde91077b313b9c36d9ecbc0c83a0edac2.diff

LOG: [lldb] Don't crash when printing static enum members with bool as 
underlying type

Undoes a lot of the code added in D135169 to piggyback off of the enum logic in 
`TypeSystemClang::SetIntegerInitializerForVariable()`.

Fixes #58383.

Reviewed By: DavidSpickett

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

Added: 


Modified: 
lldb/include/lldb/Symbol/CompilerType.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerType.cpp

lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
lldb/test/API/lang/cpp/const_static_integral_member/main.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/CompilerType.h 
b/lldb/include/lldb/Symbol/CompilerType.h
index ef9f283cefec..1ad9d6ae4c40 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -121,8 +121,6 @@ class CompilerType {
 
   bool IsIntegerOrEnumerationType(bool &is_signed) const;
 
-  bool IsBooleanType() const;
-
   bool IsPolymorphicClass() const;
 
   /// \param target_typeCan pass nullptr.

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h 
b/lldb/include/lldb/Symbol/TypeSystem.h
index 93959f4596d6..fd31b130c4ff 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -178,8 +178,6 @@ class TypeSystem : public PluginInterface {
 return false;
   }
 
-  virtual bool IsBooleanType(lldb::opaque_compiler_type_t type) = 0;
-
   virtual bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) = 0;
 
   virtual bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 6e76203dcf94..037e11895b10 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2820,12 +2820,7 @@ void DWARFASTParserClang::ParseSingleMember(
 return;
   }
 
-  if (ct.IsBooleanType())
-TypeSystemClang::SetBoolInitializerForVariable(
-v, !const_value_or_err->isZero());
-  else
-TypeSystemClang::SetIntegerInitializerForVariable(v,
-  *const_value_or_err);
+  TypeSystemClang::SetIntegerInitializerForVariable(v, 
*const_value_or_err);
 }
 return;
   }

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 4fa3c65be739..5175ad81606d 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3226,20 +3226,6 @@ bool 
TypeSystemClang::IsIntegerType(lldb::opaque_compiler_type_t type,
   return false;
 }
 
-bool TypeSystemClang::IsBooleanType(lldb::opaque_compiler_type_t type) {
-  if (!type)
-return false;
-
-  clang::QualType qual_type(GetCanonicalQualType(type));
-  const clang::BuiltinType *builtin_type =
-  
llvm::dyn_cast(qual_type->getCanonicalTypeInternal());
-
-  if (!builtin_type)
-return false;
-
-  return builtin_type->isBooleanType();
-}
-
 bool TypeSystemClang::IsEnumerationType(lldb::opaque_compiler_type_t type,
 bool &is_signed) {
   if (type) {
@@ -7593,18 +7579,6 @@ clang::VarDecl *TypeSystemClang::AddVariableToRecordType(
   return var_decl;
 }
 
-void TypeSystemClang::SetBoolInitializerForVariable(VarDecl *var, bool value) {
-  assert(!var->hasInit() && "variable already initialized");
-
-  QualType qt = var->getType();
-  assert(qt->isSpecificBuiltinType(BuiltinType::Bool) &&
- "only boolean supported");
-
-  clang::ASTContext &ast = var->getASTContext();
-  var->setInit(CXXBoolLiteralExpr::Create(ast, value, qt.getUnqualifiedType(),
-  SourceLocation()));
-}
-
 void TypeSystemClang::SetIntegerInitializerForVariable(
 VarDecl *var, const llvm::APInt &init_value) {
   assert(!var->hasInit() && "variable already initialized");
@@ -7619,8 +7593,15 @@ void TypeSystemClang::SetIntegerInitializerForVariable(
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
-  var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
-  Sour

[Lldb-commits] [PATCH] D137045: [lldb] Don't crash when printing static enum members with bool as underlying type

2022-11-01 Thread Arthur Eubanks via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa715b1bde910: [lldb] Don't crash when printing static 
enum members with bool as underlying… (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137045

Files:
  lldb/include/lldb/Symbol/CompilerType.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/source/Symbol/CompilerType.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp

Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -5,6 +5,11 @@
   enum_case2 = 2,
 };
 
+enum EnumBool : bool {
+  enum_bool_case1 = false,
+  enum_bool_case2 = true,
+};
+
 enum class ScopedEnum {
   scoped_enum_case1 = 1,
   scoped_enum_case2 = 2,
@@ -51,6 +56,7 @@
   const static auto wchar_min = std::numeric_limits::min();
 
   const static Enum enum_val = enum_case2;
+  const static EnumBool enum_bool_val = enum_bool_case2;
   const static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
   const static ScopedEnum not_enumerator_scoped_enum_val = static_cast(5);
   const static ScopedEnum not_enumerator_scoped_enum_val_2 =
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -57,6 +57,8 @@
 
 # Test an unscoped enum.
 self.expect_expr("A::enum_val", result_value="enum_case2")
+# Test an unscoped enum with bool as the underlying type.
+self.expect_expr("A::enum_bool_val", result_value="enum_bool_case2")
 
 # Test a scoped enum.
 self.expect_expr("A::scoped_enum_val", result_value="scoped_enum_case2")
Index: lldb/source/Symbol/CompilerType.cpp
===
--- lldb/source/Symbol/CompilerType.cpp
+++ lldb/source/Symbol/CompilerType.cpp
@@ -154,12 +154,6 @@
   return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
 }
 
-bool CompilerType::IsBooleanType() const {
-  if (IsValid())
-return m_type_system->IsBooleanType(m_type);
-  return false;
-}
-
 bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
   if (IsValid()) {
 return m_type_system->IsPointerType(m_type, pointee_type);
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -592,8 +592,6 @@
   bool IsEnumerationType(lldb::opaque_compiler_type_t type,
  bool &is_signed) override;
 
-  bool IsBooleanType(lldb::opaque_compiler_type_t type) override;
-
   bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) override;
 
   static bool IsObjCClassType(const CompilerType &type);
@@ -863,8 +861,6 @@
   static void SetIntegerInitializerForVariable(clang::VarDecl *var,
const llvm::APInt &init_value);
 
-  static void SetBoolInitializerForVariable(clang::VarDecl *var, bool value);
-
   /// Initializes a variable with a floating point value.
   /// \param var The variable to initialize. Must not already have an
   ///initializer and must have a floating point type.
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3226,20 +3226,6 @@
   return false;
 }
 
-bool TypeSystemClang::IsBooleanType(lldb::opaque_compiler_type_t type) {
-  if (!type)
-return false;
-
-  clang::QualType qual_type(GetCanonicalQualType(type));
-  const clang::BuiltinType *builtin_type =
-  llvm::dyn_cast(qual_type->getCanonicalTypeInternal());
-
-  if (!builtin_type)
-return false;
-
-  return builtin_type->isBooleanType();
-}
-
 bool TypeSystemClang::IsEnumerationType(lldb::opaque_compiler_type_t type,
 bool &is_signed) {
   if (type) {
@@ -7593,18 +7579,6 @@
   return var_decl;
 }
 
-void TypeSystemClang::SetBoolInitializerForVariable(VarDecl *var, bool value) {
-  assert(!var->hasInit() && "variable already i

[Lldb-commits] [PATCH] D135616: [lldb/Utility] Fix StructuredData::ParseJSONValue for null items

2022-11-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135616

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D135547: [lldb/Utility] Add GetDescription(Stream&) to StructureData::*

2022-11-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

The change looks good but I'd like to see a few more unit tests to cover edge 
cases (empty array, dict, etc),




Comment at: lldb/unittests/Utility/StructuredDataTest.cpp:40-43
+  const std::string expected =
+  "  Array :\n3.14\n1.234000  \n  Dictionary :\nFalseBool "
+  ": False  \n  Integer : 1\n  Null : NULL\n  String : value\n  TrueBool : 
"
+  "True";

Maybe use a string literal to make it clear what the formatted text looks like?


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

https://reviews.llvm.org/D135547

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137137: [lldb/Interpreter] Open saved transcript in GUI Editor

2022-11-01 Thread Dave Lee via Phabricator via lldb-commits
kastiglione accepted this revision.
kastiglione added a comment.

looks good


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

https://reviews.llvm.org/D137137

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D135616: [lldb/Utility] Fix StructuredData::ParseJSONValue for null items

2022-11-01 Thread Dave Lee via Phabricator via lldb-commits
kastiglione accepted this revision.
kastiglione added a comment.

+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135616

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: clayborg, JDevlieghere, aprantl.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Context: I plan on using this change primarily downstream in the apple fork of 
llvm to track swift module loading time.

The idea is that TypeSystems from modules can self-report statistics when 
performing the statistics dump of a module.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137191

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/source/Core/Module.cpp
  lldb/source/Symbol/TypeSystem.cpp
  lldb/source/Target/Statistics.cpp


Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -256,7 +256,20 @@
 debug_parse_time += module_stat.debug_parse_time;
 debug_index_time += module_stat.debug_index_time;
 debug_info_size += module_stat.debug_info_size;
-json_modules.emplace_back(module_stat.ToJSON());
+json::Value module_stat_json = module_stat.ToJSON();
+module->ForEachTypeSystem([&](TypeSystem *ts) {
+  if (ts) {
+json::Object *module_stat_obj = module_stat_json.getAsObject();
+if (!module_stat_obj)
+  return false;
+auto stats = ts->ReportStatistics();
+if (stats.hasValue()) {
+  module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue());
+}
+  }
+  return true;
+});
+json_modules.emplace_back(module_stat_json);
   }
 
   ConstStringStats const_string_stats;
Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symbol/TypeSystem.cpp
+++ lldb/source/Symbol/TypeSystem.cpp
@@ -178,6 +178,10 @@
   return {};
 }
 
+llvm::Optional TypeSystem::ReportStatistics() {
+  return llvm::None;
+}
+
 #pragma mark TypeSystemMap
 
 TypeSystemMap::TypeSystemMap() : m_mutex(), m_map() {}
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -369,6 +369,11 @@
   return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
 }
 
+void Module::ForEachTypeSystem(
+std::function const &callback) {
+  m_type_system_map.ForEach(callback);
+}
+
 void Module::ParseAllDebugSymbols() {
   std::lock_guard guard(m_mutex);
   size_t num_comp_units = GetNumCompileUnits();
Index: lldb/include/lldb/Symbol/TypeSystem.h
===
--- lldb/include/lldb/Symbol/TypeSystem.h
+++ lldb/include/lldb/Symbol/TypeSystem.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/JSON.h"
 
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Expression/Expression.h"
@@ -510,6 +511,8 @@
   // meaningless type itself, instead preferring to use the dynamic type
   virtual bool IsMeaninglessWithoutDynamicResolution(void *type);
 
+  virtual llvm::Optional ReportStatistics();
+
 protected:
   SymbolFile *m_sym_file = nullptr;
 };
Index: lldb/include/lldb/Core/Module.h
===
--- lldb/include/lldb/Core/Module.h
+++ lldb/include/lldb/Core/Module.h
@@ -814,6 +814,8 @@
   llvm::Expected
   GetTypeSystemForLanguage(lldb::LanguageType language);
 
+  void ForEachTypeSystem(std::function const &callback);
+
   // Special error functions that can do printf style formatting that will
   // prepend the message with something appropriate for this module (like the
   // architecture, path and object name (if any)). This centralizes code so


Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -256,7 +256,20 @@
 debug_parse_time += module_stat.debug_parse_time;
 debug_index_time += module_stat.debug_index_time;
 debug_info_size += module_stat.debug_info_size;
-json_modules.emplace_back(module_stat.ToJSON());
+json::Value module_stat_json = module_stat.ToJSON();
+module->ForEachTypeSystem([&](TypeSystem *ts) {
+  if (ts) {
+json::Object *module_stat_obj = module_stat_json.getAsObject();
+if (!module_stat_obj)
+  return false;
+auto stats = ts->ReportStatistics();
+if (stats.hasValue()) {
+  module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue());
+}
+  }
+  return true;
+});
+json_modules.emplace_back(module_stat_json);
   }
 
   ConstStringStats const_string_stats;
Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symb

[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

I have a pull request to apple's fork to show how this is used for swift: 
https://github.com/apple/llvm-project/pull/5540

I primarily wanted this portion to be upstream so that the patch is easier to 
maintain downstream, but it could be useful for clang-produced TypeSystems as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137191

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/source/Target/Statistics.cpp:258
 debug_index_time += module_stat.debug_index_time;
 debug_info_size += module_stat.debug_info_size;
+json::Value module_stat_json = module_stat.ToJSON();

Seems like we should be populating module_stat to contain a dictionary of 
TypeSystem plug-in name to stats. So adding something to the ModuleStats 
structure like:

```
std::map type_system_stats;
```
Then the loop below would look like:
```
module->ForEachTypeSystem([&](TypeSystem *ts) {
  if (auto stats = ts->ReportStatistics())
module_stat. type_system_stats[ts->GetPluginName()] = stats.value();
  return true;
});
```
We currently don't have each type system reporting a plug-in name, but that 
would be easy to add to the two TypeSystem plug-ins. ModuleStat::ToJSON() would 
need to be modified to emit a "typeSystemInfo" only if there are any stats in 
the "module_stat.type_system_stats" member.



Comment at: lldb/source/Target/Statistics.cpp:266
+auto stats = ts->ReportStatistics();
+if (stats.hasValue()) {
+  module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue());

Remove {} for single line if statement per llvm coding guidelines



Comment at: lldb/source/Target/Statistics.cpp:267
+if (stats.hasValue()) {
+  module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue());
+}

We have been doing camel case, but starting with lower case. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137191

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Thorsten via Phabricator via lldb-commits
tschuett added inline comments.



Comment at: lldb/include/lldb/Core/Module.h:817
 
+  void ForEachTypeSystem(std::function const &callback);
+

Maybe `llvm::function_ref`?
https://llvm.org/doxygen/classllvm_1_1function__ref_3_01Ret_07Params_8_8_8_08_4.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137191

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D136958: [lldb] Document QSetDetachOnError packet

2022-11-01 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve added a comment.

In D136958#3896820 , @jasonmolenda 
wrote:

> debugserver often can't tell the difference between these (when you run a 
> process on a local system, lldb actually does the posix_spawn and then tells 
> debugserver to attach to it).

That makes a lot of sense!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136958

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D136958: [lldb] Document QSetDetachOnError packet

2022-11-01 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c9afbb76f82: [lldb] Document QSetDetachOnError packet 
(authored by fdeazeve).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136958

Files:
  lldb/docs/lldb-gdb-remote.txt


Index: lldb/docs/lldb-gdb-remote.txt
===
--- lldb/docs/lldb-gdb-remote.txt
+++ lldb/docs/lldb-gdb-remote.txt
@@ -2136,3 +2136,20 @@
 { "port": 5432 },
 { "socket_name": "foo" }
 ]
+
+//--
+// "QSetDetachOnError"
+//
+// BRIEF
+//  Sets what the server should do when the communication channel with LLDB
+//  goes down. Either kill the inferior process (0) or remove breakpoints and
+//  detach (1).
+//
+// PRIORITY TO IMPLEMENT
+//  Low. Only required if the target wants to keep the inferior process alive
+//  when the communication channel goes down.
+//--
+
+The data in this packet is a single a character, which should be '0' if the
+inferior process should be killed, or '1' if the server should remove all
+breakpoints and detach from the inferior.


Index: lldb/docs/lldb-gdb-remote.txt
===
--- lldb/docs/lldb-gdb-remote.txt
+++ lldb/docs/lldb-gdb-remote.txt
@@ -2136,3 +2136,20 @@
 { "port": 5432 },
 { "socket_name": "foo" }
 ]
+
+//--
+// "QSetDetachOnError"
+//
+// BRIEF
+//  Sets what the server should do when the communication channel with LLDB
+//  goes down. Either kill the inferior process (0) or remove breakpoints and
+//  detach (1).
+//
+// PRIORITY TO IMPLEMENT
+//  Low. Only required if the target wants to keep the inferior process alive
+//  when the communication channel goes down.
+//--
+
+The data in this packet is a single a character, which should be '0' if the
+inferior process should be killed, or '1' if the server should remove all
+breakpoints and detach from the inferior.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 9c9afbb - [lldb] Document QSetDetachOnError packet

2022-11-01 Thread Felipe de Azevedo Piovezan via lldb-commits

Author: Felipe de Azevedo Piovezan
Date: 2022-11-01T14:09:33-07:00
New Revision: 9c9afbb76f82004efef4bb1be843661f8d89bcaa

URL: 
https://github.com/llvm/llvm-project/commit/9c9afbb76f82004efef4bb1be843661f8d89bcaa
DIFF: 
https://github.com/llvm/llvm-project/commit/9c9afbb76f82004efef4bb1be843661f8d89bcaa.diff

LOG: [lldb] Document QSetDetachOnError packet

The packet was introduced in 106d02866d4d54b09c08e6a12915dba58e709294.

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

Added: 


Modified: 
lldb/docs/lldb-gdb-remote.txt

Removed: 




diff  --git a/lldb/docs/lldb-gdb-remote.txt b/lldb/docs/lldb-gdb-remote.txt
index 497980ed1229b..551e94d8b71ad 100644
--- a/lldb/docs/lldb-gdb-remote.txt
+++ b/lldb/docs/lldb-gdb-remote.txt
@@ -2136,3 +2136,20 @@ Example packet:
 { "port": 5432 },
 { "socket_name": "foo" }
 ]
+
+//--
+// "QSetDetachOnError"
+//
+// BRIEF
+//  Sets what the server should do when the communication channel with LLDB
+//  goes down. Either kill the inferior process (0) or remove breakpoints and
+//  detach (1).
+//
+// PRIORITY TO IMPLEMENT
+//  Low. Only required if the target wants to keep the inferior process alive
+//  when the communication channel goes down.
+//--
+
+The data in this packet is a single a character, which should be '0' if the
+inferior process should be killed, or '1' if the server should remove all
+breakpoints and detach from the inferior.



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Thorsten via Phabricator via lldb-commits
tschuett added inline comments.



Comment at: lldb/source/Target/Statistics.cpp:266
+auto stats = ts->ReportStatistics();
+if (stats.hasValue()) {
+  module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue());

clayborg wrote:
> Remove {} for single line if statement per llvm coding guidelines
I am bit confused. If `auto stats` is an `optional`. Please remove 
`.hasValue()` and replace `stats.getValue` by `*stats`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137191

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D127695: [clang] Template Specialization Resugaring - TypeDecl

2022-11-01 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov retitled this revision from "[clang] Implement Template Specialization 
Resugaring" to "[clang] Template Specialization Resugaring - TypeDecl".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 472416.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

Files:
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/Sema/Resugar/resugar-types.cpp
  libcxx/DELETE.ME
  
lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py

Index: lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
@@ -23,7 +23,7 @@
 iter_type = "std::move_iterator >"
 
 self.expect_expr("move_begin", result_type=iter_type)
-self.expect_expr("move_begin[0]", result_type="int", result_value="1")
+self.expect_expr("move_begin[0]", result_type="__libcpp_remove_reference_t<__reference>", result_value="1")
 
 self.expect_expr("move_begin + 3 == move_end", result_value="true")
 
Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D127695
Index: clang/test/Sema/Resugar/resugar-types.cpp
===
--- /dev/null
+++ clang/test/Sema/Resugar/resugar-types.cpp
@@ -0,0 +1,209 @@
+// RUN: %clang_cc1 -std=c++2b -fms-extensions -verify %s
+// expected-no-diagnostics
+
+static constexpr int alignment = 64; // Suitable large alignment.
+
+struct Baz {};
+using Bar [[gnu::aligned(alignment)]] = Baz;
+using Int [[gnu::aligned(alignment)]] = int;
+
+#define TEST(X) static_assert(alignof(X) == alignment)
+#define TEST_NOT(X) static_assert(alignof(X) != alignment)
+
+// Sanity checks.
+TEST_NOT(Baz);
+TEST(Bar);
+
+namespace t1 {
+template  struct foo { using type = T; };
+template  struct foo { using type = U; };
+
+TEST(typename foo::type);
+TEST(typename foo::type);
+} // namespace t1
+
+namespace t2 {
+template  struct foo1 { using type = T; };
+template  struct foo2 { using type = typename foo1<1, T>::type; };
+TEST(typename foo2::type);
+} // namespace t2
+
+namespace t3 {
+template  struct foo1 {
+  template  struct foo2 { using type1 = T; };
+  using type2 = typename foo2<1, int>::type1;
+};
+TEST(typename foo1::type2);
+} // namespace t3
+
+namespace t4 {
+template  struct foo {
+  template  using type1 = T;
+  using type2 = type1;
+};
+TEST(typename foo::type2);
+} // namespace t4
+
+namespace t5 {
+template  struct foo {
+  template  using type1 = U;
+  using type2 = type1<1, T>;
+};
+TEST(typename foo::type2);
+} // namespace t5
+
+namespace t6 {
+template  struct foo1 {
+  template  struct foo2 { using type = U; };
+  using type2 = typename foo2<1, T>::type;
+};
+TEST(typename foo1::type2);
+}; // namespace t6
+
+namespace t7 {
+template  struct foo {
+  template  using type1 = U;
+};
+using type2 = typename foo::template type1<1, Bar>;
+TEST(type2);
+} // namespace t7
+
+namespace t8 {
+template  struct foo {
+  using type1 = T;
+};
+template  using type2 = T;
+using type3 = typename type2, int>::type1;
+TEST(type3);
+} // namespace t8
+
+namespace t9 {
+template  struct Y {
+  using type1 = A;
+  using type2 = B;
+};
+template  using Z = Y;
+template  struct foo {
+  template  using apply = Z;
+};
+using T1 = foo::apply;
+TEST_NOT(T1::type1);
+TEST_NOT(T1::type2); // FIXME: Needs resugaring on the pattern of template type aliases.
+
+using T2 = foo::apply;
+TEST(T2::type1);
+TEST_NOT(T2::type2);
+} // namespace t9
+
+namespace t10 {
+template  struct Y {
+  using type1 = A1;
+  using type2 = A2;
+};
+template  using Z = Y;
+template  struct foo {
+  template  using bind = Z;
+};
+using T1 = foo::bind;
+TEST_NOT(T1::type1);
+TEST_NOT(T1::type2); // FIXME: Needs resugaring on the pattern of template type aliases.
+
+using T2 = foo::bind;
+TEST(T2::type1);
+TEST_NOT(T2::type2);
+} // namespace t10
+
+namespace t11 {
+template  struct A { using type1 = A2; };
+TEST(A::type1);
+} // namespace t11
+
+namespace t12 {
+template  struct W {
+  template  class TT>
+  struct X {
+using type1 = T

[Lldb-commits] [PATCH] D127695: [clang] Template Specialization Resugaring - TypeDecl

2022-11-01 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov added a comment.

In D127695#3860316 , @rjmccall wrote:

> I see, thank you. I know you've marked this a WIP, but it's always good to 
> describe these things in the patch description; that's what it's for.

Done! I have also removed the WIP. While there is still ongoing work with 
precursors of this patch and it might reflect in some changes here, I don't 
think anything significant will change, and this is good for review now.

> This is quite exciting!  Thank you for looking into this.

Thanks!

> I think you could usefully be much more incremental here.  Obviously the 
> resugaring transform is one big piece, but it's likely that you could 
> usefully roll out the applications of it one at a time and see some 
> incremental improvements, and it would be a lot easier for us to then review 
> the changes you're needing to make to see why you're making them.  That 
> shouldn't make it any more difficult to measure holistic things like the 
> overall compile-time impact of resugaring — it's all filtering through a 
> single place, so you ought to be able to easily disable it there.  You could 
> also disable it by default by leaving it behind a `-cc1` flag that you only 
> enable in your tests.  That would let you actually land the work 
> incrementally, which I would have no objection to.

Done.

I have split the resugaring applications in three parts for now.

I consider this patch and the next one to be a single application of the 
transform, each.

re your concerns and earlier question from @davrec regarding performance, right 
now we are regressing a couple of test cases in llvm-compile-time-tracker by 
about 1%:

Commit   kimwitu++Bullet  
tramp3d-v4  7zip geomean
  C 29cd42cab9   49485M (+0.23%)  112040M (+0.05%)
109687M (+0.46%)227685M (+0.17%) 73023M (+0.10%)
  C 252f292ed2   49371M (+0.50%)  111980M (+0.11%)
109182M (+0.50%)227293M (+0.98%) 72952M (+0.21%)

Showing this patch on the top, and the previous one on the bottom. I have 
omitted most test cases as they show essentially no difference.
These are number for optimized (O3 
) builds.

So most of our hit is coming from the previous patch, which I am working to 
improve. And I think there is still a lot of things that can be tried on this 
patch to get that number even lower.

Applying all the rest of the resugaring patches, up to the third one, increases 
the worst case by an additional 0.25%. Most test cases still show essentially 
no change.

You can see these numbers at 
http://llvm-compile-time-tracker.com/?config=NewPM-O3&stat=instructions%3Au&remote=mizvekov.

I am inclined to think that, for now, we will not need to offer an option to 
turn resugaring off, on performance grounds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D137217: [LTO][COFF] Use bitcode file names in lto native object file names.

2022-11-01 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu created this revision.
zequanwu added reviewers: rnk, tejohnson, mehdi_amini.
Herald added subscribers: pmatos, asb, ormris, steven_wu, hiraditya, 
arichardson, inglorion, sbc100, emaste.
Herald added a reviewer: MaskRay.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
zequanwu requested review of this revision.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits, StephenFan, 
aheejin.
Herald added projects: clang, LLDB, LLVM.

Currently the lto native object files have names like main.exe.lto.1.obj. In
PDB, those names are used as names for each compiland. Microsoft’s tool
SizeBench uses those names to present to users the size of each object files.
So, names like main.exe.lto.1.obj is not user friendly.

This patch makes the lto native object file names more readable by using
the bitcode file names as part of the file names. For example, if the input
bitcode file has path like "path/to/foo.obj", its corresponding lto native
object file path would be "path/to/main.exe.lto.foo.obj". Since the lto native
object file name only bothers PDB, this patch only changes the lld-linker's
behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137217

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/test/COFF/lto-obj-path.ll
  lld/test/COFF/pdb-thinlto.ll
  lld/test/COFF/thinlto.ll
  lld/wasm/LTO.cpp
  lldb/source/Core/DataFileCache.cpp
  llvm/include/llvm/Support/Caching.h
  llvm/lib/Debuginfod/Debuginfod.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/Caching.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -411,7 +411,8 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream = [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task,
+   Twine File) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
@@ -420,8 +421,9 @@
 return std::make_unique(std::move(S), Path);
   };
 
-  auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
-*AddStream(Task)->OS << MB->getBuffer();
+  auto AddBuffer = [&](size_t Task, Twine File,
+   std::unique_ptr MB) {
+*AddStream(Task, File)->OS << MB->getBuffer();
   };
 
   FileCache Cache;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -317,11 +317,11 @@
   if (!CurrentActivity.empty())
 OS << ' ' << CurrentActivity;
   OS << ": ";
-  
+
   DiagnosticPrinterRawOStream DP(OS);
   DI.print(DP);
   OS << '\n';
-  
+
   if (DI.getSeverity() == DS_Error)
 exit(1);
   return true;
@@ -1099,7 +1099,8 @@
 error("writing merged module failed.");
 }
 
-auto AddStream = [&](size_t Task) -> std::unique_ptr {
+auto AddStream = [&](size_t Task,
+ Twine File) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -37,7 +37,8 @@
   TempFilePrefixRef.toVector(TempFilePrefix);
   CacheDirectoryPathRef.toVector(CacheDirectoryPath);
 
-  return [=](unsigned Task, StringRef Key) -> Expected {
+  return [=](unsigned Task, StringRef Key,
+ Twine File) -> Expected {
 // This choice of file name allows the cache to be pruned (see pruneCache()
 // in include/llvm/Support/CachePruning.h).
 SmallString<64> EntryPath;
@@ -54,7 +55,7 @@
 /*RequiresNullTerminator=*/false);
   sys::fs::closeFile(*FDOrErr);
   if (MBOrErr) {
-AddBuffer(Task, std::move(*MBOrErr));
+AddBuffer(Task, File, std::move(*MBOrErr));
 return AddStreamFn();
   }
   EC = MBOrErr.getError();
@@ -77,14 +78,15 @@
 struct CacheStream : CachedFileStream {
   AddBufferFn AddBuffer;
   sys::fs::TempFile TempFile;
+  std::string ModuleName;
   unsigned Task;
 
   CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer,
   sys::fs::TempFile TempFile, std::string EntryPath,
-  unsigned Task)
+  std::string ModuleName, unsigned Task)
   : CachedFileStream(std::move(OS), std::move(EntryPath)),
 AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
-Task(Task) {}
+ 

[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 472468.
bulbazord added a comment.

Address feedback


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

https://reviews.llvm.org/D137191

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/include/lldb/Target/Statistics.h
  lldb/source/Core/Module.cpp
  lldb/source/Symbol/TypeSystem.cpp
  lldb/source/Target/Statistics.cpp

Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -75,6 +75,17 @@
   symfile_ids.emplace_back(symfile_id);
 module.try_emplace("symbolFileModuleIdentifiers", std::move(symfile_ids));
   }
+
+  if (!type_system_stats.empty()) {
+json::Array type_systems;
+for (const auto &entry : type_system_stats) {
+  json::Object obj;
+  obj.try_emplace(entry.first().str(), entry.second);
+  type_systems.emplace_back(std::move(obj));
+}
+module.try_emplace("typeSystemInfo", std::move(type_systems));
+  }
+
   return module;
 }
 
@@ -256,6 +267,11 @@
 debug_parse_time += module_stat.debug_parse_time;
 debug_index_time += module_stat.debug_index_time;
 debug_info_size += module_stat.debug_info_size;
+module->ForEachTypeSystem([&](TypeSystem *ts) {
+  if (auto stats = ts->ReportStatistics())
+module_stat.type_system_stats.insert({ts->GetPluginName(), *stats});
+  return true;
+});
 json_modules.emplace_back(module_stat.ToJSON());
   }
 
Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symbol/TypeSystem.cpp
+++ lldb/source/Symbol/TypeSystem.cpp
@@ -178,6 +178,10 @@
   return {};
 }
 
+llvm::Optional TypeSystem::ReportStatistics() {
+  return llvm::None;
+}
+
 #pragma mark TypeSystemMap
 
 TypeSystemMap::TypeSystemMap() : m_mutex(), m_map() {}
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -369,6 +369,11 @@
   return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
 }
 
+void Module::ForEachTypeSystem(
+llvm::function_ref const &callback) {
+  m_type_system_map.ForEach(callback);
+}
+
 void Module::ParseAllDebugSymbols() {
   std::lock_guard guard(m_mutex);
   size_t num_comp_units = GetNumCompileUnits();
Index: lldb/include/lldb/Target/Statistics.h
===
--- lldb/include/lldb/Target/Statistics.h
+++ lldb/include/lldb/Target/Statistics.h
@@ -12,6 +12,7 @@
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/JSON.h"
 #include 
 #include 
@@ -107,6 +108,7 @@
   // identifiers of these modules in the global module list. This allows us to
   // track down all of the stats that contribute to this module.
   std::vector symfile_modules;
+  llvm::StringMap type_system_stats;
   double symtab_parse_time = 0.0;
   double symtab_index_time = 0.0;
   double debug_parse_time = 0.0;
Index: lldb/include/lldb/Symbol/TypeSystem.h
===
--- lldb/include/lldb/Symbol/TypeSystem.h
+++ lldb/include/lldb/Symbol/TypeSystem.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/JSON.h"
 
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Expression/Expression.h"
@@ -508,6 +509,8 @@
   // meaningless type itself, instead preferring to use the dynamic type
   virtual bool IsMeaninglessWithoutDynamicResolution(void *type);
 
+  virtual llvm::Optional ReportStatistics();
+
 protected:
   SymbolFile *m_sym_file = nullptr;
 };
Index: lldb/include/lldb/Core/Module.h
===
--- lldb/include/lldb/Core/Module.h
+++ lldb/include/lldb/Core/Module.h
@@ -29,6 +29,7 @@
 #include "lldb/lldb-types.h"
 
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Chrono.h"
 
@@ -814,6 +815,8 @@
   llvm::Expected
   GetTypeSystemForLanguage(lldb::LanguageType language);
 
+  void ForEachTypeSystem(llvm::function_ref const &callback);
+
   // Special error functions that can do printf style formatting that will
   // prepend the message with something appropriate for this module (like the
   // architecture, path and object name (if any)). This centralizes code so
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D135547: [lldb/Utility] Add GetDescription(Stream&) to StructureData::*

2022-11-01 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 472475.
mib added a comment.

Address @JDevlieghere comments:

- Fix indentation bug on nested structures
- Add tests
- Use string literals for expected string in tests


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

https://reviews.llvm.org/D135547

Files:
  lldb/include/lldb/Core/StructuredDataImpl.h
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Utility/StructuredData.cpp
  lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/Inputs/StructuredData-empty.json
  lldb/unittests/Utility/Inputs/StructuredData-full.json
  lldb/unittests/Utility/Inputs/StructuredData-nested.json
  lldb/unittests/Utility/StructuredDataTest.cpp

Index: lldb/unittests/Utility/StructuredDataTest.cpp
===
--- lldb/unittests/Utility/StructuredDataTest.cpp
+++ lldb/unittests/Utility/StructuredDataTest.cpp
@@ -31,6 +31,80 @@
   }
 }
 
+TEST(StructuredDataTest, GetDescriptionEmpty) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-empty.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(0, S.GetSize());
+}
+
+TEST(StructuredDataTest, GetDescriptionBasic) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-basic.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = R"(
+  [0]: 1
+  [1]: 2
+  [2]: 3
+ )";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
+TEST(StructuredDataTest, GetDescriptionNested) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-nested.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = R"(
+  my_dict:
+[0]:
+  three: 3
+  two: 2
+[1]:
+  four:
+val: 4
+[2]: 1
+ )";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
+TEST(StructuredDataTest, GetDescriptionFull) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-full.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = R"(
+  Array:
+[0]: 3.14
+[1]:
+  key: val
+  Dictionary:
+FalseBool: False
+  Integer: 1
+  Null: NULL
+  String: value
+  TrueBool: True
+ )";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
 TEST(StructuredDataTest, ParseJSONFromFile) {
   Status status;
   auto object_sp = StructuredData::ParseJSONFromFile(
Index: lldb/unittests/Utility/Inputs/StructuredData-nested.json
===
--- /dev/null
+++ lldb/unittests/Utility/Inputs/StructuredData-nested.json
@@ -0,0 +1,14 @@
+{
+  "my_dict": [
+{
+  "three": 3,
+  "two": 2
+},
+{
+  "four": {
+"val": 4
+  }
+},
+1
+  ]
+}
Index: lldb/unittests/Utility/Inputs/StructuredData-full.json
===
--- /dev/null
+++ lldb/unittests/Utility/Inputs/StructuredData-full.json
@@ -0,0 +1,13 @@
+{
+  "Array": [
+3.14,
+1.234
+  ],
+  "Dictionary": {
+"FalseBool": false
+  },
+  "Integer": 1,
+  "Null": null,
+  "String": "value",
+  "TrueBool": true
+}
Index: lldb/unittests/Utility/Inputs/StructuredData-empty.json
===
--- /dev/null
+++ lldb/unittests/Utility/Inputs/StructuredData-empty.json
@@ -0,0 +1 @@
+{}
Index: lldb/unittests/Utility/CMakeLists.txt
===
--- lldb/unittests/Utility/CMakeLists.txt
+++ lldb/unittests/Utility/CMakeLists.txt
@@ -54,6 +54,9 @@
 Support
   )
 
-add_

[Lldb-commits] [PATCH] D135547: [lldb/Utility] Add GetDescription(Stream&) to StructureData::*

2022-11-01 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/include/lldb/Utility/StructuredData.h:584
   static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
+  static bool IsRecordType(const ObjectSP object_sp);
 };

@JDevlieghere Not sure if it would be worth to `inline` this


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

https://reviews.llvm.org/D135547

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D135547: [lldb/Utility] Add GetDescription(Stream&) to StructureData::*

2022-11-01 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 472497.

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

https://reviews.llvm.org/D135547

Files:
  lldb/include/lldb/Core/StructuredDataImpl.h
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Utility/StructuredData.cpp
  lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/Inputs/StructuredData-full.json
  lldb/unittests/Utility/Inputs/StructuredData-nested.json
  lldb/unittests/Utility/StructuredDataTest.cpp

Index: lldb/unittests/Utility/StructuredDataTest.cpp
===
--- lldb/unittests/Utility/StructuredDataTest.cpp
+++ lldb/unittests/Utility/StructuredDataTest.cpp
@@ -31,6 +31,73 @@
   }
 }
 
+TEST(StructuredDataTest, GetDescriptionEmpty) {
+  Status status;
+  auto object_sp = StructuredData::ParseJSON("{}");
+  ASSERT_NE(nullptr, object_sp);
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(0, S.GetSize());
+}
+
+TEST(StructuredDataTest, GetDescriptionBasic) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-basic.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = "[0]: 1\n"
+   "[1]: 2\n"
+   "[2]: 3";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
+TEST(StructuredDataTest, GetDescriptionNested) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-nested.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = "my_dict:\n"
+   "  [0]:\n"
+   "three: 3\n"
+   "two: 2\n"
+   "  [1]:\n"
+   "four:\n"
+   "  val: 4\n"
+   "  [2]: 1";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
+TEST(StructuredDataTest, GetDescriptionFull) {
+  Status status;
+  std::string input = GetInputFilePath("StructuredData-full.json");
+  auto object_sp = StructuredData::ParseJSONFromFile(FileSpec(input), status);
+  ASSERT_NE(nullptr, object_sp);
+
+  const std::string expected = "Array:\n"
+   "  [0]: 3.14\n"
+   "  [1]:\n"
+   "key: val\n"
+   "Dictionary:\n"
+   "  FalseBool: False\n"
+   "Integer: 1\n"
+   "Null: NULL\n"
+   "String: value\n"
+   "TrueBool: True";
+
+  StreamString S;
+  object_sp->GetDescription(S);
+  EXPECT_EQ(expected, S.GetString());
+}
+
 TEST(StructuredDataTest, ParseJSONFromFile) {
   Status status;
   auto object_sp = StructuredData::ParseJSONFromFile(
Index: lldb/unittests/Utility/Inputs/StructuredData-nested.json
===
--- /dev/null
+++ lldb/unittests/Utility/Inputs/StructuredData-nested.json
@@ -0,0 +1,14 @@
+{
+  "my_dict": [
+{
+  "three": 3,
+  "two": 2
+},
+{
+  "four": {
+"val": 4
+  }
+},
+1
+  ]
+}
Index: lldb/unittests/Utility/Inputs/StructuredData-full.json
===
--- /dev/null
+++ lldb/unittests/Utility/Inputs/StructuredData-full.json
@@ -0,0 +1,15 @@
+{
+  "Array": [
+3.14,
+{
+  "key": "val"
+}
+  ],
+  "Dictionary": {
+"FalseBool": false
+  },
+  "Integer": 1,
+  "Null": null,
+  "String": "value",
+  "TrueBool": true
+}
Index: lldb/unittests/Utility/CMakeLists.txt
===
--- lldb/unittests/Utility/CMakeLists.txt
+++ lldb/unittests/Utility/CMakeLists.txt
@@ -54,6 +54,10 @@
 Support
   )
 
-add_unittest_inputs(UtilityTests
+set(test_inputs
   StructuredData-basic.json
+  StructuredData-nested.json
+  StructuredData-full.json
   )
+
+add_unittest_inputs(UtilityTests "${test_inputs}")
Index: lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
===
--- lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
+++ lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
@@ -37,7 +37,9 @@
 patterns=["Process .* launched: .*a.out"])
 
 self.expect('process status --verbose',
-patterns=["\"message\".*pointer being freed was not allocated"])
+  

[Lldb-commits] [PATCH] D137191: [lldb] Add information on type systems to statistics dump command

2022-11-01 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Thanks for the changes. Looks good.


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

https://reviews.llvm.org/D137191

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits