[Lldb-commits] [lldb] 4606712 - [lldb][lldb-vscode] Add example configuration for connecting to a remote gdbserver (#68866)

2023-10-17 Thread via lldb-commits

Author: David Spickett
Date: 2023-10-17T09:01:07+01:00
New Revision: 4606712ef5b422edbe3799b665dcad7dcf348b90

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

LOG: [lldb][lldb-vscode] Add example configuration for connecting to a remote 
gdbserver (#68866)

This can be used to have VS Code debug various emulators, remote
systems, hardware probes, etc.

In my case I was doing this for the Gameboy Advance,
https://github.com/stuij/gba-llvm-devkit/blob/main/docs/Debugging.md#debugging-using-visual-studio-code.

It's not very complex if you know LLDB well, but when using another
plugin, CodeLLDB, I was very glad that they had an example for it. So we
should have one too.

Added: 


Modified: 
lldb/tools/lldb-vscode/README.md

Removed: 




diff  --git a/lldb/tools/lldb-vscode/README.md 
b/lldb/tools/lldb-vscode/README.md
index 6f930293126d53e..078129026cb0cc9 100644
--- a/lldb/tools/lldb-vscode/README.md
+++ b/lldb/tools/lldb-vscode/README.md
@@ -212,6 +212,38 @@ This loads the coredump file `/cores/123.core` associated 
with the program
 }
 ```
 
+### Connect to a Debug Server on the Current Machine
+
+This connects to a debug server (e.g. `lldb-server`, `gdbserver`) on
+the current machine, that is debugging the program `/tmp/a.out` and listening
+locally on port `2345`.
+
+```javascript
+{
+  "name": "Local Debug Server",
+  "type": "lldb-vscode",
+  "request": "attach",
+  "program": "/tmp/a.out",
+  "attachCommands": ["gdb-remote 2345"],
+}
+```
+
+### Connect to a Debug Server on Another Machine
+
+This connects to a debug server running on another machine with hostname
+`hostnmame`. Which is debugging the program `/tmp/a.out` and listening on
+port `5678` of that other machine.
+
+```javascript
+{
+  "name": "Remote Debug Server",
+  "type": "lldb-vscode",
+  "request": "attach",
+  "program": "/tmp/a.out",
+  "attachCommands": ["gdb-remote hostname:5678"],
+}
+```
+
 # Custom debugger commands
 
 The `lldb-vscode` tool includes additional custom commands to support the Debug



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


[Lldb-commits] [lldb] [lldb][lldb-vscode] Add example configuration for connecting to a remote gdbserver (PR #68866)

2023-10-17 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett closed 
https://github.com/llvm/llvm-project/pull/68866
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits


@@ -18,9 +18,10 @@
 
 # Introduction

DavidSpickett wrote:

I think a stub README at the old lldb-vscode location is worth adding. It 
should just link here.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits


@@ -18,9 +18,10 @@
 
 # Introduction
 
-The `lldb-vscode` tool creates a command line tool that implements the [Visual
-Studio Code Debug 
API](https://code.visualstudio.com/docs/extensionAPI/api-debugging).
-It can be installed as an extension for the Visual Studio Code and Nuclide IDE.
+The `lldb-dap` tool (formerly `lldb-vscode) creates a command line tool that

DavidSpickett wrote:

missing the second backtick on lldb-vscode.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits


@@ -196,6 +196,7 @@ Changes to LLDB
   for formatters to quickly find directly nested type when it's known
   where to search for it, avoiding more expensive global search via
   ``SBTarget::FindFirstType``.
+* ``lldb-vscode`` was renamed to `lldb-dap``.

DavidSpickett wrote:

Needs double backtick around lldb-dap.

It is obvious to most but is it worth stating that functionality has not 
changed? Which is a strong hint that users are a symlink away from keeping 
existing scripts working.

Perhaps also "and its installation instructions have been updated to reflect 
this". Hinting hey, next time you do this you will have to read this again.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits


@@ -40,59 +41,59 @@ If you want to make a stand alone plug-in that you can send 
to others on UNIX
 systems:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-cp /path/to/a/built/lldb-vscode .
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+cp /path/to/a/built/lldb-dap .
 cp /path/to/a/built/liblldb.so .
 ```
 
 If you want to make a stand alone plug-in that you can send to others on macOS
 systems:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-cp /path/to/a/built/lldb-vscode .
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+cp /path/to/a/built/lldb-dap .
 rsync -av /path/to/a/built/LLDB.framework LLDB.framework
 ```
 
 You might need to create additional directories for the `liblldb.so` or
 `LLDB.framework` inside or next to the `bin` folder depending on how the
-[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-vscode`
+[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-dap`
 binary. By default the `Debug` builds of LLDB usually includes
 the current executable directory in the rpath, so these steps should work for
 most people.
 
-To create a plug-in that symlinks into your `lldb-vscode` in your build
+To create a plug-in that symlinks into your `lldb-dap` in your build
 directory:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-ln -s /path/to/a/built/lldb-vscode
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+ln -s /path/to/a/built/lldb-dap
 ```
 
-This is handy if you want to debug and develope the `lldb-vscode` executable
+This is handy if you want to debug and develope the `lldb-dap` executable

DavidSpickett wrote:

Do this in a follow up but, `develope` -> `develop`.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Also I just gave you some conflicts with 
https://github.com/llvm/llvm-project/commit/4606712ef5b422edbe3799b665dcad7dcf348b90.
 I think only the "type" bit needs changing to "lldb-dap".

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits


@@ -1,5 +1,5 @@
 {
-   "name": "lldb-vscode",
+   "name": "lldb-dap",

DavidSpickett wrote:

This and others are still in an "lldb-vscode" folder, that doesn't seem right.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

2023-10-17 Thread David Spickett via lldb-commits


@@ -1,3 +1,10 @@
 # REQUIRES: system-darwin
+# TODO: This test is breaking with my output 
+# reformatting done for Large Watchpoint support,
+# but the lines being output by lldb are identical,
+# by visual inspection.  
+# FileCheck is seeing some difference between them,
+# which I need to get to the bottom of.

DavidSpickett wrote:

A trick I used to do for python doctests was `str.replace(" ", "?")`. Then you 
could see the trailing spaces. Might work here if you have that or extra 
newlines.

https://github.com/llvm/llvm-project/pull/68845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

2023-10-17 Thread David Spickett via lldb-commits


@@ -135,5 +135,5 @@ def test_watch_address_with_invalid_watch_size(self):
 self.expect(
 error.GetCString(),
 exe=False,
-substrs=["watch size of %d is not supported" % 365],
+substrs=["Setting one of the watchpoint resources failed"],

DavidSpickett wrote:

Is the original error still relevant? Should it be one of the watchpoint 
resources failed because...

https://github.com/llvm/llvm-project/pull/68845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

2023-10-17 Thread David Spickett via lldb-commits


@@ -0,0 +1,61 @@
+//===-- WatchpointResourceList.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/WatchpointResourceList.h"
+#include "lldb/Target/WatchpointResource.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+WatchpointResourceList::WatchpointResourceList() : m_resources(), m_mutex() {}
+
+WatchpointResourceList::~WatchpointResourceList() { Clear(); }
+
+uint32_t WatchpointResourceList::GetSize() {
+  std::lock_guard guard(m_mutex);
+  return m_resources.size();
+}
+
+lldb::WatchpointResourceSP
+WatchpointResourceList::GetResourceAtIndex(uint32_t idx) {
+  std::lock_guard guard(m_mutex);
+  if (idx < m_resources.size()) {
+return m_resources[idx];
+  } else {
+return {};

DavidSpickett wrote:

Single line ifs.

https://github.com/llvm/llvm-project/pull/68845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

2023-10-17 Thread David Spickett via lldb-commits


@@ -0,0 +1,61 @@
+//===-- WatchpointResourceList.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/WatchpointResourceList.h"
+#include "lldb/Target/WatchpointResource.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+WatchpointResourceList::WatchpointResourceList() : m_resources(), m_mutex() {}
+
+WatchpointResourceList::~WatchpointResourceList() { Clear(); }
+
+uint32_t WatchpointResourceList::GetSize() {
+  std::lock_guard guard(m_mutex);
+  return m_resources.size();
+}
+
+lldb::WatchpointResourceSP
+WatchpointResourceList::GetResourceAtIndex(uint32_t idx) {
+  std::lock_guard guard(m_mutex);
+  if (idx < m_resources.size()) {
+return m_resources[idx];
+  } else {
+return {};

DavidSpickett wrote:

Also return in an else (as in, no need for the else)

https://github.com/llvm/llvm-project/pull/68845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

2023-10-17 Thread David Spickett via lldb-commits


@@ -2,8 +2,8 @@
 #include 
 
 int main() {
-  uint8_t x1 = 0;
-  uint16_t x2 = 0;
+  long x1 = 0;
+  long x2 = 0;

DavidSpickett wrote:

We need the type change here because?

https://github.com/llvm/llvm-project/pull/68845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterField (PR #69315)

2023-10-17 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/69315

This means you don't have to do RegisterField("", 0, 0), you can do 
RegisterField("", 0).

Which is useful for testing and even more useful when we are writing 
definitions of real registers which have 10s of single bit fields.

>From 1f5a161cb9265f2761e93d2352c65e382a44a1e5 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Tue, 17 Oct 2023 10:10:36 +
Subject: [PATCH] [lldb] Add a single bit constructor for RegisterField

This means you don't have to do RegisterField("", 0, 0),
you can do RegisterField("", 0).

Which is useful for testing and even more useful when we
are writing definitions of real registers which have 10s
of single bit fields.
---
 lldb/include/lldb/Target/RegisterFlags.h|  6 
 lldb/unittests/Target/RegisterFlagsTest.cpp | 35 +++--
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 8137fd27e99c2a2..ce3daa237194036 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -17,11 +17,17 @@ class RegisterFlags {
 public:
   class Field {
   public:
+/// Where start is the least significant bit and end is the most
+/// significant bit. The start bit must be <= the end bit.
 Field(std::string name, unsigned start, unsigned end)
 : m_name(std::move(name)), m_start(start), m_end(end) {
   assert(m_start <= m_end && "Start bit must be <= end bit.");
 }
 
+/// Construct a single bit field.
+Field(std::string name, unsigned bit)
+: m_name(std::move(name)), m_start(bit), m_end(bit) {}
+
 /// Get size of the field in bits. Will always be at least 1.
 unsigned GetSizeInBits() const { return m_end - m_start + 1; }
 
diff --git a/lldb/unittests/Target/RegisterFlagsTest.cpp 
b/lldb/unittests/Target/RegisterFlagsTest.cpp
index 194e05959c16599..167e28d0cecb3bd 100644
--- a/lldb/unittests/Target/RegisterFlagsTest.cpp
+++ b/lldb/unittests/Target/RegisterFlagsTest.cpp
@@ -16,7 +16,7 @@ using namespace lldb;
 TEST(RegisterFlagsTest, Field) {
   // We assume that start <= end is always true, so that is not tested here.
 
-  RegisterFlags::Field f1("abc", 0, 0);
+  RegisterFlags::Field f1("abc", 0);
   ASSERT_EQ(f1.GetName(), "abc");
   // start == end means a 1 bit field.
   ASSERT_EQ(f1.GetSizeInBits(), (unsigned)1);
@@ -51,11 +51,15 @@ static RegisterFlags::Field make_field(unsigned start, 
unsigned end) {
   return RegisterFlags::Field("", start, end);
 }
 
+static RegisterFlags::Field make_field(unsigned bit) {
+  return RegisterFlags::Field("", bit);
+}
+
 TEST(RegisterFlagsTest, FieldOverlaps) {
   // Single bit fields
-  ASSERT_FALSE(make_field(0, 0).Overlaps(make_field(1, 1)));
-  ASSERT_TRUE(make_field(1, 1).Overlaps(make_field(1, 1)));
-  ASSERT_FALSE(make_field(1, 1).Overlaps(make_field(3, 3)));
+  ASSERT_FALSE(make_field(0, 0).Overlaps(make_field(1)));
+  ASSERT_TRUE(make_field(1, 1).Overlaps(make_field(1)));
+  ASSERT_FALSE(make_field(1, 1).Overlaps(make_field(3)));
 
   ASSERT_TRUE(make_field(0, 1).Overlaps(make_field(1, 2)));
   ASSERT_TRUE(make_field(1, 2).Overlaps(make_field(0, 1)));
@@ -71,13 +75,13 @@ TEST(RegisterFlagsTest, PaddingDistance) {
   // (start bit is higher) field first and that they do not overlap.
 
   // [field 1][field 2]
-  ASSERT_EQ(make_field(1, 1).PaddingDistance(make_field(0, 0)), 0ULL);
+  ASSERT_EQ(make_field(1, 1).PaddingDistance(make_field(0)), 0ULL);
   // [field 1][..][field 2]
-  ASSERT_EQ(make_field(2, 2).PaddingDistance(make_field(0, 0)), 1ULL);
+  ASSERT_EQ(make_field(2, 2).PaddingDistance(make_field(0)), 1ULL);
   // [field 1][field 1][field 2]
-  ASSERT_EQ(make_field(1, 2).PaddingDistance(make_field(0, 0)), 0ULL);
+  ASSERT_EQ(make_field(1, 2).PaddingDistance(make_field(0)), 0ULL);
   // [field 1][30 bits free][field 2]
-  ASSERT_EQ(make_field(31, 31).PaddingDistance(make_field(0, 0)), 30ULL);
+  ASSERT_EQ(make_field(31, 31).PaddingDistance(make_field(0)), 30ULL);
 }
 
 static void test_padding(const std::vector &fields,
@@ -99,18 +103,18 @@ TEST(RegisterFlagsTest, RegisterFlagsPadding) {
 
   // Needs padding in between the fields, single bit.
   test_padding({make_field(17, 31), make_field(0, 15)},
-   {make_field(17, 31), make_field(16, 16), make_field(0, 15)});
+   {make_field(17, 31), make_field(16), make_field(0, 15)});
   // Multiple bits of padding.
   test_padding({make_field(17, 31), make_field(0, 14)},
{make_field(17, 31), make_field(15, 16), make_field(0, 14)});
 
   // Padding before first field, single bit.
-  test_padding({make_field(0, 30)}, {make_field(31, 31), make_field(0, 30)});
+  test_padding({make_field(0, 30)}, {make_field(31), make_field(0, 30)});
   // Multiple bits.
   test_padding({make_field(0, 15)}, {make_field(16, 31), make_field(0, 15)});
 
   // Padding after last f

[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterField (PR #69315)

2023-10-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

This means you don't have to do RegisterField("", 0, 0), you can do 
RegisterField("", 0).

Which is useful for testing and even more useful when we are writing 
definitions of real registers which have 10s of single bit fields.

---
Full diff: https://github.com/llvm/llvm-project/pull/69315.diff


2 Files Affected:

- (modified) lldb/include/lldb/Target/RegisterFlags.h (+6) 
- (modified) lldb/unittests/Target/RegisterFlagsTest.cpp (+19-16) 


``diff
diff --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 8137fd27e99c2a2..ce3daa237194036 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -17,11 +17,17 @@ class RegisterFlags {
 public:
   class Field {
   public:
+/// Where start is the least significant bit and end is the most
+/// significant bit. The start bit must be <= the end bit.
 Field(std::string name, unsigned start, unsigned end)
 : m_name(std::move(name)), m_start(start), m_end(end) {
   assert(m_start <= m_end && "Start bit must be <= end bit.");
 }
 
+/// Construct a single bit field.
+Field(std::string name, unsigned bit)
+: m_name(std::move(name)), m_start(bit), m_end(bit) {}
+
 /// Get size of the field in bits. Will always be at least 1.
 unsigned GetSizeInBits() const { return m_end - m_start + 1; }
 
diff --git a/lldb/unittests/Target/RegisterFlagsTest.cpp 
b/lldb/unittests/Target/RegisterFlagsTest.cpp
index 194e05959c16599..167e28d0cecb3bd 100644
--- a/lldb/unittests/Target/RegisterFlagsTest.cpp
+++ b/lldb/unittests/Target/RegisterFlagsTest.cpp
@@ -16,7 +16,7 @@ using namespace lldb;
 TEST(RegisterFlagsTest, Field) {
   // We assume that start <= end is always true, so that is not tested here.
 
-  RegisterFlags::Field f1("abc", 0, 0);
+  RegisterFlags::Field f1("abc", 0);
   ASSERT_EQ(f1.GetName(), "abc");
   // start == end means a 1 bit field.
   ASSERT_EQ(f1.GetSizeInBits(), (unsigned)1);
@@ -51,11 +51,15 @@ static RegisterFlags::Field make_field(unsigned start, 
unsigned end) {
   return RegisterFlags::Field("", start, end);
 }
 
+static RegisterFlags::Field make_field(unsigned bit) {
+  return RegisterFlags::Field("", bit);
+}
+
 TEST(RegisterFlagsTest, FieldOverlaps) {
   // Single bit fields
-  ASSERT_FALSE(make_field(0, 0).Overlaps(make_field(1, 1)));
-  ASSERT_TRUE(make_field(1, 1).Overlaps(make_field(1, 1)));
-  ASSERT_FALSE(make_field(1, 1).Overlaps(make_field(3, 3)));
+  ASSERT_FALSE(make_field(0, 0).Overlaps(make_field(1)));
+  ASSERT_TRUE(make_field(1, 1).Overlaps(make_field(1)));
+  ASSERT_FALSE(make_field(1, 1).Overlaps(make_field(3)));
 
   ASSERT_TRUE(make_field(0, 1).Overlaps(make_field(1, 2)));
   ASSERT_TRUE(make_field(1, 2).Overlaps(make_field(0, 1)));
@@ -71,13 +75,13 @@ TEST(RegisterFlagsTest, PaddingDistance) {
   // (start bit is higher) field first and that they do not overlap.
 
   // [field 1][field 2]
-  ASSERT_EQ(make_field(1, 1).PaddingDistance(make_field(0, 0)), 0ULL);
+  ASSERT_EQ(make_field(1, 1).PaddingDistance(make_field(0)), 0ULL);
   // [field 1][..][field 2]
-  ASSERT_EQ(make_field(2, 2).PaddingDistance(make_field(0, 0)), 1ULL);
+  ASSERT_EQ(make_field(2, 2).PaddingDistance(make_field(0)), 1ULL);
   // [field 1][field 1][field 2]
-  ASSERT_EQ(make_field(1, 2).PaddingDistance(make_field(0, 0)), 0ULL);
+  ASSERT_EQ(make_field(1, 2).PaddingDistance(make_field(0)), 0ULL);
   // [field 1][30 bits free][field 2]
-  ASSERT_EQ(make_field(31, 31).PaddingDistance(make_field(0, 0)), 30ULL);
+  ASSERT_EQ(make_field(31, 31).PaddingDistance(make_field(0)), 30ULL);
 }
 
 static void test_padding(const std::vector &fields,
@@ -99,18 +103,18 @@ TEST(RegisterFlagsTest, RegisterFlagsPadding) {
 
   // Needs padding in between the fields, single bit.
   test_padding({make_field(17, 31), make_field(0, 15)},
-   {make_field(17, 31), make_field(16, 16), make_field(0, 15)});
+   {make_field(17, 31), make_field(16), make_field(0, 15)});
   // Multiple bits of padding.
   test_padding({make_field(17, 31), make_field(0, 14)},
{make_field(17, 31), make_field(15, 16), make_field(0, 14)});
 
   // Padding before first field, single bit.
-  test_padding({make_field(0, 30)}, {make_field(31, 31), make_field(0, 30)});
+  test_padding({make_field(0, 30)}, {make_field(31), make_field(0, 30)});
   // Multiple bits.
   test_padding({make_field(0, 15)}, {make_field(16, 31), make_field(0, 15)});
 
   // Padding after last field, single bit.
-  test_padding({make_field(1, 31)}, {make_field(1, 31), make_field(0, 0)});
+  test_padding({make_field(1, 31)}, {make_field(1, 31), make_field(0)});
   // Multiple bits.
   test_padding({make_field(2, 31)}, {make_field(2, 31), make_field(0, 1)});
 
@@ -132,9 +136,8 @@ TEST(RegisterFieldsTest, ReverseFieldOrder) {
   ASSERT_EQ(0x56781234ULL, (unsigned long

[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterFlags::Field (PR #69315)

2023-10-17 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/69315
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I built this locally and I did not get a `bin/lldb-dap` only `lldb-vscde` as 
before, but it was an existing build folder. So if your clean build is correct 
you can ignore that part.

I followed the install instructions and got the "LLDB VSCode" extension with 
type "llda-dap" as expected (symlinking lldb-vscode instead).

Find in files also shows some more references to `lldb-vscode` that should be 
checked and/or changed.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Actually there was a ninja target for `lldb-dap` but it wasn't built by 
default. Again, existing cmake config so if yours is fine then ignore this.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Erich Keane via lldb-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/69010
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Erich Keane via lldb-commits


@@ -3083,6 +3083,10 @@ ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
 E->getTypeOfArgument()->getPointeeType()))
 .getQuantity();
 return llvm::ConstantInt::get(CGF.SizeTy, Alignment);
+  } else if (E->getKind() == UETT_VectorElements) {
+auto *VecTy =
+dyn_cast(ConvertType(E->getTypeOfArgument()));

erichkeane wrote:

```suggestion
cast(ConvertType(E->getTypeOfArgument()));
```
You immediately dereference this anyway, and I think the semantics guarantees 
this is the case, correct?

https://github.com/llvm/llvm-project/pull/69010
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Lawrence Benson via lldb-commits


@@ -5126,6 +5126,14 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
   Diags.Report(DiagID);
   return;
 }
+case UETT_VectorElements: {

lawben wrote:

I don't know. But none of the other `UETT_*` types are covered in 
`MicrosoftMangle.cpp`. I'm not sure whether they are missing or if it not 
necessary to add this.

https://github.com/llvm/llvm-project/pull/69010
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Lawrence Benson via lldb-commits

https://github.com/lawben updated 
https://github.com/llvm/llvm-project/pull/69010

>From df8d0a53a31e1351bb6cd3b340e9012b489e9885 Mon Sep 17 00:00:00 2001
From: Lawrence Benson 
Date: Wed, 11 Oct 2023 17:26:11 +0200
Subject: [PATCH 01/10] Add __builtin_vectorelements to get the number of
 elements in a fixed-sized vector at compile-time or via a @llvm.vscale call
 at runtime.

---
 clang/include/clang/AST/Type.h   |  3 +++
 clang/include/clang/Basic/Builtins.def   |  1 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/AST/ExprConstant.cpp   |  8 
 clang/lib/AST/ItaniumMangle.cpp  |  8 
 clang/lib/AST/Type.cpp   |  6 +-
 clang/lib/CodeGen/CGExprScalar.cpp   | 12 
 clang/lib/Parse/ParseExpr.cpp|  7 +--
 clang/lib/Sema/SemaChecking.cpp  | 18 ++
 clang/lib/Sema/SemaExpr.cpp  | 14 ++
 10 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a78d8f60462b231..f6e425783176ba2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2058,6 +2058,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   bool isSizelessType() const;
   bool isSizelessBuiltinType() const;
 
+  /// Returns true for all scalable vector types.
+  bool isSizelessVectorType() const;
+
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..6033e8a955fb8bd 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -674,6 +674,7 @@ BUILTIN(__builtin_debugtrap, "v", "n")
 BUILTIN(__builtin_unreachable, "v", "nr")
 BUILTIN(__builtin_shufflevector, "v."   , "nct")
 BUILTIN(__builtin_convertvector, "v."   , "nct")
+BUILTIN(__builtin_vectorelements, "v."  , "nct")
 BUILTIN(__builtin_alloca, "v*z"   , "Fn")
 BUILTIN(__builtin_alloca_uninitialized, "v*z", "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 94db56a9fd5d78c..bbae1200d376c0d 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -746,6 +746,7 @@ ALIAS("_pascal"  , __pascal   , KEYBORLAND)
 
 // Clang Extensions.
 KEYWORD(__builtin_convertvector  , KEYALL)
+UNARY_EXPR_OR_TYPE_TRAIT(__builtin_vectorelements, VectorElements, KEYALL)
 ALIAS("__char16_t"   , char16_t  , KEYCXX)
 ALIAS("__char32_t"   , char32_t  , KEYCXX)
 KEYWORD(__builtin_bit_cast   , KEYALL)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..eb36a57e462f3f1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13595,6 +13595,14 @@ bool IntExprEvaluator::VisitUnaryExprOrTypeTraitExpr(
 Info.Ctx.getOpenMPDefaultSimdAlign(E->getArgumentType()))
 .getQuantity(),
 E);
+  case UETT_VectorElements: {
+QualType Ty = E->getTypeOfArgument();
+// If the vector has a fixed size, we can determine the number of elements 
at compile time.
+if (Ty->isVectorType())
+  return Success(Ty->castAs()->getNumElements(), E);
+
+return false;
+  }
   }
 
   llvm_unreachable("unknown expr/type trait");
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 23ec35cae4b7b40..171dfe429c12d31 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -5126,6 +5126,14 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
   Diags.Report(DiagID);
   return;
 }
+case UETT_VectorElements: {
+  DiagnosticsEngine &Diags = Context.getDiags();
+  unsigned DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "cannot yet mangle __builtin_vectorelements expression");
+  Diags.Report(DiagID);
+  return;
+}
 }
 break;
   }
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..050761784498a9c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2369,7 +2369,7 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
 }
 
 bool Type::isSizelessBuiltinType() const {
-  if (isSVESizelessBuiltinType() || isRVVSizelessBuiltinType())
+  if (isSizelessVectorType())
 return true;
 
   if (const BuiltinType *BT = getAs()) {
@@ -2403,6 +2403,10 @@ bool Type::isWebAssemblyTableType() const {
 
 bool Type::isSizelessType() const { return isSizelessBuiltinType(); }
 
+bool Type::isSizelessVectorType() const {
+  return isSVESizelessBuiltinType() || isRVVSizelessBuiltinType();
+}
+
 bool Type::isSVESizelessBuiltinType() const {
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {

[Lldb-commits] [lldb] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Erich Keane via lldb-commits


@@ -5126,6 +5126,14 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
   Diags.Report(DiagID);
   return;
 }
+case UETT_VectorElements: {

erichkeane wrote:

OK, SGTM at least, I just know this pattern of 'cannot yet mangle...' shows up 
primarily in the MicrosoftMangle, so figured it might need to be covered.  
There is some funny-business as to how much each mangles of expressions in 
template arguments.

This gets me thinking further though,the constexprness of this likely means you 
may need to mangle this.  I'm open if others are to letting it be done in a 
follow-up however.

https://github.com/llvm/llvm-project/pull/69010
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-vscode] Allow specifying a custom escape character for LLDB commands (PR #69238)

2023-10-17 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo updated 
https://github.com/llvm/llvm-project/pull/69238

>From 19295d5fe84c1f06f3e5d712d5af39f8ef48286c Mon Sep 17 00:00:00 2001
From: walter erquinigo 
Date: Mon, 16 Oct 2023 15:08:20 -0400
Subject: [PATCH] [lldb-vscode] Allow specifying a custom escape character for
 LLDB commands

We've been using the backtick as our escape character, however that leads to a 
weird experience on VS Code, because on most hosts, as soon as you type the 
backtick on VS Code, the IDE will introduce another backtick. As changing the 
default escape character might be out of question because other plugins might 
rely on it, we can instead introduce an option to change this variable upon 
lldb-vscode initialization.
FWIW, my users will be using : instead ot the backtick.
---
 .../tools/lldb-vscode/lldbvscode_testcase.py  |  4 ++
 .../test/tools/lldb-vscode/vscode.py  |  9 +++-
 .../lldb-vscode/console/TestVSCode_console.py | 46 +--
 lldb/tools/lldb-vscode/JSONUtils.cpp  | 10 ++--
 lldb/tools/lldb-vscode/JSONUtils.h| 11 +++--
 lldb/tools/lldb-vscode/VSCode.cpp | 11 +++--
 lldb/tools/lldb-vscode/VSCode.h   |  1 +
 lldb/tools/lldb-vscode/lldb-vscode.cpp|  4 ++
 lldb/tools/lldb-vscode/package.json   | 10 
 9 files changed, 90 insertions(+), 16 deletions(-)

diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
index 8cd4e8454c89099..2e4a13b2fa2eed3 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -351,6 +351,7 @@ def launch(
 postRunCommands=None,
 enableAutoVariableSummaries=False,
 enableSyntheticChildDebugging=False,
+commandEscapePrefix="`",
 ):
 """Sending launch request to vscode"""
 
@@ -389,6 +390,7 @@ def cleanup():
 postRunCommands=postRunCommands,
 enableAutoVariableSummaries=enableAutoVariableSummaries,
 enableSyntheticChildDebugging=enableSyntheticChildDebugging,
+commandEscapePrefix=commandEscapePrefix,
 )
 
 if expectFailure:
@@ -425,6 +427,7 @@ def build_and_launch(
 lldbVSCodeEnv=None,
 enableAutoVariableSummaries=False,
 enableSyntheticChildDebugging=False,
+commandEscapePrefix="`",
 ):
 """Build the default Makefile target, create the VSCode debug adaptor,
 and launch the process.
@@ -455,4 +458,5 @@ def build_and_launch(
 postRunCommands=postRunCommands,
 enableAutoVariableSummaries=enableAutoVariableSummaries,
 enableSyntheticChildDebugging=enableSyntheticChildDebugging,
+commandEscapePrefix=commandEscapePrefix,
 )
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
index 5ee0800b27a5699..d5e213d3e13db8f 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -731,6 +731,7 @@ def request_launch(
 postRunCommands=None,
 enableAutoVariableSummaries=False,
 enableSyntheticChildDebugging=False,
+commandEscapePrefix="`",
 ):
 args_dict = {"program": program}
 if args:
@@ -774,6 +775,7 @@ def request_launch(
 args_dict["postRunCommands"] = postRunCommands
 args_dict["enableAutoVariableSummaries"] = enableAutoVariableSummaries
 args_dict["enableSyntheticChildDebugging"] = 
enableSyntheticChildDebugging
+args_dict["commandEscapePrefix"] = commandEscapePrefix
 command_dict = {"command": "launch", "type": "request", "arguments": 
args_dict}
 response = self.send_recv(command_dict)
 
@@ -1015,7 +1017,12 @@ def terminate(self):
 
 class DebugAdaptor(DebugCommunication):
 def __init__(
-self, executable=None, port=None, init_commands=[], log_file=None, 
env=None
+self,
+executable=None,
+port=None,
+init_commands=[],
+log_file=None,
+env=None,
 ):
 self.process = None
 if executable is not None:
diff --git a/lldb/test/API/tools/lldb-vscode/console/TestVSCode_console.py 
b/lldb/test/API/tools/lldb-vscode/console/TestVSCode_console.py
index d28e98b37c589dd..8eb02257ec6c5c5 100644
--- a/lldb/test/API/tools/lldb-vscode/console/TestVSCode_console.py
+++ b/lldb/test/API/tools/lldb-vscode/console/TestVSCode_console.py
@@ -2,16 +2,20 @@
 Test lldb-vscode setBreakpoints request
 """
 
+import lldbvscode_testcase
 import vscode
+from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-import lldbvs

[Lldb-commits] [lldb] [lldb-vscode] Allow specifying a custom escape prefix for LLDB commands (PR #69238)

2023-10-17 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo edited 
https://github.com/llvm/llvm-project/pull/69238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterFlags::Field (PR #69315)

2023-10-17 Thread Alex Langford via lldb-commits

https://github.com/bulbazord edited 
https://github.com/llvm/llvm-project/pull/69315
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterFlags::Field (PR #69315)

2023-10-17 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

Makes sense to me since this seems to be a relatively common pattern (from the 
tests).

Is there anywhere you can begin to use this other than in the tests? Or is this 
building up to [your proposal on adding register field info to 
lldb-server](https://discourse.llvm.org/t/rfc-adding-register-field-information-to-lldb-server/74143)?

https://github.com/llvm/llvm-project/pull/69315
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add a single bit constructor for RegisterFlags::Field (PR #69315)

2023-10-17 Thread Alex Langford via lldb-commits


@@ -17,11 +17,17 @@ class RegisterFlags {
 public:
   class Field {
   public:
+/// Where start is the least significant bit and end is the most
+/// significant bit. The start bit must be <= the end bit.
 Field(std::string name, unsigned start, unsigned end)
 : m_name(std::move(name)), m_start(start), m_end(end) {
   assert(m_start <= m_end && "Start bit must be <= end bit.");
 }
 
+/// Construct a single bit field.
+Field(std::string name, unsigned bit)
+: m_name(std::move(name)), m_start(bit), m_end(bit) {}

bulbazord wrote:

Can you either add more to the doxygen comment or rename the `bit` field? 
Perhaps something like `bit_position` or something? It feels a little vague to 
me at the moment.

https://github.com/llvm/llvm-project/pull/69315
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Scalar::GetValue() should take a Stream by reference (PR #69231)

2023-10-17 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/69231
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Scalar::GetValue() should take a Stream by reference (PR #69231)

2023-10-17 Thread Greg Clayton via lldb-commits

clayborg wrote:

There are probably a lot of functions that could be converted from a "Stream *" 
to "Stream &". 

https://github.com/llvm/llvm-project/pull/69231
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Scalar::GetValue() should take a Stream by reference (PR #69231)

2023-10-17 Thread Alex Langford via lldb-commits

bulbazord wrote:

> There are probably a lot of functions that could be converted from a "Stream 
> *" to "Stream &".

Yes, when I have a spare 5-10 minutes I pick a function and convert it. I don't 
want to end up with a huge diff that is difficult to merge downstream so I do 
it piecemeal.

https://github.com/llvm/llvm-project/pull/69231
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> Actually there was a ninja target for `lldb-dap` but it wasn't built by 
> default. Again, existing cmake config so if yours is fine then ignore this.

Yes, I had the same thing happen to me with an incremental build, but 
everything looked correct for a clean build. 

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -18,9 +18,10 @@
 
 # Introduction

JDevlieghere wrote:

I've made `lldb-vscode` a symlink to `lldb-dap`. 

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -40,59 +41,59 @@ If you want to make a stand alone plug-in that you can send 
to others on UNIX
 systems:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-cp /path/to/a/built/lldb-vscode .
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+cp /path/to/a/built/lldb-dap .
 cp /path/to/a/built/liblldb.so .
 ```
 
 If you want to make a stand alone plug-in that you can send to others on macOS
 systems:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-cp /path/to/a/built/lldb-vscode .
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+cp /path/to/a/built/lldb-dap .
 rsync -av /path/to/a/built/LLDB.framework LLDB.framework
 ```
 
 You might need to create additional directories for the `liblldb.so` or
 `LLDB.framework` inside or next to the `bin` folder depending on how the
-[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-vscode`
+[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-dap`
 binary. By default the `Debug` builds of LLDB usually includes
 the current executable directory in the rpath, so these steps should work for
 most people.
 
-To create a plug-in that symlinks into your `lldb-vscode` in your build
+To create a plug-in that symlinks into your `lldb-dap` in your build
 directory:
 
 ```bash
-mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
-cp package.json ~/llvm-org.lldb-vscode-0.1.0
-cd ~/llvm-org.lldb-vscode-0.1.0/bin
-ln -s /path/to/a/built/lldb-vscode
+mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
+cp package.json ~/llvm-org.lldb-dap-0.1.0
+cd ~/llvm-org.lldb-dap-0.1.0/bin
+ln -s /path/to/a/built/lldb-dap
 ```
 
-This is handy if you want to debug and develope the `lldb-vscode` executable
+This is handy if you want to debug and develope the `lldb-dap` executable

JDevlieghere wrote:

Given I'm already modifying the line, figured I'd just fix it now. 

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

@JDevlieghere , PTAL 
https://discourse.llvm.org/t/rfc-rename-lldb-vscode-to-lldb-dap/74075/16?u=wallace


https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> @JDevlieghere , PTAL 
> https://discourse.llvm.org/t/rfc-rename-lldb-vscode-to-lldb-dap/74075/16?u=wallace

I just replied! :D 

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Detect against invalid variant index for LibStdC++ std::variant data formatters (PR #69253)

2023-10-17 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/69253

>From 4a668481a1a17512ee412c31b452c114626f8cde Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Mon, 16 Oct 2023 14:21:40 -0700
Subject: [PATCH 1/3] Guard against invalid variant index

---
 lldb/examples/synthetic/gnu_libstdcpp.py | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index 29c926167fb440c..f778065aaca3771 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,6 +914,11 @@ def get_variant_npos_value(index_byte_size):
 if index == npos_value:
 return " No Value"
 
+# Invalid index can happen when the variant is not initialized yet.
+template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
+if index >= template_arg_count:
+return " "
+
 active_type = data_obj.GetType().GetTemplateArgumentType(index)
 return f" Active Type = {active_type.GetDisplayTypeName()} "
 

>From 43f808e39f727aca4199673cbbbddaa0b206dc4b Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Mon, 16 Oct 2023 14:21:40 -0700
Subject: [PATCH 2/3] Guard against invalid variant index

---
 lldb/examples/synthetic/gnu_libstdcpp.py  |  5 
 .../TypeSystem/Clang/TypeSystemClang.cpp  |  3 +++
 .../TestDataFormatterLibStdcxxVariant.py  | 26 +++
 3 files changed, 34 insertions(+)

diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index 29c926167fb440c..f778065aaca3771 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,6 +914,11 @@ def get_variant_npos_value(index_byte_size):
 if index == npos_value:
 return " No Value"
 
+# Invalid index can happen when the variant is not initialized yet.
+template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
+if index >= template_arg_count:
+return " "
+
 active_type = data_obj.GetType().GetTemplateArgumentType(index)
 return f" Active Type = {active_type.GetDisplayTypeName()} "
 
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index f1353db2631ddc6..23aeb8f53ad06dc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7173,6 +7173,9 @@ GetNthTemplateArgument(const 
clang::ClassTemplateSpecializationDecl *decl,
   if (idx < last_idx)
 return &args[idx];
 
+  if (idx >= args.size())
+return nullptr;
+
   // We're asked for the last template argument but we don't want/need to
   // expand it.
   if (!expand_pack || args[last_idx].getKind() != 
clang::TemplateArgument::Pack)
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index 96a9c8d30c45b00..1aa7d463eb359a4 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -71,3 +71,29 @@ def test_with_run_command(self):
 substrs=["v_many_types_no_value =  No Value"],
 )
 """
+
+@add_test_categories(["libstdcxx"])
+def test_invalid_variant_index(self):
+"""Test LibStdC++ data formatter for std::variant with invalid 
index."""
+self.build()
+
+(self.target, self.process, thread, bkpt) = 
lldbutil.run_to_source_breakpoint(
+self, "// break here", lldb.SBFileSpec("main.cpp", False)
+)
+
+lldbutil.continue_to_breakpoint(self.process, bkpt)
+
+self.expect(
+"frame variable v1",
+substrs=["v1 =  Active Type = int  {", "Value = 12", "}"],
+)
+
+var_v1 = thread.frames[0].FindVariable("v1")
+var_v1_raw_obj = var_v1.GetNonSyntheticValue()
+index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
+self.assertTrue(index_obj and index_obj.IsValid())
+
+INVALID_INDEX = 100
+index_obj.SetValueFromCString(INVALID_INDEX)
+
+self.expect("frame variable v1", substrs=["v1 =  "])

>From a042a092f3939fa9bb2c77e086e664ed044976bf Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 17 Oct 2023 11:28:25 -0700
Subject: [PATCH 3/3] Fix crash in GetNthTemplateArgument

---
 lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp| 6 +++---
 .../libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins

[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

fantastic!

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jorge Gorbe Moya via lldb-commits


@@ -388,7 +385,7 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread 
&thread, uint32_t stop_id);
 /// The variable name of \a value or a default placeholder.
 const char *GetNonNullVariableName(lldb::SBValue value);
 
-/// VSCode can't display two variables with the same name, so we need to
+/// DAP can't display two variables with the same name, so we need to

slackito wrote:

Is this a protocol limitation or a VSCode limitation?

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jorge Gorbe Moya via lldb-commits


@@ -196,6 +196,9 @@ Changes to LLDB
   for formatters to quickly find directly nested type when it's known
   where to search for it, avoiding more expensive global search via
   ``SBTarget::FindFirstType``.
+* ``lldb-vscode`` was renamed to ``lldb-dap`` and and its installation
+  nstructions have been updated to reflect this. The underlying functionality

slackito wrote:

Typo: nstructions -> instructions

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jorge Gorbe Moya via lldb-commits

https://github.com/slackito edited 
https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jorge Gorbe Moya via lldb-commits

https://github.com/slackito commented:

Thanks for doing this!

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jorge Gorbe Moya via lldb-commits


@@ -437,7 +434,7 @@ std::string 
CreateUniqueVariableNameForDisplay(lldb::SBValue v,
 /// context (e.g. locals). This can happen due to shadowed variables in
 /// nested blocks.
 ///
-/// As VSCode doesn't render two of more variables with the same name, we

slackito wrote:

Same here, "VSCode doesn't render..." looks like it's talking about VSCode the 
program rather than the protocol, and how we workaround this VSCode-specific 
behavior.

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc++] Implement ranges::contains (PR #65148)

2023-10-17 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/16] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_c

[Lldb-commits] [lldb] Detect against invalid variant index for LibStdC++ std::variant data formatters (PR #69253)

2023-10-17 Thread Greg Clayton via lldb-commits

https://github.com/clayborg approved this pull request.


https://github.com/llvm/llvm-project/pull/69253
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-vscode] Allow specifying a custom escape prefix for LLDB commands (PR #69238)

2023-10-17 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

@clayborg , friendly ping

https://github.com/llvm/llvm-project/pull/69238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Usama Hameed (usama54321)


Changes

[lldb] Refactor InstrumentationRuntimeAsan and add a new plugin 
InstrumentationRuntimeLibsanitizers.

This commit adds InstrumentationRuntimeLibsanitizers, a new runtime plugin for 
ASan. The plugin provides the same
functionality as InstrumentationRuntimeASan, but provides a different set of 
symbols/library names to search for while activating the plugin.

The code can be made a lot cleaner by templatizing the 
InstrumentationRuntimeASan class, and providing the symbol names through the 
template argument. However, at the moment the plugin infrastructure does not 
seem to support templatized plugin classes.

rdar://112491689

---

Patch is 29.96 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/69388.diff


9 Files Affected:

- (modified) lldb/include/lldb/lldb-enumerations.h (+1) 
- (modified) lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt 
(+2) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp 
(+4-208) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h 
(+2-4) 
- (added) 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/CMakeLists.txt 
(+14) 
- (added) 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
 (+108) 
- (added) 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.h
 (+56) 
- (added) lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.cpp 
(+241) 
- (added) lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.h 
(+31) 


``diff
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 36f3030c5226d60..206ff4ed7e6ad05 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -527,6 +527,7 @@ enum InstrumentationRuntimeType {
   eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer = 0x0002,
   eInstrumentationRuntimeTypeMainThreadChecker = 0x0003,
   eInstrumentationRuntimeTypeSwiftRuntimeReporting = 0x0004,
+  eInstrumentationRuntimeTypeLibsanitizersAsan = 0x0005,
   eNumInstrumentationRuntimeTypes
 };
 
diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
index 0b29027018463fe..361e78316f290c0 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
+++ b/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
@@ -1,5 +1,7 @@
+add_subdirectory(Libsanitizers)
 add_lldb_library(lldbPluginInstrumentationRuntimeASan PLUGIN
   InstrumentationRuntimeASan.cpp
+  ReportRetriever.cpp
 
   LINK_LIBS
 lldbBreakpoint
diff --git 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
index 5fcdc808bbb154c..8bcbae47b10429a 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
@@ -69,169 +69,6 @@ bool InstrumentationRuntimeASan::CheckIfRuntimeIsValid(
   return symbol != nullptr;
 }
 
-const char *address_sanitizer_retrieve_report_data_prefix = R"(
-extern "C"
-{
-int __asan_report_present();
-void *__asan_get_report_pc();
-void *__asan_get_report_bp();
-void *__asan_get_report_sp();
-void *__asan_get_report_address();
-const char *__asan_get_report_description();
-int __asan_get_report_access_type();
-size_t __asan_get_report_access_size();
-}
-)";
-
-const char *address_sanitizer_retrieve_report_data_command = R"(
-struct {
-int present;
-int access_type;
-void *pc;
-void *bp;
-void *sp;
-void *address;
-size_t access_size;
-const char *description;
-} t;
-
-t.present = __asan_report_present();
-t.access_type = __asan_get_report_access_type();
-t.pc = __asan_get_report_pc();
-t.bp = __asan_get_report_bp();
-t.sp = __asan_get_report_sp();
-t.address = __asan_get_report_address();
-t.access_size = __asan_get_report_access_size();
-t.description = __asan_get_report_description();
-t
-)";
-
-StructuredData::ObjectSP InstrumentationRuntimeASan::RetrieveReportData() {
-  ProcessSP process_sp = GetProcessSP();
-  if (!process_sp)
-return StructuredData::ObjectSP();
-
-  ThreadSP thread_sp =
-  process_sp->GetThreadList().GetExpressionExecutionThread();
-  StackFrameSP frame_sp =
-  thread_sp->GetSelectedFrame(DoNoSelectMostRelevantFrame);
-
-  if (!frame_sp)
-return StructuredData::ObjectSP();
-
-  EvaluateExpressionOptions options;
-  options.SetUnwindOnError(true);
-  options.SetTryAllThreads(true);
-  options.SetStopOthers(true);
-  options.SetIgnoreBreakpoints(true);
-  options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
-  options.SetPrefix(address_sani

[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Usama Hameed via lldb-commits

https://github.com/usama54321 updated 
https://github.com/llvm/llvm-project/pull/69388

>From 3ee63c7dfd8b92ac8738d19bd3cebffeccfd59ec Mon Sep 17 00:00:00 2001
From: usama 
Date: Tue, 17 Oct 2023 14:35:04 -0700
Subject: [PATCH] [lldb] Refactor InstrumentationRuntimeAsan and add a new
 plugin InstrumentationRuntimeLibsanitizers.

This commit adds InstrumentationRuntimeLibsanitizers, a new runtime
plugin for ASan. The plugin provides the same
functionality as InstrumentationRuntimeASan, but provides a different
set of symbols/library names to search for while activating the plugin.

rdar://112491689
---
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../ASan/CMakeLists.txt   |   2 +
 .../ASan/InstrumentationRuntimeASan.cpp   | 225 +---
 .../ASan/InstrumentationRuntimeASan.h |   6 +-
 .../ASan/Libsanitizers/CMakeLists.txt |  14 +
 .../InstrumentationRuntimeLibsanitizers.cpp   | 108 
 .../InstrumentationRuntimeLibsanitizers.h |  56 
 .../ASan/ReportRetriever.cpp  | 241 ++
 .../ASan/ReportRetriever.h|  31 +++
 9 files changed, 460 insertions(+), 224 deletions(-)
 create mode 100644 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/CMakeLists.txt
 create mode 100644 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
 create mode 100644 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.h
 create mode 100644 
lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.cpp
 create mode 100644 
lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.h

diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 36f3030c5226d60..206ff4ed7e6ad05 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -527,6 +527,7 @@ enum InstrumentationRuntimeType {
   eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer = 0x0002,
   eInstrumentationRuntimeTypeMainThreadChecker = 0x0003,
   eInstrumentationRuntimeTypeSwiftRuntimeReporting = 0x0004,
+  eInstrumentationRuntimeTypeLibsanitizersAsan = 0x0005,
   eNumInstrumentationRuntimeTypes
 };
 
diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
index 0b29027018463fe..361e78316f290c0 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
+++ b/lldb/source/Plugins/InstrumentationRuntime/ASan/CMakeLists.txt
@@ -1,5 +1,7 @@
+add_subdirectory(Libsanitizers)
 add_lldb_library(lldbPluginInstrumentationRuntimeASan PLUGIN
   InstrumentationRuntimeASan.cpp
+  ReportRetriever.cpp
 
   LINK_LIBS
 lldbBreakpoint
diff --git 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
index 5fcdc808bbb154c..3ca0f2d528fea1d 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
@@ -9,23 +9,12 @@
 #include "InstrumentationRuntimeASan.h"
 
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
-#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Core/PluginManager.h"
-#include "lldb/Core/ValueObject.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/StreamFile.h"
-#include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Symbol/Symbol.h"
-#include "lldb/Target/InstrumentationRuntimeStopInfo.h"
-#include "lldb/Target/StopInfo.h"
-#include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Utility/RegularExpression.h"
-#include "lldb/Utility/Stream.h"
-
-#include "llvm/ADT/StringSwitch.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -69,169 +58,6 @@ bool InstrumentationRuntimeASan::CheckIfRuntimeIsValid(
   return symbol != nullptr;
 }
 
-const char *address_sanitizer_retrieve_report_data_prefix = R"(
-extern "C"
-{
-int __asan_report_present();
-void *__asan_get_report_pc();
-void *__asan_get_report_bp();
-void *__asan_get_report_sp();
-void *__asan_get_report_address();
-const char *__asan_get_report_description();
-int __asan_get_report_access_type();
-size_t __asan_get_report_access_size();
-}
-)";
-
-const char *address_sanitizer_retrieve_report_data_command = R"(
-struct {
-int present;
-int access_type;
-void *pc;
-void *bp;
-void *sp;
-void *address;
-size_t access_size;
-const char *description;
-} t;
-
-t.present = __asan_report_present();
-t.access_type = __asan_get_report_access_type();
-t.pc = __asan_get_report_pc();
-t.bp = __asan_get_report_bp();
-t.sp = __asan_get_report_sp();
-t.address = __asan_get_report_address();
-t.access_

[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Usama Hameed via lldb-commits

usama54321 wrote:

@llvm-ci test

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff cf670d5e56d14afa7c3e005c13588fd7b5ee75ce 
76493df4dcfc055ec0b4f7d745f3799b904f679d -- 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
 
lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.h
 lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.cpp 
lldb/source/Plugins/InstrumentationRuntime/ASan/ReportRetriever.h 
lldb/include/lldb/lldb-enumerations.h 
lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp 
lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h
``





View the diff from clang-format here.


``diff
diff --git 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
index 8bcbae47b104..6db39d1eb3f6 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
@@ -81,7 +81,8 @@ bool InstrumentationRuntimeASan::NotifyBreakpointHit(
 
   ProcessSP process_sp = instance->GetProcessSP();
 
-  return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id, 
break_loc_id);
+  return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id,
+  break_loc_id);
 }
 
 void InstrumentationRuntimeASan::Activate() {
@@ -92,7 +93,8 @@ void InstrumentationRuntimeASan::Activate() {
   if (!process_sp)
 return;
 
-  Breakpoint *breakpoint = 
ReportRetriever::SetupBreakpoint(GetRuntimeModuleSP(), process_sp, 
ConstString("_ZN6__asanL7AsanDieEv"));
+  Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint(
+  GetRuntimeModuleSP(), process_sp, ConstString("_ZN6__asanL7AsanDieEv"));
 
   if (!breakpoint)
 return;
diff --git 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
index 6ab9f28010ae..04ee0ba8129a 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/Libsanitizers/InstrumentationRuntimeLibsanitizers.cpp
@@ -1,4 +1,5 @@
-//===-- InstrumentationRuntimeLibsanitizers.cpp 
===//
+//===-- InstrumentationRuntimeLibsanitizers.cpp
+//===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -22,13 +23,16 @@ using namespace lldb_private;
 LLDB_PLUGIN_DEFINE(InstrumentationRuntimeLibsanitizers)
 
 lldb::InstrumentationRuntimeSP
-InstrumentationRuntimeLibsanitizers::CreateInstance(const lldb::ProcessSP 
&process_sp) {
-  return InstrumentationRuntimeSP(new 
InstrumentationRuntimeLibsanitizers(process_sp));
+InstrumentationRuntimeLibsanitizers::CreateInstance(
+const lldb::ProcessSP &process_sp) {
+  return InstrumentationRuntimeSP(
+  new InstrumentationRuntimeLibsanitizers(process_sp));
 }
 
 void InstrumentationRuntimeLibsanitizers::Initialize() {
   PluginManager::RegisterPlugin(
-  GetPluginNameStatic(), "AddressSanitizer instrumentation runtime plugin 
for Libsanitizers.",
+  GetPluginNameStatic(),
+  "AddressSanitizer instrumentation runtime plugin for Libsanitizers.",
   CreateInstance, GetTypeStatic);
 }
 
@@ -36,11 +40,14 @@ void InstrumentationRuntimeLibsanitizers::Terminate() {
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
-lldb::InstrumentationRuntimeType 
InstrumentationRuntimeLibsanitizers::GetTypeStatic() {
+lldb::InstrumentationRuntimeType
+InstrumentationRuntimeLibsanitizers::GetTypeStatic() {
   return eInstrumentationRuntimeTypeLibsanitizersAsan;
 }
 
-InstrumentationRuntimeLibsanitizers::~InstrumentationRuntimeLibsanitizers() { 
Deactivate(); }
+InstrumentationRuntimeLibsanitizers::~InstrumentationRuntimeLibsanitizers() {
+  Deactivate();
+}
 
 const RegularExpression &
 InstrumentationRuntimeLibsanitizers::GetPatternForRuntimeLibrary() {
@@ -70,7 +77,8 @@ bool InstrumentationRuntimeLibsanitizers::NotifyBreakpointHit(
 
   ProcessSP process_sp = instance->GetProcessSP();
 
-  return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id, 
break_loc_id);
+  return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id,
+  break_loc_id);
 }
 
 void InstrumentationRuntimeLibsanitizers::Activate() {
@@ -81,15 +89,17 @@ void InstrumentationRuntimeLibsanitizers::Activate() {
   if (

[Lldb-commits] [lldb] 5990850 - [LLDB][NFC] Add a missing namespace

2023-10-17 Thread walter erquinigo via lldb-commits

Author: walter erquinigo
Date: 2023-10-17T18:15:29-04:00
New Revision: 59908504cd7a72cd2a614e5c6db5410101209365

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

LOG: [LLDB][NFC] Add a missing namespace

This adds back a namespace to the value of a #define statement. This is needed 
to prevent collision with other types with the same name.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 8ba7cd34f43e044..646d5d9a471c41c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -62,7 +62,7 @@ class SymbolFileDWARFDebugMap;
 class SymbolFileDWARFDwo;
 class SymbolFileDWARFDwp;
 
-#define DIE_IS_BEING_PARSED ((Type *)1)
+#define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
 
 class SymbolFileDWARF : public SymbolFileCommon {
   /// LLVM RTTI support.



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


[Lldb-commits] [lldb] 170b552 - [lldb] Scalar::GetValue() should take a Stream by reference (#69231)

2023-10-17 Thread via lldb-commits

Author: Alex Langford
Date: 2023-10-17T15:40:51-07:00
New Revision: 170b552136f845ffc4267c8728629b6b6b19518d

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

LOG: [lldb] Scalar::GetValue() should take a Stream by reference (#69231)

This function always expects the pointer to be valid, a reference seems
more appropriate.

Added: 


Modified: 
lldb/include/lldb/Utility/Scalar.h
lldb/source/Core/Value.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Utility/Scalar.cpp
lldb/unittests/Utility/ScalarTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/Scalar.h 
b/lldb/include/lldb/Utility/Scalar.h
index 34c2111ae0ac6ee..8e087a5ddeb8552 100644
--- a/lldb/include/lldb/Utility/Scalar.h
+++ b/lldb/include/lldb/Utility/Scalar.h
@@ -101,7 +101,7 @@ class Scalar {
 
   const char *GetTypeAsCString() const { return GetValueTypeAsCString(m_type); 
}
 
-  void GetValue(Stream *s, bool show_type) const;
+  void GetValue(Stream &s, bool show_type) const;
 
   bool IsValid() const { return (m_type >= e_int) && (m_type <= e_float); }
 

diff  --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp
index 8efcfd3b4a1adac..995cc934c82044a 100644
--- a/lldb/source/Core/Value.cpp
+++ b/lldb/source/Core/Value.cpp
@@ -98,7 +98,9 @@ void Value::AppendBytes(const void *bytes, int len) {
 }
 
 void Value::Dump(Stream *strm) {
-  m_value.GetValue(strm, true);
+  if (!strm)
+return;
+  m_value.GetValue(*strm, true);
   strm->Printf(", value_type = %s, context = %p, context_type = %s",
Value::GetValueTypeAsCString(m_value_type), m_context,
Value::GetContextTypeAsCString(m_context_type));

diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index dcff53ff843f328..e1275ce711fc172 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1773,7 +1773,7 @@ CommandInterpreter::PreprocessToken(std::string 
&expr_str) {
 
   StreamString value_strm;
   const bool show_type = false;
-  scalar.GetValue(&value_strm, show_type);
+  scalar.GetValue(value_strm, show_type);
   size_t value_string_size = value_strm.GetSize();
   if (value_string_size) {
 expr_str = value_strm.GetData();

diff  --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 791c0fb74352913..5ad68065bce1b76 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -153,20 +153,20 @@ bool Scalar::IsZero() const {
   return false;
 }
 
-void Scalar::GetValue(Stream *s, bool show_type) const {
+void Scalar::GetValue(Stream &s, bool show_type) const {
   if (show_type)
-s->Printf("(%s) ", GetTypeAsCString());
+s.Printf("(%s) ", GetTypeAsCString());
 
   switch (m_type) {
   case e_void:
 break;
   case e_int:
-s->PutCString(llvm::toString(m_integer, 10));
+s.PutCString(llvm::toString(m_integer, 10));
 break;
   case e_float:
 llvm::SmallString<24> string;
 m_float.toString(string);
-s->PutCString(string);
+s.PutCString(string);
 break;
   }
 }
@@ -894,6 +894,6 @@ bool Scalar::SetBit(uint32_t bit) {
 
 llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &os, const 
Scalar &scalar) {
   StreamString s;
-  scalar.GetValue(&s, /*show_type*/ true);
+  scalar.GetValue(s, /*show_type*/ true);
   return os << s.GetString();
 }

diff  --git a/lldb/unittests/Utility/ScalarTest.cpp 
b/lldb/unittests/Utility/ScalarTest.cpp
index 17dfc689dd4e87b..29a4bcd356f1135 100644
--- a/lldb/unittests/Utility/ScalarTest.cpp
+++ b/lldb/unittests/Utility/ScalarTest.cpp
@@ -241,7 +241,7 @@ TEST(ScalarTest, ExtractBitfield) {
 
 template  static std::string ScalarGetValue(T value) {
   StreamString stream;
-  Scalar(value).GetValue(&stream, false);
+  Scalar(value).GetValue(stream, false);
   return std::string(stream.GetString());
 }
 



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


[Lldb-commits] [lldb] [lldb] Scalar::GetValue() should take a Stream by reference (PR #69231)

2023-10-17 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/69231
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 7d1bf1c - [LLDB][NFC] Move some constructors to their cpp file

2023-10-17 Thread walter erquinigo via lldb-commits

Author: walter erquinigo
Date: 2023-10-17T18:50:18-04:00
New Revision: 7d1bf1c5cf284ce1a18fe0ce4a4cf91f3e514866

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

LOG: [LLDB][NFC] Move some constructors to their cpp file

CompilerType constructors rely on the NDEBUG macro, so it's better to move them 
to their cpp file so that the header doesn't get confused when this macro is 
used differently for other compilation units.

Added: 


Modified: 
lldb/include/lldb/Symbol/CompilerType.h
lldb/source/Symbol/CompilerType.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/CompilerType.h 
b/lldb/include/lldb/Symbol/CompilerType.h
index 414db18e52ed71c..0a9533a1ac0efc1 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -42,10 +42,7 @@ class CompilerType {
   ///
   /// \see lldb_private::TypeSystemClang::GetType(clang::QualType)
   CompilerType(lldb::TypeSystemWP type_system,
-   lldb::opaque_compiler_type_t type)
-: m_type_system(type_system), m_type(type) {
-assert(Verify() && "verification failed");
-  }
+   lldb::opaque_compiler_type_t type);
 
   /// This is a minimal wrapper of a TypeSystem shared pointer as
   /// returned by CompilerType which conventien dyn_cast support.
@@ -88,10 +85,8 @@ class CompilerType {
 lldb::TypeSystemSP GetSharedPointer() const { return m_typesystem_sp; }
   };
 
-  CompilerType(TypeSystemSPWrapper type_system, lldb::opaque_compiler_type_t 
type)
-: m_type_system(type_system.GetSharedPointer()), m_type(type) {
-assert(Verify() && "verification failed");
-  }
+  CompilerType(TypeSystemSPWrapper type_system,
+   lldb::opaque_compiler_type_t type);
 
   CompilerType(const CompilerType &rhs)
   : m_type_system(rhs.m_type_system), m_type(rhs.m_type) {}

diff  --git a/lldb/source/Symbol/CompilerType.cpp 
b/lldb/source/Symbol/CompilerType.cpp
index 7732a66f49d8dbb..78cc8dad94a9c5f 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -951,6 +951,18 @@ bool CompilerType::GetValueAsScalar(const 
lldb_private::DataExtractor &data,
   return false;
 }
 
+CompilerType::CompilerType(CompilerType::TypeSystemSPWrapper type_system,
+   lldb::opaque_compiler_type_t type)
+: m_type_system(type_system.GetSharedPointer()), m_type(type) {
+  assert(Verify() && "verification failed");
+}
+
+CompilerType::CompilerType(lldb::TypeSystemWP type_system,
+   lldb::opaque_compiler_type_t type)
+: m_type_system(type_system), m_type(type) {
+  assert(Verify() && "verification failed");
+}
+
 #ifndef NDEBUG
 bool CompilerType::Verify() const {
   if (!IsValid())



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


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -1,5 +1,7 @@
+add_subdirectory(Libsanitizers)

JDevlieghere wrote:

Rather than living under the Asan plugin, it seems like his should be living at 
the same level. If there's shared code between the two plugins, we should hoist 
that up into a separate library (something like `plugins/Process/Utility`, but 
for the instrumentation plugins. 

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,56 @@
+//===-- InstrumentationRuntimeLibsanitizers.h *- 
C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMELIBSANITIZERS_H
+#define 
LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMELIBSANITIZERS_H
+
+#include "../ReportRetriever.h"
+
+
+namespace lldb_private {
+
+class InstrumentationRuntimeLibsanitizers : public 
lldb_private::InstrumentationRuntime {

JDevlieghere wrote:

You probably don't need the `lldb_private::` here?

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,108 @@
+//===-- InstrumentationRuntimeLibsanitizers.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "InstrumentationRuntimeLibsanitizers.h"
+
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/RegularExpression.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(InstrumentationRuntimeLibsanitizers)
+
+lldb::InstrumentationRuntimeSP
+InstrumentationRuntimeLibsanitizers::CreateInstance(const lldb::ProcessSP 
&process_sp) {
+  return InstrumentationRuntimeSP(new 
InstrumentationRuntimeLibsanitizers(process_sp));
+}
+
+void InstrumentationRuntimeLibsanitizers::Initialize() {
+  PluginManager::RegisterPlugin(
+  GetPluginNameStatic(), "AddressSanitizer instrumentation runtime plugin 
for Libsanitizers.",
+  CreateInstance, GetTypeStatic);
+}
+
+void InstrumentationRuntimeLibsanitizers::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb::InstrumentationRuntimeType 
InstrumentationRuntimeLibsanitizers::GetTypeStatic() {
+  return eInstrumentationRuntimeTypeLibsanitizersAsan;
+}
+
+InstrumentationRuntimeLibsanitizers::~InstrumentationRuntimeLibsanitizers() { 
Deactivate(); }
+
+const RegularExpression &
+InstrumentationRuntimeLibsanitizers::GetPatternForRuntimeLibrary() {
+  // FIXME: This shouldn't include the "dylib" suffix.
+  static RegularExpression regex(
+  llvm::StringRef("libsystem_sanitizers\\.dylib"));
+  return regex;
+}
+
+bool InstrumentationRuntimeLibsanitizers::CheckIfRuntimeIsValid(
+const lldb::ModuleSP module_sp) {
+  const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
+  ConstString("__asan_abi_init"), lldb::eSymbolTypeAny);
+
+  return symbol != nullptr;
+}
+
+bool InstrumentationRuntimeLibsanitizers::NotifyBreakpointHit(
+void *baton, StoppointCallbackContext *context, user_id_t break_id,
+user_id_t break_loc_id) {
+  assert(baton && "null baton");
+  if (!baton)
+return false;
+
+  InstrumentationRuntimeLibsanitizers *const instance =
+  static_cast(baton);
+
+  ProcessSP process_sp = instance->GetProcessSP();
+
+  return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id, 
break_loc_id);
+}
+
+void InstrumentationRuntimeLibsanitizers::Activate() {
+  if (IsActive())
+return;
+
+  ProcessSP process_sp = GetProcessSP();
+  if (!process_sp)
+return;
+
+  Breakpoint *breakpoint = 
ReportRetriever::SetupBreakpoint(GetRuntimeModuleSP(), process_sp, 
ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
+
+  if (!breakpoint)
+return;
+
+  bool sync = false;
+
+  
breakpoint->SetCallback(InstrumentationRuntimeLibsanitizers::NotifyBreakpointHit,
 this,
+  sync);
+  breakpoint->SetBreakpointKind("address-sanitizer-report");
+  SetBreakpointID(breakpoint->GetID());
+
+  SetActive(true);
+}
+
+void InstrumentationRuntimeLibsanitizers::Deactivate() {
+  if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
+ProcessSP process_sp = GetProcessSP();
+if (process_sp) {

JDevlieghere wrote:

You can do:

```
if (ProcessSP process_sp = GetProcessSP()) {
  ...
}
```

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,31 @@
+//===-- ReportRetriever.h *- C++ -*-===//

JDevlieghere wrote:

Fix ASCII art

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,108 @@
+//===-- InstrumentationRuntimeLibsanitizers.cpp 
===//

JDevlieghere wrote:

Fix ASCII art

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (PR #69388)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,56 @@
+//===-- InstrumentationRuntimeLibsanitizers.h *- 
C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMELIBSANITIZERS_H
+#define 
LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_ASAN_INSTRUMENTATIONRUNTIMELIBSANITIZERS_H

JDevlieghere wrote:

Moving the Libsanitizers runtime up will also avoid this abomination of a 
header guard :-) 

https://github.com/llvm/llvm-project/pull/69388
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Rename lldb-vscode to lldb-dap (PR #69264)

2023-10-17 Thread Jonas Devlieghere via lldb-commits


@@ -388,7 +385,7 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread 
&thread, uint32_t stop_id);
 /// The variable name of \a value or a default placeholder.
 const char *GetNonNullVariableName(lldb::SBValue value);
 
-/// VSCode can't display two variables with the same name, so we need to
+/// DAP can't display two variables with the same name, so we need to

JDevlieghere wrote:

Yes, this appears to be a VSCode limitation: 
https://github.com/microsoft/vscode/issues/107506. I'll revert this back to 
`VSCode`. 

https://github.com/llvm/llvm-project/pull/69264
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Detect against invalid variant index for LibStdC++ std::variant data formatters (PR #69253)

2023-10-17 Thread via lldb-commits

https://github.com/jeffreytan81 closed 
https://github.com/llvm/llvm-project/pull/69253
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 659a48f - Detect against invalid variant index for LibStdC++ std::variant data formatters (#69253)

2023-10-17 Thread via lldb-commits

Author: jeffreytan81
Date: 2023-10-17T17:26:05-07:00
New Revision: 659a48f25a96b7072b44d372c47385a2608f8671

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

LOG: Detect against invalid variant index for LibStdC++ std::variant data 
formatters (#69253)

https://github.com/llvm/llvm-project/pull/68012/files added new data
formatters for LibStdC++ std::variant.

However, this formatter can crash if std::variant's index field has
invalid value (exceeds the number of template arguments).
This can happen if the current IP stops at a place std::variant is not
initialized yet.

This patch fixes the crash by ensuring the index is a valid value.

-

Co-authored-by: jeffreytan81 

Added: 


Modified: 
lldb/examples/synthetic/gnu_libstdcpp.py
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py

Removed: 




diff  --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index 29c926167fb440c..f778065aaca3771 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,6 +914,11 @@ def get_variant_npos_value(index_byte_size):
 if index == npos_value:
 return " No Value"
 
+# Invalid index can happen when the variant is not initialized yet.
+template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
+if index >= template_arg_count:
+return " "
+
 active_type = data_obj.GetType().GetTemplateArgumentType(index)
 return f" Active Type = {active_type.GetDisplayTypeName()} "
 

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index f1353db2631ddc6..0b8edbb75eb9aee 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7182,6 +7182,9 @@ GetNthTemplateArgument(const 
clang::ClassTemplateSpecializationDecl *decl,
   // Note that 'idx' counts from the beginning of all template arguments
   // (including the ones preceding the parameter pack).
   const auto &pack = args[last_idx];
+  if (idx >= pack.pack_size())
+return nullptr;
+
   const size_t pack_idx = idx - last_idx;
   assert(pack_idx < pack.pack_size() && "parameter pack index out-of-bounds");
   return &pack.pack_elements()[pack_idx];

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index 96a9c8d30c45b00..ba1641888b6f30f 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -71,3 +71,29 @@ def test_with_run_command(self):
 substrs=["v_many_types_no_value =  No Value"],
 )
 """
+
+@add_test_categories(["libstdcxx"])
+def test_invalid_variant_index(self):
+"""Test LibStdC++ data formatter for std::variant with invalid 
index."""
+self.build()
+
+(self.target, self.process, thread, bkpt) = 
lldbutil.run_to_source_breakpoint(
+self, "// break here", lldb.SBFileSpec("main.cpp", False)
+)
+
+lldbutil.continue_to_breakpoint(self.process, bkpt)
+
+self.expect(
+"frame variable v1",
+substrs=["v1 =  Active Type = int  {", "Value = 12", "}"],
+)
+
+var_v1 = thread.frames[0].FindVariable("v1")
+var_v1_raw_obj = var_v1.GetNonSyntheticValue()
+index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
+self.assertTrue(index_obj and index_obj.IsValid())
+
+INVALID_INDEX = "100"
+index_obj.SetValueFromCString(INVALID_INDEX)
+
+self.expect("frame variable v1", substrs=["v1 =  "])



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


[Lldb-commits] [lldb] Detect against invalid variant index for LibStdC++ std::variant data formatters (PR #69253)

2023-10-17 Thread Jordan Rupprecht via lldb-commits

rupprecht wrote:

This seems to cause `TestTemplatePackArgs.py` to fail, e.g. 
https://lab.llvm.org/buildbot/#/builders/68/builds/61819

```shell
  File 
"/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/lang/cpp/class-template-parameter-pack/TestTemplatePackArgs.py",
 line 42, in test_template_argument_pack
self.assertEqual(nested_template.GetTemplateArgumentType(2).GetName(), 
"bool")
AssertionError: '' != 'bool'
```

https://github.com/llvm/llvm-project/pull/69253
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)

2023-10-17 Thread via lldb-commits

https://github.com/taalhaataahir0102 created 
https://github.com/llvm/llvm-project/pull/69422

This is the current issue for symbol search:
https://github.com/llvm/llvm-project/issues/57372

Previously some work has already been done on this. A PR was generated but it 
remained in review:
https://reviews.llvm.org/D136462
In short previous approach was following:
Changing the symbol names (making the searched part colorized) -> printing them 
-> restoring the symbol names back in their original form.
The reviewers suggested that instead of changing the symbol table, this 
colorization should be done in the dump function itself. We've prepared an 
initial draft in which we've redefined the dump functions which takes the regex 
searched symbol as an argument and for every dump function we've written a 
PrintRed function which is actually responsible for colorizing the searched 
string inside a symbol.

>From 8e5e67ff640aa0ff14b1a0bd0110b88c539ccfe8 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100...@lums.edu.pk>
Date: Wed, 11 Oct 2023 14:27:15 +0500
Subject: [PATCH 1/6] colorization

---
 lldb/include/lldb/Core/Address.h |   6 +
 lldb/include/lldb/Symbol/Symbol.h|   3 +
 lldb/include/lldb/Symbol/SymbolContext.h |  11 +
 lldb/source/Commands/CommandObjectTarget.cpp |  97 -
 lldb/source/Core/Address.cpp | 428 +++
 lldb/source/Symbol/Symbol.cpp|  68 +++
 lldb/source/Symbol/SymbolContext.cpp | 248 +++
 7 files changed, 859 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546f8..4151817813c7e35 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -249,6 +249,12 @@ class Address {
 uint32_t addr_byte_size = UINT32_MAX,
 bool all_ranges = false) const;
 
+
+  bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const 
char* name,
+DumpStyle fallback_style = DumpStyleInvalid,
+uint32_t addr_byte_size = UINT32_MAX,
+bool all_ranges = false) const;
+
   AddressClass GetAddressClass() const;
 
   /// Get the file address.
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe40..a9e91fbac055a92 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -177,6 +177,9 @@ class Symbol : public SymbolContextScope {
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
   Target *target) const;
 
+  void GetDescription(Stream *s, lldb::DescriptionLevel level,
+  Target *target, const char* name) const;
+
   bool IsSynthetic() const { return m_is_synthetic; }
 
   bool IsSyntheticWithAutoGeneratedName() const;
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a1656..947c39eec96e53a 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -153,6 +153,14 @@ class SymbolContext {
bool show_function_arguments,
bool show_function_name) const;
 
+  bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
+   const Address &so_addr, bool show_fullpaths,
+   bool show_module, bool show_inlined_frames,
+   bool show_function_arguments,
+   bool show_function_name, 
+   const char* name) const;
+   
+
   /// Get the address range contained within a symbol context.
   ///
   /// Address range priority is as follows:
@@ -220,6 +228,9 @@ class SymbolContext {
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
   Target *target) const;
 
+  void GetDescription(Stream *s, lldb::DescriptionLevel level,
+  Target *target, const char* name) const;
+
   uint32_t GetResolvedMask() const;
 
   lldb::LanguageType GetLanguage() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 0ef0926d61f..aa59e3680a37872 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1513,6 +1513,98 @@ static bool LookupAddressInModule(CommandInterpreter 
&interpreter, Stream &strm,
   return false;
 }
 
+//===
+static void PrintRed(Stream &strm, const char *text, const char *name) {
+const char *red_start = "\033[31m";  // Set text color to red
+const char *reset_color = "\033[0m";   // Reset text color to default
+
+// Escape1(ansi.red)
+
+const char *match = text;
+size_t name_len = strlen(name);
+
+while ((match = strstr(match, name))) {
+size_t prefix_len = match - 

[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)

2023-10-17 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 112e49b38150b8bfdef01434309d1b05204193e4 
07e3a614c1a346c3a09dbf232328b83b744750b2 -- lldb/include/lldb/Core/Address.h 
lldb/include/lldb/Symbol/Symbol.h lldb/include/lldb/Symbol/SymbolContext.h 
lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Core/Address.cpp 
lldb/source/Symbol/Symbol.cpp lldb/source/Symbol/SymbolContext.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index 4151817813c7..92355e88c6ea 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -249,9 +249,8 @@ public:
 uint32_t addr_byte_size = UINT32_MAX,
 bool all_ranges = false) const;
 
-
-  bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const 
char* name,
-DumpStyle fallback_style = DumpStyleInvalid,
+  bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
+const char *name, DumpStyle fallback_style = DumpStyleInvalid,
 uint32_t addr_byte_size = UINT32_MAX,
 bool all_ranges = false) const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index a9e91fbac055..43aceeb0a2aa 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -177,8 +177,8 @@ public:
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
   Target *target) const;
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target, const char* name) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *name) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index 947c39eec96e..2ac5f4162c52 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -156,10 +156,8 @@ public:
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address &so_addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name, 
-   const char* name) const;
-   
+   bool show_function_arguments, bool show_function_name,
+   const char *name) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -228,8 +226,8 @@ public:
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
   Target *target) const;
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target, const char* name) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *name) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 8086474a32a9..dd833a57ddbf 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -56,6 +56,7 @@
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "lldb/Utility/AnsiTerminal.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -63,7 +64,6 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
-#include "lldb/Utility/AnsiTerminal.h"
 #include 
 
 using namespace lldb;
@@ -1518,30 +1518,32 @@ static bool LookupAddressInModule(CommandInterpreter 
&interpreter, Stream &strm,
 
 // This function is the one which colorizes the regex symbol searched
 static void PrintRed(Stream &strm, const char *text, const char *name) {
-const std::string red_start = ANSI_ESC_START + 
std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
-const std::string reset_color = ANSI_ESC_START + 
std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
-
-const char *match = text;
-size_t name_len = strlen(name);
-
-while ((match = strstr(match, name))) {
-size_t prefix_len = match - text;
-
-strm.Write(text, prefix_len);
-strm.PutCString(red_start.c_str());
-strm.Write(match, name_len);
-strm.PutCString(reset_color.c_str());
-
-text = match + name_len;
-match = text;
-}
+  const std::string red_start =
+  ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_R