[Lldb-commits] [lldb] 58e750b - [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (#98041)

2024-07-09 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-09T09:59:49+02:00
New Revision: 58e750bfd621ac7ef8647eb1170b254e05ffc10d

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

LOG: [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache 
(#98041)

In async mode, the test terminates sooner than it should
(`run_to_source_breakpoint` does not work in this mode), and then the
test crashes due to #76057. Most of the time, the test does not fail
because its already XFAILed, but the crash still registers as a failure.

Added: 


Modified: 
lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py

Removed: 




diff  --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 0942dcd655b75..ccefc28946e06 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -111,6 +111,7 @@ def do_test(self, one_target, one_debugger):
 else:
 if one_target:
 new_debugger = lldb.SBDebugger().Create()
+new_debugger.SetAsync(False)
 self.old_debugger = self.dbg
 self.dbg = new_debugger
 



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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-09 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-09 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `lldb` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/59/builds/1234

Here is the relevant piece of the build log for the reference:
```
Step 6 (test) failure: build (failure)
...
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5-index-is-used.cpp (1606 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5-implicit-const.s (1607 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5_locations.s (1608 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5-line-strp.s (1609 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5_tu_index_abbrev_offset.s (1610 
of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5-split.s (1611 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwarf5-partial-index.cpp (1612 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwo-not-found-warning.cpp (1613 of 
1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwo-type-in-main-file.s (1614 of 1989)
PASS: lldb-shell :: SymbolFile/DWARF/x86/dwp-debug-types.s (1615 of 1989)
FAIL: lldb-shell :: SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp (1616 of 
1989)
 TEST 'lldb-shell :: 
SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 21: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang 
--target=specify-a-target-or-use-a-_host-substitution -target x86_64-pc-linux 
-gdwarf-5 -gsplit-dwarf-fdebug-types-section -gpubnames -c 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.main.o
+ /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang 
--target=specify-a-target-or-use-a-_host-substitution -target x86_64-pc-linux 
-gdwarf-5 -gsplit-dwarf -fdebug-types-section -gpubnames -c 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.main.o
RUN: at line 23: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang 
--target=specify-a-target-or-use-a-_host-substitution -target x86_64-pc-linux 
-gdwarf-5 -gsplit-dwarf -DVARIANT-fdebug-types-section -gpubnames -c 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.foo.o
+ /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang 
--target=specify-a-target-or-use-a-_host-substitution -target x86_64-pc-linux 
-gdwarf-5 -gsplit-dwarf -DVARIANT -fdebug-types-section -gpubnames -c 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.foo.o
RUN: at line 25: 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/ld.lld 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.main.o
 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.foo.o
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp
+ /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/ld.lld 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.main.o
 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.foo.o
 -o 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp
ld.lld: warning: cannot find entry symbol _start; not setting start address
RUN: at line 28: rm -f 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.dwp
+ rm -f 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/dwp-foreign-type-units.cpp.tmp.dwp
RUN: at line 29: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb 
--no-lldbinit -S 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/lit-lldb-init-quiet
-o "type lookup IntegerType"-o "type lookup FloatType" 

[Lldb-commits] [lldb] cd89d92 - [lldb] Correct invalid format style (#98089)

2024-07-09 Thread via lldb-commits

Author: Alex Langford
Date: 2024-07-09T09:34:06+01:00
New Revision: cd89d926aed1de3d1255043eba39801b54393040

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

LOG: [lldb] Correct invalid format style (#98089)

Fixes https://github.com/llvm/llvm-project/issues/97511

Added: 


Modified: 
lldb/source/Target/StackFrameList.cpp

Removed: 




diff  --git a/lldb/source/Target/StackFrameList.cpp 
b/lldb/source/Target/StackFrameList.cpp
index 314b5e39c7169..0cf9ce1bf043f 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -966,9 +966,9 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t 
first_frame,
 // Check for interruption here.  If we're fetching arguments, this loop
 // can go slowly:
 Debugger &dbg = m_thread.GetProcess()->GetTarget().GetDebugger();
-if (INTERRUPT_REQUESTED(dbg, 
-  "Interrupted dumping stack for thread {0:hex} with {1} shown.",
-  m_thread.GetID(), num_frames_displayed))
+if (INTERRUPT_REQUESTED(
+dbg, "Interrupted dumping stack for thread {0:x} with {1} shown.",
+m_thread.GetID(), num_frames_displayed))
   break;
 
 



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


[Lldb-commits] [lldb] [lldb] Correct invalid format style (PR #98089)

2024-07-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] ae5aebd - [lldb][NFC] Add maybe_unused to err used in asserts (#98055)

2024-07-09 Thread via lldb-commits

Author: Keith Smiley
Date: 2024-07-09T10:35:56+01:00
New Revision: ae5aebd48df8d15f06a7a9aa7a9e193d32cd5c85

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

LOG: [lldb][NFC] Add maybe_unused to err used in asserts (#98055)

Added: 


Modified: 
lldb/tools/debugserver/source/PThreadMutex.h

Removed: 




diff  --git a/lldb/tools/debugserver/source/PThreadMutex.h 
b/lldb/tools/debugserver/source/PThreadMutex.h
index a4535dd79172c..17f9fdff5f2d3 100644
--- a/lldb/tools/debugserver/source/PThreadMutex.h
+++ b/lldb/tools/debugserver/source/PThreadMutex.h
@@ -78,13 +78,13 @@ class PThreadMutex {
   };
 
   PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_init(&m_mutex, NULL);
 assert(err == 0);
   }
 
   PThreadMutex(int type) {
-int err;
+[[maybe_unused]] int err;
 ::pthread_mutexattr_t attr;
 err = ::pthread_mutexattr_init(&attr);
 assert(err == 0);
@@ -97,7 +97,7 @@ class PThreadMutex {
   }
 
   ~PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_destroy(&m_mutex);
 if (err != 0) {
   err = Unlock();



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


[Lldb-commits] [lldb] [lldb][NFC] Add maybe_unused to err used in asserts (PR #98055)

2024-07-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return optional from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Fair point, iirc all the callers go on to iterate the map so no one is handling 
failure in a special way. I'll update this.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,468 @@
+//===-- DILAST.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/Core/DILAST.h"
+#include "lldb/API/SBType.h"
+#include "lldb/Core/ValueObjectRegister.h"
+#include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/RegisterContext.h"
+#include "llvm/ADT/StringRef.h"
+
+#include 
+
+namespace lldb_private {
+
+lldb::ValueObjectSP DILGetSPWithLock(lldb::ValueObjectSP in_valobj_sp,
+ lldb::DynamicValueType use_dynamic,
+ bool use_synthetic) {
+  Process::StopLocker stop_locker;
+  std::unique_lock lock;
+  Status error;
+
+  if (!in_valobj_sp) {
+error.SetErrorString("invalid value object");
+return in_valobj_sp;
+  }
+
+  lldb::ValueObjectSP value_sp = in_valobj_sp;
+
+  Target *target = value_sp->GetTargetSP().get();
+  // If this ValueObject holds an error, then it is valuable for that.
+  if (value_sp->GetError().Fail())
+return value_sp;
+
+  if (!target)
+return lldb::ValueObjectSP();
+
+  lock = std::unique_lock(target->GetAPIMutex());
+
+  lldb::ProcessSP process_sp(value_sp->GetProcessSP());
+  if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
+// We don't allow people to play around with ValueObject if the process
+// is running. If you want to look at values, pause the process, then
+// look.
+error.SetErrorString("process must be stopped.");
+return lldb::ValueObjectSP();
+  }
+
+  if (use_dynamic != lldb::eNoDynamicValues) {
+lldb::ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(use_dynamic);
+if (dynamic_sp)
+  value_sp = dynamic_sp;
+  }
+
+  if (use_synthetic) {
+lldb::ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
+if (synthetic_sp)
+  value_sp = synthetic_sp;
+  }
+
+  if (!value_sp)
+error.SetErrorString("invalid value object");
+
+  return value_sp;
+}
+
+CompilerType DILASTNode::result_type_deref() const {
+  auto type = result_type();
+  return type.IsReferenceType() ? type.GetNonReferenceType() : type;
+}
+
+static std::unordered_map context_args;
+
+bool IsContextVar(const std::string &name) {
+  return context_args.find(name) != context_args.end();
+}

labath wrote:

This definitely needs to be scoped to something (and not a global), but since 
its not used right now, let's remove it.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {

labath wrote:

Some of the names defined here have embedded namespace names (DILMemberInfo), 
while others (IdentifierInfo) have deceptively generic name even though they're 
specific to the DIL. What do you (all) think about putting all of this in a 
namespace (I suggest `dil`)?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.
+bool IsSmartPtrType(CompilerType type);
+
+/// Class used to store & manipulate information about identifiers.
+class IdentifierInfo {
+private:
+  using MemberPath = std::vector;
+  using IdentifierInfoPtr = std::unique_ptr;

labath wrote:

elsewhere, we'd use IdentifierInfoUP

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }

labath wrote:

What would you say to deleting this and using `optional` instead?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.
+bool IsSmartPtrType(CompilerType type);
+
+/// Class used to store & manipulate information about identifiers.
+class IdentifierInfo {
+private:
+  using MemberPath = std::vector;
+  using IdentifierInfoPtr = std::unique_ptr;
+
+public:
+  enum class Kind {
+kValue,
+kContextArg,
+kMemberPath,
+kThisKeyword,
+  };
+
+  static IdentifierInfoPtr FromValue(lldb::ValueObjectSP value_sp) {
+CompilerType type;
+lldb::ValueObjectSP value = DILGetSPWithLock(value_sp);
+if (value)
+  type = value->GetCompilerType();
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kValue, type, value, 
{}));
+  }
+
+  static IdentifierInfoPtr FromContextArg(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new IdentifierInfo(Kind::kContextArg, type, empty_value, {}));
+  }
+
+  static IdentifierInfoPtr FromMemberPath(CompilerType type, MemberPath path) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kMemberPath, type,
+empty_value, std::move(path)));
+  }
+
+  static IdentifierInfoPtr FromThisKeyword(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new Ident

[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,43 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = cast_expression;
+
+cast_expression = unary_expression;
+
+unary_expression = postfix_expression
+ | unary_operator cast_expression;
+
+unary_operator = "*" | "&" | "-" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this" ;

labath wrote:

Other languages may use a different keyword (`self` typically) to refer to 
"this" object (in which case `this` can refer to a regular variable). 
Special-casing `this` in the parser could make that difficult, so it may be 
better to treat `this` as a regular identifier, and only resolve it later, once 
we know which language we're in.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

> BTW, I have verified that this stripped down version passes all the frame 
> variable tests in LLDB.

That's cool. Just to confirm, have you looked at replacing `target variable` as 
well? It uses the same language as "frame var" under the hood, which  but it 
has a somewhat different starting point (it basically ignores the local scope 
and looks only at globals), which means it may need some special handling in 
the new parser.

> I agree with Jim re the DIL language: We should only have a single language 
> definition, and it can be a superset of the languages it supports. So there 
> may be parts of it that belong to particular languages, but that does not 
> mean it supports those languages exclusively.

This direction makes sense to me, but I think that's all the more reason to be 
conservative/cautious about adding new features to the language. We can't just 
put every possible feature of every language into it, as we'd end up with a 
unmaintainable mess.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,43 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = cast_expression;
+
+cast_expression = unary_expression;
+
+unary_expression = postfix_expression
+ | unary_operator cast_expression;
+
+unary_operator = "*" | "&" | "-" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this" ;
+
+nested_name_specifier = namespace_name '::'
+  | nested_name_specifier identifier "::";
+
+namespace_name = identifier ;
+
+id_expression = unqualified_id
+  | qualified_id ;
+
+unqualified_id = identifier ;
+
+qualified_id = [nested_name_specifier] unqualified_id
+ | identifier ;
+
+identifier = ? clang::tok::identifier ? ;
+
+numeric_literal = ? clang::tok::numeric_constant ? ;
+
+boolean_literal = "true" | "false" ;
+
+pointer_literal = "nullptr" ;

labath wrote:

true/false/nullptr are also spelled differently in different languages, and I 
don't believe they're necessary for the basic "frame variable" implementation. 
Can we skip those for now?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;

labath wrote:

Does every bitfield have to have a size? If yes, what would you say to 
`optional bitfield_bit_size` (with `nullopt` meaning "it's not a 
bitfield")?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.
+bool IsSmartPtrType(CompilerType type);
+
+/// Class used to store & manipulate information about identifiers.
+class IdentifierInfo {
+private:
+  using MemberPath = std::vector;
+  using IdentifierInfoPtr = std::unique_ptr;
+
+public:
+  enum class Kind {
+kValue,
+kContextArg,
+kMemberPath,
+kThisKeyword,
+  };
+
+  static IdentifierInfoPtr FromValue(lldb::ValueObjectSP value_sp) {
+CompilerType type;
+lldb::ValueObjectSP value = DILGetSPWithLock(value_sp);
+if (value)
+  type = value->GetCompilerType();
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kValue, type, value, 
{}));
+  }
+
+  static IdentifierInfoPtr FromContextArg(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new IdentifierInfo(Kind::kContextArg, type, empty_value, {}));
+  }
+
+  static IdentifierInfoPtr FromMemberPath(CompilerType type, MemberPath path) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kMemberPath, type,
+empty_value, std::move(path)));
+  }
+
+  static IdentifierInfoPtr FromThisKeyword(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new Ident

[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);

labath wrote:

these aren't implemented anywhere.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay

labath wrote:

lldb doesn't use the `k` prefix for constants. For unscoped enums, we use `e`. 
I think some of the scoped ones have it as well, but an empty prefix is also 
pretty common (so you can then refer to them as `DILNodeKind::Literal` (or 
`dil::NodeKind::Literal` in the namespace version).

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,468 @@
+//===-- DILAST.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/Core/DILAST.h"
+#include "lldb/API/SBType.h"
+#include "lldb/Core/ValueObjectRegister.h"
+#include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/RegisterContext.h"
+#include "llvm/ADT/StringRef.h"
+
+#include 
+
+namespace lldb_private {
+
+lldb::ValueObjectSP DILGetSPWithLock(lldb::ValueObjectSP in_valobj_sp,
+ lldb::DynamicValueType use_dynamic,
+ bool use_synthetic) {
+  Process::StopLocker stop_locker;
+  std::unique_lock lock;
+  Status error;
+
+  if (!in_valobj_sp) {
+error.SetErrorString("invalid value object");
+return in_valobj_sp;
+  }
+
+  lldb::ValueObjectSP value_sp = in_valobj_sp;
+
+  Target *target = value_sp->GetTargetSP().get();
+  // If this ValueObject holds an error, then it is valuable for that.
+  if (value_sp->GetError().Fail())
+return value_sp;
+
+  if (!target)
+return lldb::ValueObjectSP();
+
+  lock = std::unique_lock(target->GetAPIMutex());
+
+  lldb::ProcessSP process_sp(value_sp->GetProcessSP());
+  if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
+// We don't allow people to play around with ValueObject if the process
+// is running. If you want to look at values, pause the process, then
+// look.
+error.SetErrorString("process must be stopped.");
+return lldb::ValueObjectSP();
+  }
+
+  if (use_dynamic != lldb::eNoDynamicValues) {
+lldb::ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(use_dynamic);
+if (dynamic_sp)
+  value_sp = dynamic_sp;
+  }
+
+  if (use_synthetic) {
+lldb::ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
+if (synthetic_sp)
+  value_sp = synthetic_sp;
+  }
+
+  if (!value_sp)
+error.SetErrorString("invalid value object");
+
+  return value_sp;
+}
+
+CompilerType DILASTNode::result_type_deref() const {
+  auto type = result_type();
+  return type.IsReferenceType() ? type.GetNonReferenceType() : type;
+}
+
+static std::unordered_map context_args;
+
+bool IsContextVar(const std::string &name) {
+  return context_args.find(name) != context_args.end();
+}
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  std::vector values;
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(
+  name, (size_t)std::numeric_limits::max, variable_list);
+  if (!variable_list.Empty()) {
+ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+if (exe_scope == nullptr)
+  exe_scope = target_sp.get();
+for (const lldb::VariableSP &var_sp : variable_list) {
+  lldb::ValueObjectSP valobj_sp(
+  ValueObjectVariable::Create(exe_scope, var_sp));
+  if (valobj_sp)
+values.push_back(valobj_sp);
+}
+  }
+
+  // Find the corrent variable by matching the name. lldb::SBValue::GetName()
+  // can return strings like "::globarVar", "ns::i" or "int const ns::foo"
+  // depending on the version and the platform.
+  for (uint32_t i = 0; i < values.size(); ++i) {
+lldb::ValueObjectSP val = values[i];
+llvm::StringRef val_name_sstr = val->GetName().GetStringRef();
+llvm::StringRef name_sstr = name.GetStringRef();
+
+if (val->GetVariable() && 
val->GetVariable()->NameMatches(unqualified_name))
+  return val;
+
+if (val_name_sstr == name_sstr ||
+val_name_sstr == llvm::formatv("::{0}", name_sstr).str() ||
+val_name_sstr.ends_with(llvm::formatv(" {0}", name_sstr).str()) ||
+val_name_sstr.ends_with(llvm::formatv("*{0}", name_sstr).str()) ||
+val_name_sstr.ends_with(llvm::formatv("&{0}", name_sstr).str()))
+  return val;
+  }
+  lldb::ValueObjectSP empty_obj_sp;
+  return empty_obj_sp;
+}
+
+struct EnumMember {
+  CompilerType type;
+  ConstString name;
+  llvm::APSInt value;
+};
+
+static std::vector GetEnumMembers(CompilerType type) {
+  std::vector enum_member_list;
+  if (type.IsValid()) {
+type.ForEachEnumerator(
+[&enum_member_list](const CompilerType &integer_type, ConstString name,
+const llvm::APSInt &value) -> bool {
+  EnumMember enum_member = 

[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.
+bool IsSmartPtrType(CompilerType type);
+
+/// Class used to store & manipulate information about identifiers.
+class IdentifierInfo {
+private:
+  using MemberPath = std::vector;
+  using IdentifierInfoPtr = std::unique_ptr;
+
+public:
+  enum class Kind {
+kValue,
+kContextArg,
+kMemberPath,
+kThisKeyword,
+  };
+
+  static IdentifierInfoPtr FromValue(lldb::ValueObjectSP value_sp) {
+CompilerType type;
+lldb::ValueObjectSP value = DILGetSPWithLock(value_sp);
+if (value)
+  type = value->GetCompilerType();
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kValue, type, value, 
{}));
+  }
+
+  static IdentifierInfoPtr FromContextArg(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new IdentifierInfo(Kind::kContextArg, type, empty_value, {}));
+  }
+
+  static IdentifierInfoPtr FromMemberPath(CompilerType type, MemberPath path) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(new IdentifierInfo(Kind::kMemberPath, type,
+empty_value, std::move(path)));
+  }
+
+  static IdentifierInfoPtr FromThisKeyword(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return IdentifierInfoPtr(
+new Ident

[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)

2024-07-09 Thread Shivam Gupta via lldb-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/94785

>From 6ec5b1a005b7551f2857b30e2461d297e7febfa3 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Fri, 7 Jun 2024 23:44:49 +0530
Subject: [PATCH 1/3] [LLDB][NFC] Fix a cppcheck warning in
 Platform/Android/PlatformAndroid.cpp

Fix #91211
---
 lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp 
b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
index e177c134fea20..6367763dd8b4a 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec 
&src_file_spec,
   static constexpr llvm::StringLiteral k_zip_separator("!/");
   size_t pos = source_file.find(k_zip_separator);
   if (pos != std::string::npos)
-source_file = source_file.substr(0, pos);
+source_file = source_file.resize(0, pos);
 
   Status error;
   AdbClientUP adb(GetAdbClient(error));

>From c05f1a9812b8ef6cfc4f1f4c2d7525371d65a95b Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sat, 6 Jul 2024 11:00:16 +0200
Subject: [PATCH 2/3] address review comment

---
 lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp 
b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
index 6367763dd8b4a..ff63af68aec9d 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec 
&src_file_spec,
   static constexpr llvm::StringLiteral k_zip_separator("!/");
   size_t pos = source_file.find(k_zip_separator);
   if (pos != std::string::npos)
-source_file = source_file.resize(0, pos);
+source_file = source_file.resize(pos);
 
   Status error;
   AdbClientUP adb(GetAdbClient(error));

>From 1cd2f9c11070bcbee2efad2e5b84433eef31438c Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Tue, 9 Jul 2024 12:31:01 +0200
Subject: [PATCH 3/3] address review comment

---
 lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp 
b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
index ff63af68aec9d..50b6a5c29a657 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec 
&src_file_spec,
   static constexpr llvm::StringLiteral k_zip_separator("!/");
   size_t pos = source_file.find(k_zip_separator);
   if (pos != std::string::npos)
-source_file = source_file.resize(pos);
+source_file.resize(pos);
 
   Status error;
   AdbClientUP adb(GetAdbClient(error));

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


[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)

2024-07-09 Thread Shivam Gupta via lldb-commits


@@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec 
&src_file_spec,
   static constexpr llvm::StringLiteral k_zip_separator("!/");
   size_t pos = source_file.find(k_zip_separator);
   if (pos != std::string::npos)
-source_file = source_file.substr(0, pos);
+source_file = source_file.resize(0, pos);

xgupta wrote:

Thanks, got it.

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/96654

>From d47f7306c913336529a01a401e41ce688d0c6b46 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 19 Jun 2024 23:50:18 +
Subject: [PATCH] [lldb][test] Set target and host OS for API tests in case of
 remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python 
lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 29 +--
 .../Python/lldbsuite/test/make/Makefile.rules |  5 +++-
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..e4de298fb11ae 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -56,6 +56,10 @@ def target_is_android():
 return configuration.lldb_platform_name == "remote-android"
 
 
+def target_is_remote_linux():
+return configuration.lldb_platform_name == "remote-linux"
+
+
 def android_device_api():
 if not hasattr(android_device_api, "result"):
 assert configuration.lldb_platform_url is not None
@@ -92,11 +96,28 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+# Provide uname-like platform name
+platform_name_to_uname = { "linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+}
+
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+
+if platformIsDarwin():
+dictionary["HOST_OS"] = "Darwin"
+else:
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
+
 return dictionary
 
 
@@ -113,6 +134,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+
 return ""
 
 
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bd8eea3d6f5a0..c101d84a9b959 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -55,7 +55,10 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
-HOST_OS := $(shell uname -s)
+ifeq "$(OS)" ""
+  HOST_OS := $(shell uname -s)
+endif
+
 ifneq (,$(findstring windows32,$(HOST_OS)))
HOST_OS := Windows_NT
 endif

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/96654

>From b6e1aa283d46292556d0edac70eb05d6467497f2 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 19 Jun 2024 23:50:18 +
Subject: [PATCH] [lldb][test] Set target and host OS for API tests in case of
 remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python 
lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 25 +--
 .../Python/lldbsuite/test/make/Makefile.rules |  5 +++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..1e076061c6c43 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -92,11 +92,28 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+# Provide uname-like platform name
+platform_name_to_uname = {
+"linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+"macosx": "Darwin",
+"darwin": "Darwin",
+}
+
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
+
 return dictionary
 
 
@@ -113,6 +130,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+
 return ""
 
 
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bd8eea3d6f5a0..3d562285ce9cc 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -55,7 +55,10 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
-HOST_OS := $(shell uname -s)
+ifeq "$(HOST_OS)" ""
+  HOST_OS := $(shell uname -s)
+endif
+
 ifneq (,$(findstring windows32,$(HOST_OS)))
HOST_OS := Windows_NT
 endif

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

dzhidzhoev wrote:

Thank you! Updated it: improved code for Darwin host detection, and removed 
overriding of HOST_OS in Makefile.

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -113,6 +130,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+

labath wrote:

Can you explain why was this necessary? I get the connected part, but who was 
asking for the platform before connecting?

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


[Lldb-commits] [lldb] [lldb] Use correct path separator for C++ library files lookup (PR #98144)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev created 
https://github.com/llvm/llvm-project/pull/98144

Use POSIX-style path separators when checking for libcpp library path.
This is necessary to run API tests from 'std-module' group compiled on Windows 
host for Linux target.

>From fce5e1e4a59b511a0bd4aa1bb1865528297c5471 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 22 May 2024 11:19:44 -0700
Subject: [PATCH] [lldb] Use correct path separator for C++ library files
 lookup

Take into account separator style of target platorm.
This is necessary to run API tests from 'std-module' group compiled
on Windows host for Linux target.
---
 .../Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index f43a04488230f..f3aabc12f92b7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -71,7 +71,7 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
   // If the path is in the libc++ include directory use it as the found libc++
   // path. Ignore subdirectories such as /c++/v1/experimental as those don't
   // need to be specified in the header search.
-  if (libcpp_regex.match(f.GetPath()) &&
+  if (libcpp_regex.match(convert_to_slash(f.GetPath())) &&
   parent_path(posix_dir, Style::posix).ends_with("c++")) {
 if (!m_std_inc.TrySet(posix_dir))
   return false;

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


[Lldb-commits] [lldb] [lldb] Use correct path separator for C++ library files lookup (PR #98144)

2024-07-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vladislav Dzhidzhoev (dzhidzhoev)


Changes

Use POSIX-style path separators when checking for libcpp library path.
This is necessary to run API tests from 'std-module' group compiled on Windows 
host for Linux target.

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


1 Files Affected:

- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp (+1-1) 


``diff
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index f43a04488230f..f3aabc12f92b7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -71,7 +71,7 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
   // If the path is in the libc++ include directory use it as the found libc++
   // path. Ignore subdirectories such as /c++/v1/experimental as those don't
   // need to be specified in the header search.
-  if (libcpp_regex.match(f.GetPath()) &&
+  if (libcpp_regex.match(convert_to_slash(f.GetPath())) &&
   parent_path(posix_dir, Style::posix).ends_with("c++")) {
 if (!m_std_inc.TrySet(posix_dir))
   return false;

``




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


[Lldb-commits] [lldb] [lldb] Use correct path separator for C++ library files lookup (PR #98144)

2024-07-09 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Use correct path separator for C++ library files lookup (PR #98144)

2024-07-09 Thread Raphael Isemann via lldb-commits

Teemperor wrote:

This LGTM

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits


@@ -113,6 +130,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+

dzhidzhoev wrote:

That may be relevant if _get_platform_os is called before the connection is 
established, or, for example, if it has failed to be established.
But yeah, currently I'm not aware of such use cases. Should it be removed?

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Use correct path separator for C++ library files lookup (PR #98144)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

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


[Lldb-commits] [lldb] afee09c - [lldb] Use correct path separator for C++ library files lookup (#98144)

2024-07-09 Thread via lldb-commits

Author: Vladislav Dzhidzhoev
Date: 2024-07-09T14:22:33+02:00
New Revision: afee09c50c11da1ea6ba0b341a1c10dedeaf5be6

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

LOG: [lldb] Use correct path separator for C++ library files lookup (#98144)

Use POSIX-style path separators when checking for libcpp library path.
This is necessary to run API tests from 'std-module' group compiled on
Windows host for Linux target.

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index f43a04488230f..f3aabc12f92b7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -71,7 +71,7 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
   // If the path is in the libc++ include directory use it as the found libc++
   // path. Ignore subdirectories such as /c++/v1/experimental as those don't
   // need to be specified in the header search.
-  if (libcpp_regex.match(f.GetPath()) &&
+  if (libcpp_regex.match(convert_to_slash(f.GetPath())) &&
   parent_path(posix_dir, Style::posix).ends_with("c++")) {
 if (!m_std_inc.TrySet(posix_dir))
   return false;



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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -113,6 +130,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+

labath wrote:

Yes, I would very much prefer that, as the code you added only handles linux. 
To support other oses, we would need to create a whole new mapping from lldb 
platform names to os strings. That list could then get out of sync, etc., so it 
would be best to just avoid doing that.

I'm not worried about the debug target going down during testing, as that means 
the test results will be meaningless anyway. If we find out we regularly need 
the os name before connecting, then I think we ought to revisit the mechanism 
for determining the OS.

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/96654

>From 016ed9ec4ed320709b981f4a5fe228a91d753230 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 19 Jun 2024 23:50:18 +
Subject: [PATCH] [lldb][test] Set target and host OS for API tests in case of
 remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python 
lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 21 +--
 .../Python/lldbsuite/test/make/Makefile.rules |  5 -
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..818fdf0e6b5c5 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -92,11 +92,28 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+# Provide uname-like platform name
+platform_name_to_uname = {
+"linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+"macosx": "Darwin",
+"darwin": "Darwin",
+}
+
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
+
 return dictionary
 
 
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bd8eea3d6f5a0..3d562285ce9cc 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -55,7 +55,10 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
-HOST_OS := $(shell uname -s)
+ifeq "$(HOST_OS)" ""
+  HOST_OS := $(shell uname -s)
+endif
+
 ifneq (,$(findstring windows32,$(HOST_OS)))
HOST_OS := Windows_NT
 endif

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits


@@ -113,6 +130,10 @@ def _get_platform_os(p):
 platform = "openbsd"
 return platform
 
+# Triple is not available if we're not connected yet
+if p.GetName() == "remote-linux":
+return "linux"
+

dzhidzhoev wrote:

Fixed.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return optional from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/97824

>From 7ebe4e487b763ff26fbab6d75aa7c8694d63e8b1 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Fri, 5 Jul 2024 08:42:22 +
Subject: [PATCH 1/4] [llvm][TargetParser] Return optional from
 getHostCPUFeatures

Previously this took a reference to a map and returned a bool
to say whether it succeeded. This is an optional but with more
steps.

The only reason to keep it that way was if someone was appending
to an existing map, but all callers made a new map before calling
it.
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  |  6 ++--
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  6 ++--
 lldb/utils/lit-cpuid/lit-cpuid.cpp| 21 +++---
 llvm/include/llvm/TargetParser/Host.h | 14 -
 llvm/lib/CodeGen/CommandFlags.cpp | 16 --
 .../Orc/JITTargetMachineBuilder.cpp   |  8 ++---
 llvm/lib/Target/TargetMachineC.cpp|  5 ++--
 llvm/lib/TargetParser/Host.cpp| 29 ---
 8 files changed, 54 insertions(+), 51 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 8ae22cc37a136..77adbf3865ab1 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -591,9 +591,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 
   // Add CPU features for generic CPUs
   if (CPUName == "native") {
-llvm::StringMap HostFeatures;
-if (llvm::sys::getHostCPUFeatures(HostFeatures))
-  for (auto &F : HostFeatures)
+if (std::optional> HostFeatures =
+llvm::sys::getHostCPUFeatures())
+  for (auto &F : *HostFeatures)
 Features.push_back(
 Args.MakeArgString((F.second ? "+" : "-") + F.first()));
   } else if (!CPUName.empty()) {
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 92821b2a82dae..e4adfcac23ca0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -131,9 +131,9 @@ void x86::getX86TargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   // If -march=native, autodetect the feature list.
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
 if (StringRef(A->getValue()) == "native") {
-  llvm::StringMap HostFeatures;
-  if (llvm::sys::getHostCPUFeatures(HostFeatures))
-for (auto &F : HostFeatures)
+  if (std::optional> HostFeatures =
+  llvm::sys::getHostCPUFeatures())
+for (auto &F : *HostFeatures)
   Features.push_back(
   Args.MakeArgString((F.second ? "+" : "-") + F.first()));
 }
diff --git a/lldb/utils/lit-cpuid/lit-cpuid.cpp 
b/lldb/utils/lit-cpuid/lit-cpuid.cpp
index be322cb6aa42a..16743164e6a5d 100644
--- a/lldb/utils/lit-cpuid/lit-cpuid.cpp
+++ b/lldb/utils/lit-cpuid/lit-cpuid.cpp
@@ -15,22 +15,23 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 
+#include 
+
 using namespace llvm;
 
 int main(int argc, char **argv) {
 #if defined(__i386__) || defined(_M_IX86) || \
 defined(__x86_64__) || defined(_M_X64)
-  StringMap features;
-
-  if (!sys::getHostCPUFeatures(features))
+  if (std::optional> features =
+  sys::getHostCPUFeatures(features)) {
+if ((*features)["sse"])
+  outs() << "sse\n";
+if ((*features)["avx"])
+  outs() << "avx\n";
+if ((*features)["avx512f"])
+  outs() << "avx512f\n";
+  } else
 return 1;
-
-  if (features["sse"])
-outs() << "sse\n";
-  if (features["avx"])
-outs() << "avx\n";
-  if (features["avx512f"])
-outs() << "avx512f\n";
 #endif
 
   return 0;
diff --git a/llvm/include/llvm/TargetParser/Host.h 
b/llvm/include/llvm/TargetParser/Host.h
index af72045a8fe67..d68655835a323 100644
--- a/llvm/include/llvm/TargetParser/Host.h
+++ b/llvm/include/llvm/TargetParser/Host.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_TARGETPARSER_HOST_H
 #define LLVM_TARGETPARSER_HOST_H
 
+#include 
 #include 
 
 namespace llvm {
@@ -47,13 +48,12 @@ namespace sys {
   /// The particular format of the names are target dependent, and suitable for
   /// passing as -mattr to the target which matches the host.
   ///
-  /// \param Features - A string mapping feature names to either
-  /// true (if enabled) or false (if disabled). This routine makes no 
guarantees
-  /// about exactly which features may appear in this map, except that they are
-  /// all valid LLVM feature names.
-  ///
-  /// \return - True on success.
-  bool getHostCPUFeatures(StringMap &Features);
+  /// \return - If feature detection succeeds, a string map mapping feature
+  /// names to either true (if enabled) or false (if disabled). This routine
+  /// makes no guarantees about exactly which features may appear in this map,
+  /// except that they are all valid LLVM feature names. If feature detection
+  /// fails, an 

[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

DavidSpickett wrote:

>  Why not return a map every time?

Done.


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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/98154

While looking at a TSAN report (patch coming soon) in the ThreadList class, I 
noticed that this code would be simpler if it did not use the ThreadList class.

>From 2e74468a99015645f1abbfdf42f6e5c9893e7cf3 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 9 Jul 2024 15:00:05 +0200
Subject: [PATCH] [lldb] Small cleanup of ProcessEventData::ShouldStop

While looking at a TSAN report (patch coming soon) in the ThreadList
class, I noticed that this code would be simpler if it did not use the
ThreadList class.
---
 lldb/source/Target/Process.cpp | 31 +++
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 6fac0df1d7a66..085e3f502e093 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4152,7 +4152,6 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
 
   ThreadList &curr_thread_list = process_sp->GetThreadList();
   uint32_t num_threads = curr_thread_list.GetSize();
-  uint32_t idx;
 
   // The actions might change one of the thread's stop_info's opinions about
   // whether we should stop the process, so we need to query that as we go.
@@ -4162,23 +4161,18 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // get that wrong (which is possible) then the thread list might have
   // changed, and that would cause our iteration here to crash.  We could
   // make a copy of the thread list, but we'd really like to also know if it
-  // has changed at all, so we make up a vector of the thread ID's and check
-  // what we get back against this list & bag out if anything differs.
-  ThreadList not_suspended_thread_list(process_sp.get());
-  std::vector thread_index_array(num_threads);
-  uint32_t not_suspended_idx = 0;
-  for (idx = 0; idx < num_threads; ++idx) {
+  // has changed at all, so we store the original thread ID's of all threads 
and
+  // check what we get back against this list & bag out if anything differs.
+  std::vector> not_suspended_threads;
+  for (uint32_t idx = 0; idx < num_threads; ++idx) {
 lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx);
 
 /*
  Filter out all suspended threads, they could not be the reason
  of stop and no need to perform any actions on them.
  */
-if (thread_sp->GetResumeState() != eStateSuspended) {
-  not_suspended_thread_list.AddThread(thread_sp);
-  thread_index_array[not_suspended_idx] = thread_sp->GetIndexID();
-  not_suspended_idx++;
-}
+if (thread_sp->GetResumeState() != eStateSuspended)
+  not_suspended_threads.emplace_back(thread_sp, thread_sp->GetIndexID());
   }
 
   // Use this to track whether we should continue from here.  We will only
@@ -4194,7 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for (idx = 0; idx < not_suspended_thread_list.GetSize(); ++idx) {
+  for(auto [thread_sp, thread_index] : not_suspended_threads) {
 curr_thread_list = process_sp->GetThreadList();
 if (curr_thread_list.GetSize() != num_threads) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
@@ -4205,14 +4199,11 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   break;
 }
 
-lldb::ThreadSP thread_sp = not_suspended_thread_list.GetThreadAtIndex(idx);
-
-if (thread_sp->GetIndexID() != thread_index_array[idx]) {
+if (thread_sp->GetIndexID() != thread_index) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
-  LLDB_LOGF(log,
-"The thread at position %u changed from %u to %u while "
-"processing event.",
-idx, thread_index_array[idx], thread_sp->GetIndexID());
+  LLDB_LOG(log,
+   "The thread {0} changed from {1} to {2} while processing 
event.",
+   thread_sp.get(), thread_index, thread_sp->GetIndexID());
   break;
 }
 

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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

While looking at a TSAN report (patch coming soon) in the ThreadList class, I 
noticed that this code would be simpler if it did not use the ThreadList class.

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


1 Files Affected:

- (modified) lldb/source/Target/Process.cpp (+11-20) 


``diff
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 6fac0df1d7a66..085e3f502e093 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4152,7 +4152,6 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
 
   ThreadList &curr_thread_list = process_sp->GetThreadList();
   uint32_t num_threads = curr_thread_list.GetSize();
-  uint32_t idx;
 
   // The actions might change one of the thread's stop_info's opinions about
   // whether we should stop the process, so we need to query that as we go.
@@ -4162,23 +4161,18 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // get that wrong (which is possible) then the thread list might have
   // changed, and that would cause our iteration here to crash.  We could
   // make a copy of the thread list, but we'd really like to also know if it
-  // has changed at all, so we make up a vector of the thread ID's and check
-  // what we get back against this list & bag out if anything differs.
-  ThreadList not_suspended_thread_list(process_sp.get());
-  std::vector thread_index_array(num_threads);
-  uint32_t not_suspended_idx = 0;
-  for (idx = 0; idx < num_threads; ++idx) {
+  // has changed at all, so we store the original thread ID's of all threads 
and
+  // check what we get back against this list & bag out if anything differs.
+  std::vector> not_suspended_threads;
+  for (uint32_t idx = 0; idx < num_threads; ++idx) {
 lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx);
 
 /*
  Filter out all suspended threads, they could not be the reason
  of stop and no need to perform any actions on them.
  */
-if (thread_sp->GetResumeState() != eStateSuspended) {
-  not_suspended_thread_list.AddThread(thread_sp);
-  thread_index_array[not_suspended_idx] = thread_sp->GetIndexID();
-  not_suspended_idx++;
-}
+if (thread_sp->GetResumeState() != eStateSuspended)
+  not_suspended_threads.emplace_back(thread_sp, thread_sp->GetIndexID());
   }
 
   // Use this to track whether we should continue from here.  We will only
@@ -4194,7 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for (idx = 0; idx < not_suspended_thread_list.GetSize(); ++idx) {
+  for(auto [thread_sp, thread_index] : not_suspended_threads) {
 curr_thread_list = process_sp->GetThreadList();
 if (curr_thread_list.GetSize() != num_threads) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
@@ -4205,14 +4199,11 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   break;
 }
 
-lldb::ThreadSP thread_sp = not_suspended_thread_list.GetThreadAtIndex(idx);
-
-if (thread_sp->GetIndexID() != thread_index_array[idx]) {
+if (thread_sp->GetIndexID() != thread_index) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
-  LLDB_LOGF(log,
-"The thread at position %u changed from %u to %u while "
-"processing event.",
-idx, thread_index_array[idx], thread_sp->GetIndexID());
+  LLDB_LOG(log,
+   "The thread {0} changed from {1} to {2} while processing 
event.",
+   thread_sp.get(), thread_index, thread_sp->GetIndexID());
   break;
 }
 

``




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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 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 9856af634db8bf550893606ba42c56d4dff3f320 
2e74468a99015645f1abbfdf42f6e5c9893e7cf3 -- lldb/source/Target/Process.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 085e3f502e..f1140a2f12 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4188,7 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for(auto [thread_sp, thread_index] : not_suspended_threads) {
+  for (auto [thread_sp, thread_index] : not_suspended_threads) {
 curr_thread_list = process_sp->GetThreadList();
 if (curr_thread_list.GetSize() != num_threads) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));

``




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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Pavel Labath via lldb-commits

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

Thank you.

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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/98154

>From 27d419b047d0c2e95978b8c88dd84641aae423f2 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 9 Jul 2024 15:00:05 +0200
Subject: [PATCH] [lldb] Small cleanup of ProcessEventData::ShouldStop

While looking at a TSAN report (patch coming soon) in the ThreadList
class, I noticed that this code would be simpler if it did not use the
ThreadList class.
---
 lldb/source/Target/Process.cpp | 32 +++-
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 6fac0df1d7a66..dc7f6c9e86a47 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4152,7 +4152,6 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
 
   ThreadList &curr_thread_list = process_sp->GetThreadList();
   uint32_t num_threads = curr_thread_list.GetSize();
-  uint32_t idx;
 
   // The actions might change one of the thread's stop_info's opinions about
   // whether we should stop the process, so we need to query that as we go.
@@ -4162,23 +4161,18 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // get that wrong (which is possible) then the thread list might have
   // changed, and that would cause our iteration here to crash.  We could
   // make a copy of the thread list, but we'd really like to also know if it
-  // has changed at all, so we make up a vector of the thread ID's and check
-  // what we get back against this list & bag out if anything differs.
-  ThreadList not_suspended_thread_list(process_sp.get());
-  std::vector thread_index_array(num_threads);
-  uint32_t not_suspended_idx = 0;
-  for (idx = 0; idx < num_threads; ++idx) {
+  // has changed at all, so we store the original thread ID's of all threads 
and
+  // check what we get back against this list & bag out if anything differs.
+  std::vector> not_suspended_threads;
+  for (uint32_t idx = 0; idx < num_threads; ++idx) {
 lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx);
 
 /*
  Filter out all suspended threads, they could not be the reason
  of stop and no need to perform any actions on them.
  */
-if (thread_sp->GetResumeState() != eStateSuspended) {
-  not_suspended_thread_list.AddThread(thread_sp);
-  thread_index_array[not_suspended_idx] = thread_sp->GetIndexID();
-  not_suspended_idx++;
-}
+if (thread_sp->GetResumeState() != eStateSuspended)
+  not_suspended_threads.emplace_back(thread_sp, thread_sp->GetIndexID());
   }
 
   // Use this to track whether we should continue from here.  We will only
@@ -4194,8 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for (idx = 0; idx < not_suspended_thread_list.GetSize(); ++idx) {
-curr_thread_list = process_sp->GetThreadList();
+  for (auto [thread_sp, thread_index] : not_suspended_threads) {
 if (curr_thread_list.GetSize() != num_threads) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
   LLDB_LOGF(
@@ -4205,14 +4198,11 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   break;
 }
 
-lldb::ThreadSP thread_sp = not_suspended_thread_list.GetThreadAtIndex(idx);
-
-if (thread_sp->GetIndexID() != thread_index_array[idx]) {
+if (thread_sp->GetIndexID() != thread_index) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
-  LLDB_LOGF(log,
-"The thread at position %u changed from %u to %u while "
-"processing event.",
-idx, thread_index_array[idx], thread_sp->GetIndexID());
+  LLDB_LOG(log,
+   "The thread {0} changed from {1} to {2} while processing 
event.",
+   thread_sp.get(), thread_index, thread_sp->GetIndexID());
   break;
 }
 

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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -4194,8 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for (idx = 0; idx < not_suspended_thread_list.GetSize(); ++idx) {
-curr_thread_list = process_sp->GetThreadList();

labath wrote:

curr_thread_list is a reference to the process's thread list, which made this a 
self-assignment.

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


[Lldb-commits] [lldb] [lldb] Fix printing of unsigned enum bitfields when they contain the max value (PR #96202)

2024-07-09 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Clang's dwarf v2 output is missing `DW_AT_type`. With `g++` I see that (and 
more) with v2 and v3.

v2:
```
0x0043:   DW_TAG_enumeration_type
DW_AT_name  ("UnsignedEnum")
DW_AT_byte_size (0x04)
DW_AT_decl_file ("/tmp/test.cpp")
DW_AT_decl_line (2)
```
v3:
```
0x004e:   DW_TAG_enumeration_type
DW_AT_type  (0x0067 "unsigned int")
DW_AT_name  ("UnsignedEnum")
DW_AT_byte_size (0x04)
DW_AT_decl_file ("/tmp/test.cpp")
DW_AT_decl_line (2)
```

Will revert while I figure that out.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread Phoebe Wang via lldb-commits


@@ -15,21 +15,22 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 
+#include 
+

phoebewang wrote:

Not needed.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread Phoebe Wang via lldb-commits


@@ -13,6 +13,7 @@
 #ifndef LLVM_TARGETPARSER_HOST_H
 #define LLVM_TARGETPARSER_HOST_H
 
+#include 

phoebewang wrote:

ditto

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


[Lldb-commits] [lldb] 0ad9d8f - [lldb][test] Skip bitfield enum tests for DWARF v2 and below

2024-07-09 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2024-07-09T14:11:26Z
New Revision: 0ad9d8f279437772d390c7fc6309c09b97406be3

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

LOG: [lldb][test] Skip bitfield enum tests for DWARF v2 and below

Clang's v2 output appears to be missing a key DW_AT_type attribute,
and this causes the "max" of the unsigned enum to appear as -1 instead
of "max" aka 3.

```
(BitfieldStruct) $0 = {
  signed_min = min
  signed_other = -1
  signed_max = max
  unsigned_min = min
  unsigned_other = 1
  unsigned_max = -1
}
```

Test added by #96202.

Added: 


Modified: 
lldb/test/API/commands/expression/bitfield_enums/TestBitfieldEnums.py

Removed: 




diff  --git 
a/lldb/test/API/commands/expression/bitfield_enums/TestBitfieldEnums.py 
b/lldb/test/API/commands/expression/bitfield_enums/TestBitfieldEnums.py
index a484b69300e7b..dbe9b9241a9ac 100644
--- a/lldb/test/API/commands/expression/bitfield_enums/TestBitfieldEnums.py
+++ b/lldb/test/API/commands/expression/bitfield_enums/TestBitfieldEnums.py
@@ -10,6 +10,9 @@
 
 
 class TestBitfieldEnum(TestBase):
+# clang's DWARF v2 output is missing DW_AT_type which causes unsigned_max 
to
+# appear as -1 instead of the "max" enumerator, whose value is 3.
+@skipIf(dwarf_version=["<", "3"], compiler="clang")
 def test_bitfield_enums(self):
 self.build()
 



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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/97824

>From 7ebe4e487b763ff26fbab6d75aa7c8694d63e8b1 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Fri, 5 Jul 2024 08:42:22 +
Subject: [PATCH 1/5] [llvm][TargetParser] Return optional from
 getHostCPUFeatures

Previously this took a reference to a map and returned a bool
to say whether it succeeded. This is an optional but with more
steps.

The only reason to keep it that way was if someone was appending
to an existing map, but all callers made a new map before calling
it.
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  |  6 ++--
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  6 ++--
 lldb/utils/lit-cpuid/lit-cpuid.cpp| 21 +++---
 llvm/include/llvm/TargetParser/Host.h | 14 -
 llvm/lib/CodeGen/CommandFlags.cpp | 16 --
 .../Orc/JITTargetMachineBuilder.cpp   |  8 ++---
 llvm/lib/Target/TargetMachineC.cpp|  5 ++--
 llvm/lib/TargetParser/Host.cpp| 29 ---
 8 files changed, 54 insertions(+), 51 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 8ae22cc37a136..77adbf3865ab1 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -591,9 +591,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 
   // Add CPU features for generic CPUs
   if (CPUName == "native") {
-llvm::StringMap HostFeatures;
-if (llvm::sys::getHostCPUFeatures(HostFeatures))
-  for (auto &F : HostFeatures)
+if (std::optional> HostFeatures =
+llvm::sys::getHostCPUFeatures())
+  for (auto &F : *HostFeatures)
 Features.push_back(
 Args.MakeArgString((F.second ? "+" : "-") + F.first()));
   } else if (!CPUName.empty()) {
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 92821b2a82dae..e4adfcac23ca0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -131,9 +131,9 @@ void x86::getX86TargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   // If -march=native, autodetect the feature list.
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
 if (StringRef(A->getValue()) == "native") {
-  llvm::StringMap HostFeatures;
-  if (llvm::sys::getHostCPUFeatures(HostFeatures))
-for (auto &F : HostFeatures)
+  if (std::optional> HostFeatures =
+  llvm::sys::getHostCPUFeatures())
+for (auto &F : *HostFeatures)
   Features.push_back(
   Args.MakeArgString((F.second ? "+" : "-") + F.first()));
 }
diff --git a/lldb/utils/lit-cpuid/lit-cpuid.cpp 
b/lldb/utils/lit-cpuid/lit-cpuid.cpp
index be322cb6aa42a..16743164e6a5d 100644
--- a/lldb/utils/lit-cpuid/lit-cpuid.cpp
+++ b/lldb/utils/lit-cpuid/lit-cpuid.cpp
@@ -15,22 +15,23 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 
+#include 
+
 using namespace llvm;
 
 int main(int argc, char **argv) {
 #if defined(__i386__) || defined(_M_IX86) || \
 defined(__x86_64__) || defined(_M_X64)
-  StringMap features;
-
-  if (!sys::getHostCPUFeatures(features))
+  if (std::optional> features =
+  sys::getHostCPUFeatures(features)) {
+if ((*features)["sse"])
+  outs() << "sse\n";
+if ((*features)["avx"])
+  outs() << "avx\n";
+if ((*features)["avx512f"])
+  outs() << "avx512f\n";
+  } else
 return 1;
-
-  if (features["sse"])
-outs() << "sse\n";
-  if (features["avx"])
-outs() << "avx\n";
-  if (features["avx512f"])
-outs() << "avx512f\n";
 #endif
 
   return 0;
diff --git a/llvm/include/llvm/TargetParser/Host.h 
b/llvm/include/llvm/TargetParser/Host.h
index af72045a8fe67..d68655835a323 100644
--- a/llvm/include/llvm/TargetParser/Host.h
+++ b/llvm/include/llvm/TargetParser/Host.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_TARGETPARSER_HOST_H
 #define LLVM_TARGETPARSER_HOST_H
 
+#include 
 #include 
 
 namespace llvm {
@@ -47,13 +48,12 @@ namespace sys {
   /// The particular format of the names are target dependent, and suitable for
   /// passing as -mattr to the target which matches the host.
   ///
-  /// \param Features - A string mapping feature names to either
-  /// true (if enabled) or false (if disabled). This routine makes no 
guarantees
-  /// about exactly which features may appear in this map, except that they are
-  /// all valid LLVM feature names.
-  ///
-  /// \return - True on success.
-  bool getHostCPUFeatures(StringMap &Features);
+  /// \return - If feature detection succeeds, a string map mapping feature
+  /// names to either true (if enabled) or false (if disabled). This routine
+  /// makes no guarantees about exactly which features may appear in this map,
+  /// except that they are all valid LLVM feature names. If feature detection
+  /// fails, an 

[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits


@@ -15,21 +15,22 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 
+#include 
+

DavidSpickett wrote:

Done.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread David Spickett via lldb-commits


@@ -13,6 +13,7 @@
 #ifndef LLVM_TARGETPARSER_HOST_H
 #define LLVM_TARGETPARSER_HOST_H
 
+#include 

DavidSpickett wrote:

Done.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread Phoebe Wang via lldb-commits

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

LGTM.

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread Nikita Popov via lldb-commits


@@ -20,16 +20,15 @@ using namespace llvm;
 int main(int argc, char **argv) {
 #if defined(__i386__) || defined(_M_IX86) || \
 defined(__x86_64__) || defined(_M_X64)
-  StringMap features;
-
-  if (!sys::getHostCPUFeatures(features))
+  const < StringMap features = sys::getHostCPUFeatures(features);

nikic wrote:

I think something went wrong here...

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


[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-09 Thread Michael Buch via lldb-commits

Michael137 wrote:

> If I'm understanding correctly, the way this currently works is that you do 
> normal field layout, then if you discover that the actual offset of a field 
> is less than the offset normal field layout would produce, you assume the 
> struct is packed. This misses cases where a struct is packed, but the packing 
> doesn't affect the offset of any of the fields. But as you note, this can't 
> be fixed without adjusting the overall architecture.
> 
> There's an issue with the current implementation: it skips fields which 
> actually are packed, I think. Consider the following:
> 
> ```
> struct Empty {};
> struct __attribute((packed)) S {
>   [[no_unique_address]] Empty a,b,c,d;
>   char x;
>   int y;
> };
> S s;
> ```
> 
> In this case, the field "y" is both overlapping, and at a packed offset. 
> Really, you don't want to check for overlap; you want to ignore empty fields. 
> (Non-empty fields can't overlap.)

Good point, we would still infer packedness in this example, but for the wrong 
reasons.

Skipping empty fields does seem like a better heuristic here

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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)

2024-07-09 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/96538

>From 634ae8b82e7b14f28d092735f573ad8f301ba731 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 29 Jan 2024 16:23:16 +
Subject: [PATCH 1/3] [lldb] Support new libc++ __compressed_pair layout

This patch is in preparation for the `__compressed_pair`
refactor in https://github.com/llvm/llvm-project/pull/76756.

This gets the formatter tests to at least pass.

Currently in draft because there's still some cleanup to be done.
---
 lldb/examples/synthetic/libcxx.py | 26 --
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 61 ++
 .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 83 ---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 68 +++
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 62 +-
 .../Language/CPlusPlus/LibCxxVector.cpp   | 40 +
 .../list/TestDataFormatterGenericList.py  |  3 +-
 .../libcxx/string/simulator/main.cpp  |  1 +
 .../TestDataFormatterLibcxxUniquePtr.py   |  7 +-
 9 files changed, 246 insertions(+), 105 deletions(-)

diff --git a/lldb/examples/synthetic/libcxx.py 
b/lldb/examples/synthetic/libcxx.py
index 474aaa428fa23..060ff90100849 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair):
 def update(self):
 logger = lldb.formatters.Logger.Logger()
 try:
+has_compressed_pair_layout = True
+alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_")
+size_valobj = self.valobj.GetChildMemberWithName("__size_")
+if alloc_valobj.IsValid() and size_valobj.IsValid():
+has_compressed_pair_layout = False
+
 # A deque is effectively a two-dim array, with fixed width.
 # 'map' contains pointers to the rows of this array. The
 # full memory area allocated by the deque is delimited
@@ -734,9 +740,13 @@ def update(self):
 # variable tells which element in this NxM array is the 0th
 # one, and the 'size' element gives the number of elements
 # in the deque.
-count = self._get_value_of_compressed_pair(
-self.valobj.GetChildMemberWithName("__size_")
-)
+if has_compressed_pair_layout:
+count = self._get_value_of_compressed_pair(
+self.valobj.GetChildMemberWithName("__size_")
+)
+else:
+count = size_valobj.GetValueAsUnsigned(0)
+
 # give up now if we cant access memory reliably
 if self.block_size < 0:
 logger.write("block_size < 0")
@@ -748,9 +758,13 @@ def update(self):
 self.map_begin = map_.GetChildMemberWithName("__begin_")
 map_begin = self.map_begin.GetValueAsUnsigned(0)
 map_end = 
map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0)
-map_endcap = self._get_value_of_compressed_pair(
-map_.GetChildMemberWithName("__end_cap_")
-)
+
+if has_compressed_pair_layout:
+map_endcap = self._get_value_of_compressed_pair(
+map_.GetChildMemberWithName("__end_cap_")
+)
+else:
+map_endcap = 
map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0)
 
 # check consistency
 if not map_first <= map_begin <= map_end <= map_endcap:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 05cfa0568c25d..df17b7bbd1dad 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -27,6 +27,7 @@
 #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
 #include 
 #include 
 
@@ -176,9 +177,9 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   if (!ptr_sp)
 return false;
 
-  ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp);
-  if (!ptr_sp)
-return false;
+  if (ValueObjectSP compressed_pair_value__sp =
+  GetFirstValueOfLibCXXCompressedPair(*ptr_sp))
+ptr_sp = std::move(compressed_pair_value__sp);
 
   if (ptr_sp->GetValueAsUnsigned(0) == 0) {
 stream.Printf("nullptr");
@@ -510,15 +511,28 @@ 
lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::Update() {
   if (!ptr_sp)
 return lldb::ChildCacheState::eRefetch;
 
+  bool has_compressed_pair_layout = true;
+  ValueObjectSP deleter_sp(valobj_sp->GetChildMemberWithName("__deleter_"));
+  if (deleter_sp)
+has_compressed_pair_layout = false;
+
   // Retrieve the actual pointer and the deleter, and clone them to give them
   // user-friendly name

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-09 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/97470

>From 8647eccd35085ab80f978fabb78b016915c5524f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/7] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(exception_stream.ThreadId) > 0) {
+  // We only cast to avoid the warning around converting little endian in 
printf.
+  error.SetErrorStringWithFormat("duplicate exception stream for tid %" 
PRIu32, (uint32_t)exception_stream.ThreadId);
+  return error;
+} else 
+  m_exceptions_by_tid[exception_stream.ThreadId] = exception_stream;
+
+
+std::cout << "Adding Exception Stream # " << 
(uint32_t)exception_stream.ThreadId << std::endl;
+std::cout << "Added index " << 
(uint32_t)m_exceptions_by_tid[exception_stream.ThreadId].ExceptionRecord.ExceptionCode
 << std::endl;
+  }
 
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
@@ -232,60 

[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

https://github.com/kastiglione created 
https://github.com/llvm/llvm-project/pull/98190

None

>From 24f2c8ee442b67bae4b78543f54cae4b026f3862 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 8 Jul 2024 11:19:55 -0700
Subject: [PATCH] [lldb] Improve summary string handling of dollar chars

---
 lldb/source/Core/FormatEntity.cpp | 258 +-
 .../data-formatter/special-chars/Makefile |   2 +
 .../TestSummaryStringSpecialChars.py  |  19 ++
 .../data-formatter/special-chars/main.c   |   9 +
 4 files changed, 156 insertions(+), 132 deletions(-)
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/Makefile
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/TestSummaryStringSpecialChars.py
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/main.c

diff --git a/lldb/source/Core/FormatEntity.cpp 
b/lldb/source/Core/FormatEntity.cpp
index fe95858f35c9f..4e1f37099148b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2170,154 +2170,148 @@ static Status ParseInternal(llvm::StringRef &format, 
Entry &parent_entry,
 } break;
 
 case '$':
-  if (format.size() == 1) {
-// '$' at the end of a format string, just print the '$'
+  format = format.drop_front(); // Skip the '$'
+  if (format.empty() || format.front() != '{') {
+// Print '$' when not followed by '{'.
 parent_entry.AppendText("$");
   } else {
-format = format.drop_front(); // Skip the '$'
-
-if (format[0] == '{') {
-  format = format.drop_front(); // Skip the '{'
-
-  llvm::StringRef variable, variable_format;
-  error = FormatEntity::ExtractVariableInfo(format, variable,
-variable_format);
-  if (error.Fail())
-return error;
-  bool verify_is_thread_id = false;
-  Entry entry;
-  if (!variable_format.empty()) {
-entry.printf_format = variable_format.str();
-
-// If the format contains a '%' we are going to assume this is a
-// printf style format. So if you want to format your thread ID
-// using "0x%llx" you can use: ${thread.id%0x%llx}
-//
-// If there is no '%' in the format, then it is assumed to be a
-// LLDB format name, or one of the extended formats specified in
-// the switch statement below.
-
-if (entry.printf_format.find('%') == std::string::npos) {
-  bool clear_printf = false;
-
-  if (entry.printf_format.size() == 1) {
-switch (entry.printf_format[0]) {
-case '@': // if this is an @ sign, print ObjC description
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleLanguageSpecific;
-  clear_printf = true;
-  break;
-case 'V': // if this is a V, print the value using the default
-  // format
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleValue;
-  clear_printf = true;
-  break;
-case 'L': // if this is an L, print the location of the value
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleLocation;
-  clear_printf = true;
-  break;
-case 'S': // if this is an S, print the summary after all
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleSummary;
-  clear_printf = true;
-  break;
-case '#': // if this is a '#', print the number of children
-  entry.number =
-  
ValueObject::eValueObjectRepresentationStyleChildrenCount;
-  clear_printf = true;
-  break;
-case 'T': // if this is a 'T', print the type
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleType;
-  clear_printf = true;
-  break;
-case 'N': // if this is a 'N', print the name
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleName;
-  clear_printf = true;
-  break;
-case '>': // if this is a '>', print the expression path
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleExpressionPath;
-  clear_printf = true;
-  break;
-}
+format = format.drop_front(); // Skip the '{'
+
+llvm::StringRef variable, variable_format;
+error = FormatEntity::ExtractVariableInfo(format, variabl

[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)


Changes



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


4 Files Affected:

- (modified) lldb/source/Core/FormatEntity.cpp (+126-132) 
- (added) lldb/test/API/functionalities/data-formatter/special-chars/Makefile 
(+2) 
- (added) 
lldb/test/API/functionalities/data-formatter/special-chars/TestSummaryStringSpecialChars.py
 (+19) 
- (added) lldb/test/API/functionalities/data-formatter/special-chars/main.c 
(+9) 


``diff
diff --git a/lldb/source/Core/FormatEntity.cpp 
b/lldb/source/Core/FormatEntity.cpp
index fe95858f35c9f..4e1f37099148b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2170,154 +2170,148 @@ static Status ParseInternal(llvm::StringRef &format, 
Entry &parent_entry,
 } break;
 
 case '$':
-  if (format.size() == 1) {
-// '$' at the end of a format string, just print the '$'
+  format = format.drop_front(); // Skip the '$'
+  if (format.empty() || format.front() != '{') {
+// Print '$' when not followed by '{'.
 parent_entry.AppendText("$");
   } else {
-format = format.drop_front(); // Skip the '$'
-
-if (format[0] == '{') {
-  format = format.drop_front(); // Skip the '{'
-
-  llvm::StringRef variable, variable_format;
-  error = FormatEntity::ExtractVariableInfo(format, variable,
-variable_format);
-  if (error.Fail())
-return error;
-  bool verify_is_thread_id = false;
-  Entry entry;
-  if (!variable_format.empty()) {
-entry.printf_format = variable_format.str();
-
-// If the format contains a '%' we are going to assume this is a
-// printf style format. So if you want to format your thread ID
-// using "0x%llx" you can use: ${thread.id%0x%llx}
-//
-// If there is no '%' in the format, then it is assumed to be a
-// LLDB format name, or one of the extended formats specified in
-// the switch statement below.
-
-if (entry.printf_format.find('%') == std::string::npos) {
-  bool clear_printf = false;
-
-  if (entry.printf_format.size() == 1) {
-switch (entry.printf_format[0]) {
-case '@': // if this is an @ sign, print ObjC description
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleLanguageSpecific;
-  clear_printf = true;
-  break;
-case 'V': // if this is a V, print the value using the default
-  // format
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleValue;
-  clear_printf = true;
-  break;
-case 'L': // if this is an L, print the location of the value
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleLocation;
-  clear_printf = true;
-  break;
-case 'S': // if this is an S, print the summary after all
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleSummary;
-  clear_printf = true;
-  break;
-case '#': // if this is a '#', print the number of children
-  entry.number =
-  
ValueObject::eValueObjectRepresentationStyleChildrenCount;
-  clear_printf = true;
-  break;
-case 'T': // if this is a 'T', print the type
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleType;
-  clear_printf = true;
-  break;
-case 'N': // if this is a 'N', print the name
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleName;
-  clear_printf = true;
-  break;
-case '>': // if this is a '>', print the expression path
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleExpressionPath;
-  clear_printf = true;
-  break;
-}
+format = format.drop_front(); // Skip the '{'
+
+llvm::StringRef variable, variable_format;
+error = FormatEntity::ExtractVariableInfo(format, variable,
+  variable_format);
+if (error.Fail())
+  return error;
+bool verify_is_thread_id = false;
+Entry entry;
+if (!variable_format.empty()) {
+  entry.printf_format = variable_format.str();
+
+  // If the format contains a '%' we are going t

[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
822a818786ccd726e20e2b12cbcccbf9a8f23d4c...24f2c8ee442b67bae4b78543f54cae4b026f3862
 
lldb/test/API/functionalities/data-formatter/special-chars/TestSummaryStringSpecialChars.py
``





View the diff from darker here.


``diff
--- TestSummaryStringSpecialChars.py2024-07-09 17:08:42.00 +
+++ TestSummaryStringSpecialChars.py2024-07-09 17:12:36.183515 +
@@ -3,11 +3,10 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
 class TestCase(TestBase):
-
 def test_summary_string_with_bare_dollar_char(self):
 self.build()
 lldbutil.run_to_source_breakpoint(self, "break here", 
lldb.SBFileSpec("main.c"))
 self.runCmd("type summary add --summary-string '$ $CASH $' --no-value 
Dollars")
 self.expect("v cash", startstr="(Dollars) cash = $ $CASH $")

``




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


[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-09 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/97470

>From 8647eccd35085ab80f978fabb78b016915c5524f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/8] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(exception_stream.ThreadId) > 0) {
+  // We only cast to avoid the warning around converting little endian in 
printf.
+  error.SetErrorStringWithFormat("duplicate exception stream for tid %" 
PRIu32, (uint32_t)exception_stream.ThreadId);
+  return error;
+} else 
+  m_exceptions_by_tid[exception_stream.ThreadId] = exception_stream;
+
+
+std::cout << "Adding Exception Stream # " << 
(uint32_t)exception_stream.ThreadId << std::endl;
+std::cout << "Added index " << 
(uint32_t)m_exceptions_by_tid[exception_stream.ThreadId].ExceptionRecord.ExceptionCode
 << std::endl;
+  }
 
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
@@ -232,60 

[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-09 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-09 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

Seems okay to me, but I'm not exactly an expert when it comes to lldb-dap. 
You'll probably want to get sign-off from at least another person.

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-09 Thread Alex Langford via lldb-commits


@@ -18,6 +18,32 @@ class SBLanguageRuntime {
   static lldb::LanguageType GetLanguageTypeFromString(const char *string);
 
   static const char *GetNameForLanguageType(lldb::LanguageType language);
+
+  /// Returns whether the given language is any version of  C++.

bulbazord wrote:

nit: extra space between `of` and `C++` at the end.

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-09 Thread Alex Langford via lldb-commits


@@ -26,3 +26,43 @@ SBLanguageRuntime::GetNameForLanguageType(lldb::LanguageType 
language) {
 
   return Language::GetNameForLanguageType(language);
 }
+
+bool SBLanguageRuntime::LanguageIsCPlusPlus(lldb::LanguageType language) {
+  return Language::LanguageIsCPlusPlus(language);
+}
+
+bool SBLanguageRuntime::LanguageIsObjC(lldb::LanguageType language) {
+  return Language::LanguageIsObjC(language);
+}
+
+bool SBLanguageRuntime::LanguageIsCFamily(lldb::LanguageType language) {
+  return Language::LanguageIsCFamily(language);
+}
+
+bool SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow(
+lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return lang_plugin->SupportsExceptionBreakpointsOnThrow();
+  return false;
+}
+
+bool SBLanguageRuntime::SupportsExceptionBreakpointsOnCatch(
+lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return lang_plugin->SupportsExceptionBreakpointsOnCatch();
+  return false;
+}
+
+const char *
+SBLanguageRuntime::GetThrowKeywordForLanguage(lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return ConstString(lang_plugin->GetThrowKeyword().data()).AsCString();

bulbazord wrote:

Shouldn't need to do `.data()` at the end there. `ConstString::ConstString` can 
accept `llvm::StringRef` as an argument, and even better it doesn't have to 
re-calculate the length of the string when you do so.

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-09 Thread Alex Langford via lldb-commits


@@ -80,6 +87,45 @@ void DAP::PopulateExceptionBreakpoints() {
   exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
   lldb::eLanguageTypeSwift);
 }
+// Besides handling the hardcoded list of languages from above, we try to
+// find any other languages that support exception breakpoints using the
+// SB API.
+for (int raw_lang = lldb::eLanguageTypeUnknown;
+ raw_lang < lldb::eNumLanguageTypes; ++raw_lang) {
+  lldb::LanguageType lang = static_cast(raw_lang);
+
+  // We first discard any languages already handled above.
+  if (lldb::SBLanguageRuntime::LanguageIsCFamily(lang) ||
+  lang == lldb::eLanguageTypeSwift)
+continue;
+
+  if (!lldb::SBDebugger::SupportsLanguage(lang))
+continue;
+
+  const char *name = lldb::SBLanguageRuntime::GetNameForLanguageType(lang);
+  if (!name)
+continue;
+  std::string raw_lang_name = name;
+  std::string capitalized_lang_name = capitalize(name);
+  const char *raw_throw_keyword =
+  lldb::SBLanguageRuntime::GetThrowKeywordForLanguage(lang);
+  const char *raw_catch_keyword =
+  lldb::SBLanguageRuntime::GetCatchKeywordForLanguage(lang);
+  std::string throw_keyword =
+  raw_throw_keyword ? raw_throw_keyword : "throw";
+  std::string catch_keyword =
+  raw_catch_keyword ? raw_catch_keyword : "catch";

bulbazord wrote:

Suggestion: Instead of always calculating the keywords, why not calculate them 
conditionally below?

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


[Lldb-commits] [clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)

2024-07-09 Thread Alex Langford via lldb-commits


@@ -47,13 +47,12 @@ namespace sys {
   /// The particular format of the names are target dependent, and suitable for
   /// passing as -mattr to the target which matches the host.
   ///
-  /// \param Features - A string mapping feature names to either
-  /// true (if enabled) or false (if disabled). This routine makes no 
guarantees
-  /// about exactly which features may appear in this map, except that they are
-  /// all valid LLVM feature names.
-  ///
-  /// \return - True on success.
-  bool getHostCPUFeatures(StringMap &Features);
+  /// \return - A string map mapping feature names to either true (if enabled)
+  /// or false (if disabled). This routine makes no guarantees about exactly
+  /// which features may appear in this map, except that they are all valid 
LLVM
+  /// feature names. The map can be empty, for example if feature detection
+  /// fails.
+  StringMap getHostCPUFeatures();

bulbazord wrote:

While we're here, maybe the return type should be marked `const`? This is a 
map, and `operator[]` is notoriously easy to mess up with maps. This might save 
somebody a big headache down the line.

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


[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)

2024-07-09 Thread Alex Langford via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread Alex Langford via lldb-commits

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

Makes sense to me

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


[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

kastiglione wrote:

Note that this is essentially a few lines of concrete change, most of the 
change is whitespace only. Use `?w=1` to filter out whitespace only changes: 
https://github.com/llvm/llvm-project/pull/98190/files?w=1

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


[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/98190

>From 24f2c8ee442b67bae4b78543f54cae4b026f3862 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 8 Jul 2024 11:19:55 -0700
Subject: [PATCH 1/2] [lldb] Improve summary string handling of dollar chars

---
 lldb/source/Core/FormatEntity.cpp | 258 +-
 .../data-formatter/special-chars/Makefile |   2 +
 .../TestSummaryStringSpecialChars.py  |  19 ++
 .../data-formatter/special-chars/main.c   |   9 +
 4 files changed, 156 insertions(+), 132 deletions(-)
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/Makefile
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/TestSummaryStringSpecialChars.py
 create mode 100644 
lldb/test/API/functionalities/data-formatter/special-chars/main.c

diff --git a/lldb/source/Core/FormatEntity.cpp 
b/lldb/source/Core/FormatEntity.cpp
index fe95858f35c9f..4e1f37099148b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2170,154 +2170,148 @@ static Status ParseInternal(llvm::StringRef &format, 
Entry &parent_entry,
 } break;
 
 case '$':
-  if (format.size() == 1) {
-// '$' at the end of a format string, just print the '$'
+  format = format.drop_front(); // Skip the '$'
+  if (format.empty() || format.front() != '{') {
+// Print '$' when not followed by '{'.
 parent_entry.AppendText("$");
   } else {
-format = format.drop_front(); // Skip the '$'
-
-if (format[0] == '{') {
-  format = format.drop_front(); // Skip the '{'
-
-  llvm::StringRef variable, variable_format;
-  error = FormatEntity::ExtractVariableInfo(format, variable,
-variable_format);
-  if (error.Fail())
-return error;
-  bool verify_is_thread_id = false;
-  Entry entry;
-  if (!variable_format.empty()) {
-entry.printf_format = variable_format.str();
-
-// If the format contains a '%' we are going to assume this is a
-// printf style format. So if you want to format your thread ID
-// using "0x%llx" you can use: ${thread.id%0x%llx}
-//
-// If there is no '%' in the format, then it is assumed to be a
-// LLDB format name, or one of the extended formats specified in
-// the switch statement below.
-
-if (entry.printf_format.find('%') == std::string::npos) {
-  bool clear_printf = false;
-
-  if (entry.printf_format.size() == 1) {
-switch (entry.printf_format[0]) {
-case '@': // if this is an @ sign, print ObjC description
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleLanguageSpecific;
-  clear_printf = true;
-  break;
-case 'V': // if this is a V, print the value using the default
-  // format
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleValue;
-  clear_printf = true;
-  break;
-case 'L': // if this is an L, print the location of the value
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleLocation;
-  clear_printf = true;
-  break;
-case 'S': // if this is an S, print the summary after all
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleSummary;
-  clear_printf = true;
-  break;
-case '#': // if this is a '#', print the number of children
-  entry.number =
-  
ValueObject::eValueObjectRepresentationStyleChildrenCount;
-  clear_printf = true;
-  break;
-case 'T': // if this is a 'T', print the type
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleType;
-  clear_printf = true;
-  break;
-case 'N': // if this is a 'N', print the name
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleName;
-  clear_printf = true;
-  break;
-case '>': // if this is a '>', print the expression path
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleExpressionPath;
-  clear_printf = true;
-  break;
-}
+format = format.drop_front(); // Skip the '{'
+
+llvm::StringRef variable, variable_format;
+error = FormatEntity::ExtractVariableInfo(format, variable,

[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] 10f3f06 - [lldb] Improve summary string handling of dollar chars (#98190)

2024-07-09 Thread via lldb-commits

Author: Dave Lee
Date: 2024-07-09T13:35:34-07:00
New Revision: 10f3f06d865fe5ec434fbaf78009301e95b59ea5

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

LOG: [lldb] Improve summary string handling of dollar chars (#98190)

This improves the handling of `$` (dollar) characters in summary strings in the 
following ways:

1. When a `$` is not followed by an open paren (`{`), it should be treated as a 
literal 
character and preserved in the output. Previously, the dollar would be consumed 
by the 
parser and not shown in the output.
2. When a `$` is the last character of a format string, this change eliminates 
the 
infinite loop lldb would enter into.

rdar://131392446

Added: 
lldb/test/API/functionalities/data-formatter/special-chars/Makefile

lldb/test/API/functionalities/data-formatter/special-chars/TestSummaryStringSpecialChars.py
lldb/test/API/functionalities/data-formatter/special-chars/main.c

Modified: 
lldb/source/Core/FormatEntity.cpp

Removed: 




diff  --git a/lldb/source/Core/FormatEntity.cpp 
b/lldb/source/Core/FormatEntity.cpp
index fe95858f35c9f..4e1f37099148b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2170,154 +2170,148 @@ static Status ParseInternal(llvm::StringRef &format, 
Entry &parent_entry,
 } break;
 
 case '$':
-  if (format.size() == 1) {
-// '$' at the end of a format string, just print the '$'
+  format = format.drop_front(); // Skip the '$'
+  if (format.empty() || format.front() != '{') {
+// Print '$' when not followed by '{'.
 parent_entry.AppendText("$");
   } else {
-format = format.drop_front(); // Skip the '$'
-
-if (format[0] == '{') {
-  format = format.drop_front(); // Skip the '{'
-
-  llvm::StringRef variable, variable_format;
-  error = FormatEntity::ExtractVariableInfo(format, variable,
-variable_format);
-  if (error.Fail())
-return error;
-  bool verify_is_thread_id = false;
-  Entry entry;
-  if (!variable_format.empty()) {
-entry.printf_format = variable_format.str();
-
-// If the format contains a '%' we are going to assume this is a
-// printf style format. So if you want to format your thread ID
-// using "0x%llx" you can use: ${thread.id%0x%llx}
-//
-// If there is no '%' in the format, then it is assumed to be a
-// LLDB format name, or one of the extended formats specified in
-// the switch statement below.
-
-if (entry.printf_format.find('%') == std::string::npos) {
-  bool clear_printf = false;
-
-  if (entry.printf_format.size() == 1) {
-switch (entry.printf_format[0]) {
-case '@': // if this is an @ sign, print ObjC description
-  entry.number = ValueObject::
-  eValueObjectRepresentationStyleLanguageSpecific;
-  clear_printf = true;
-  break;
-case 'V': // if this is a V, print the value using the default
-  // format
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleValue;
-  clear_printf = true;
-  break;
-case 'L': // if this is an L, print the location of the value
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleLocation;
-  clear_printf = true;
-  break;
-case 'S': // if this is an S, print the summary after all
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleSummary;
-  clear_printf = true;
-  break;
-case '#': // if this is a '#', print the number of children
-  entry.number =
-  
ValueObject::eValueObjectRepresentationStyleChildrenCount;
-  clear_printf = true;
-  break;
-case 'T': // if this is a 'T', print the type
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleType;
-  clear_printf = true;
-  break;
-case 'N': // if this is a 'N', print the name
-  entry.number =
-  ValueObject::eValueObjectRepresentationStyleName;
-  clear_printf = true;
-  break;
-case '>': // if this is a '>', print the expression path
-  entry.number = ValueObj

[Lldb-commits] [lldb] [lldb] Improve summary string handling of dollar chars (PR #98190)

2024-07-09 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] 7021e44 - [lldb][test] Set target and host OS for API tests in case of remote testing

2024-07-09 Thread via lldb-commits

Author: Vladislav Dzhidzhoev
Date: 2024-07-10T00:25:50+02:00
New Revision: 7021e44b2f0e11717c0d82456bad0fed4a0b48f9

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

LOG: [lldb][test] Set target and host OS for API tests in case of remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit moves the platform detection logic from Makefile to Python lldb
test suite.

This is useful for the case of Windows-to-Linux cross-testing.

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..818fdf0e6b5c5 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -92,11 +92,28 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+# Provide uname-like platform name
+platform_name_to_uname = {
+"linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+"macosx": "Darwin",
+"darwin": "Darwin",
+}
+
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
+
 return dictionary
 
 

diff  --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bd8eea3d6f5a0..3d562285ce9cc 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -55,7 +55,10 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
-HOST_OS := $(shell uname -s)
+ifeq "$(HOST_OS)" ""
+  HOST_OS := $(shell uname -s)
+endif
+
 ifneq (,$(findstring windows32,$(HOST_OS)))
HOST_OS := Windows_NT
 endif



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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-09 Thread Vladislav Dzhidzhoev via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix the flaky test dwp-foreign-type-units.cpp. (PR #98237)

2024-07-09 Thread Zequan Wu via lldb-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/98237

Use `--match-full-lines` with FileCheck. Otherwise, the checks for `int` and 
`unsigned int` will match to the fields inside two `CustomType`s and FileCheck 
will start scanning from there, causing string not found error.

>From f103032c6218dc6cddc3c5d267aed86adc2aac56 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 9 Jul 2024 15:47:38 -0700
Subject: [PATCH] [lldb] Fix the flaky test dwp-foreign-type-units.cpp.

Use `--match-full-lines` with FileCheck. Otherwise, the checks for `int` and 
`unsigned int` will match to the fields inside two `CustomType`s and FileCheck 
will start scanning from there, causing stirng not found error.
---
 .../Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
index ef15d418b4cfe..415b4850a244c 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
@@ -1,6 +1,4 @@
 // REQUIRES: lld
-// Is flaky on Windows.
-// UNSUPPORTED: system-windows
 
 // This test will make a type that will be compiled differently into two
 // different .dwo files in a type unit with the same type hash, but with
@@ -30,7 +28,7 @@
 // RUN:   -o "type lookup IntegerType" \
 // RUN:   -o "type lookup FloatType" \
 // RUN:   -o "type lookup CustomType" \
-// RUN:   -b %t | FileCheck %s --check-prefix=NODWP
+// RUN:   -b %t | FileCheck %s --check-prefix=NODWP --match-full-lines
 // NODWP: (lldb) type lookup IntegerType
 // NODWP-DAG: int
 // NODWP-DAG: unsigned int

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


[Lldb-commits] [lldb] Fix the test to deal with non-deterministic output. (PR #96800)

2024-07-09 Thread Zequan Wu via lldb-commits

ZequanWu wrote:

This also failed for me on Linux. I sent a fix at 
https://github.com/llvm/llvm-project/pull/98237 which also enables it on 
windows.

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


[Lldb-commits] [lldb] [lldb] Fix the flaky test dwp-foreign-type-units.cpp. (PR #98237)

2024-07-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Zequan Wu (ZequanWu)


Changes

Use `--match-full-lines` with FileCheck. Otherwise, the checks for `int` and 
`unsigned int` will match to the fields inside two `CustomType`s and FileCheck 
will start scanning from there, causing string not found error.

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


1 Files Affected:

- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp 
(+1-3) 


``diff
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
index ef15d418b4cfe..415b4850a244c 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
@@ -1,6 +1,4 @@
 // REQUIRES: lld
-// Is flaky on Windows.
-// UNSUPPORTED: system-windows
 
 // This test will make a type that will be compiled differently into two
 // different .dwo files in a type unit with the same type hash, but with
@@ -30,7 +28,7 @@
 // RUN:   -o "type lookup IntegerType" \
 // RUN:   -o "type lookup FloatType" \
 // RUN:   -o "type lookup CustomType" \
-// RUN:   -b %t | FileCheck %s --check-prefix=NODWP
+// RUN:   -b %t | FileCheck %s --check-prefix=NODWP --match-full-lines
 // NODWP: (lldb) type lookup IntegerType
 // NODWP-DAG: int
 // NODWP-DAG: unsigned int

``




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


[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-09 Thread Kendal Harland via lldb-commits


@@ -55,14 +55,23 @@ def test_basic(self):
 self.assertEqual(len(step_in_targets), 3, "expect 3 step in targets")
 
 # Verify the target names are correct.
-self.assertEqual(step_in_targets[0]["label"], "bar()", "expect bar()")
-self.assertEqual(step_in_targets[1]["label"], "bar2()", "expect 
bar2()")
-self.assertEqual(
-step_in_targets[2]["label"], "foo(int, int)", "expect foo(int, 
int)"
-)
+# The order of funcA and funcB may change depending on the compiler 
ABI.
+funcA_target = None
+funcB_target = None
+for target in step_in_targets[0:2]:
+if "funcB" in target["label"]:
+funcB_target = target
+elif "funcA" in target["label"]:
+funcA_target = target
+else:
+self.fail(f"Unexpected step in target: {target}")
+
+self.assertIsNotNone(funcA_target, "expect funcA")
+self.assertIsNotNone(funcB_target, "expect funcB")
+self.assertIn("foo", step_in_targets[2]["label"], "expect foo")
 
-# Choose to step into second target and verify that we are in bar2()
-self.stepIn(threadId=tid, targetId=step_in_targets[1]["id"], 
waitForStop=True)
+# Choose to step into second target and verify that we are in funcB()

kendalharland wrote:

Thanks for the explanation! This sounds like the right thing to do, however I 
believe I'm hitting a bug: the test's DAP always steps into funcB regardless of 
the option passed to `targetId`.  Would you be able to reproduce this? If it 
reproduces for you, I wonder if this has always been broken, given that IIRC 
there's no Windows x64 CI and this test only runs when the architecture is 
x86_64.

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


[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-09 Thread Kendal Harland via lldb-commits

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


[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-09 Thread Kendal Harland via lldb-commits

https://github.com/kendalharland updated 
https://github.com/llvm/llvm-project/pull/96687

>From 02f06f90a40cc7ed18a9744918acf4daf6212486 Mon Sep 17 00:00:00 2001
From: kendal 
Date: Mon, 24 Jun 2024 14:01:31 -0700
Subject: [PATCH] Fix test assertions in TestDAP_stepInTargets.py

---
 .../stepInTargets/TestDAP_stepInTargets.py| 24 +--
 .../API/tools/lldb-dap/stepInTargets/main.cpp |  6 ++---
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git 
a/lldb/test/API/tools/lldb-dap/stepInTargets/TestDAP_stepInTargets.py 
b/lldb/test/API/tools/lldb-dap/stepInTargets/TestDAP_stepInTargets.py
index 6296f6554d07e..6670989a58fe8 100644
--- a/lldb/test/API/tools/lldb-dap/stepInTargets/TestDAP_stepInTargets.py
+++ b/lldb/test/API/tools/lldb-dap/stepInTargets/TestDAP_stepInTargets.py
@@ -55,14 +55,24 @@ def test_basic(self):
 self.assertEqual(len(step_in_targets), 3, "expect 3 step in targets")
 
 # Verify the target names are correct.
-self.assertEqual(step_in_targets[0]["label"], "bar()", "expect bar()")
-self.assertEqual(step_in_targets[1]["label"], "bar2()", "expect 
bar2()")
-self.assertEqual(
-step_in_targets[2]["label"], "foo(int, int)", "expect foo(int, 
int)"
-)
+# The order of funcA and funcB may change depending on the compiler 
ABI.
+funcA_target = None
+funcB_target = None
+for target in step_in_targets[0:2]:
+if "funcB" in target["label"]:
+funcB_target = target
+elif "funcA" in target["label"]:
+funcA_target = target
+else:
+self.fail(f"Unexpected step in target: {target}")
+
+self.assertIsNotNone(funcA_target, "expect funcA")
+self.assertIsNotNone(funcB_target, "expect funcB")
+self.assertIn("foo", step_in_targets[2]["label"], "expect foo")
 
-# Choose to step into second target and verify that we are in bar2()
+# Choose to step into second target and verify that we are in the 
second target,
+# be it funcA or funcB.
 self.stepIn(threadId=tid, targetId=step_in_targets[1]["id"], 
waitForStop=True)
 leaf_frame = self.dap_server.get_stackFrame()
 self.assertIsNotNone(leaf_frame, "expect a leaf frame")
-self.assertEqual(leaf_frame["name"], "bar2()")
+self.assertEqual(step_in_targets[1]["label"], leaf_frame["name"])
diff --git a/lldb/test/API/tools/lldb-dap/stepInTargets/main.cpp 
b/lldb/test/API/tools/lldb-dap/stepInTargets/main.cpp
index d3c3dbcc139ef..a48b79af0c760 100644
--- a/lldb/test/API/tools/lldb-dap/stepInTargets/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/stepInTargets/main.cpp
@@ -1,11 +1,11 @@
 
 int foo(int val, int extra) { return val + extra; }
 
-int bar() { return 22; }
+int funcA() { return 22; }
 
-int bar2() { return 54; }
+int funcB() { return 54; }
 
 int main(int argc, char const *argv[]) {
-  foo(bar(), bar2()); // set breakpoint here
+  foo(funcA(), funcB()); // set breakpoint here
   return 0;
 }

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


[Lldb-commits] [lldb] 12239d2 - [lldb] Small cleanup of ProcessEventData::ShouldStop (#98154)

2024-07-09 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-10T04:05:43+02:00
New Revision: 12239d253d555d6cbd65588b72e9da7acf482c2f

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

LOG: [lldb] Small cleanup of ProcessEventData::ShouldStop (#98154)

While looking at a TSAN report (patch coming soon) in the ThreadList
class, I noticed that this code would be simpler if it did not use the
ThreadList class.

Added: 


Modified: 
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 6fac0df1d7a66..dc7f6c9e86a47 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4152,7 +4152,6 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
 
   ThreadList &curr_thread_list = process_sp->GetThreadList();
   uint32_t num_threads = curr_thread_list.GetSize();
-  uint32_t idx;
 
   // The actions might change one of the thread's stop_info's opinions about
   // whether we should stop the process, so we need to query that as we go.
@@ -4162,23 +4161,18 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // get that wrong (which is possible) then the thread list might have
   // changed, and that would cause our iteration here to crash.  We could
   // make a copy of the thread list, but we'd really like to also know if it
-  // has changed at all, so we make up a vector of the thread ID's and check
-  // what we get back against this list & bag out if anything 
diff ers.
-  ThreadList not_suspended_thread_list(process_sp.get());
-  std::vector thread_index_array(num_threads);
-  uint32_t not_suspended_idx = 0;
-  for (idx = 0; idx < num_threads; ++idx) {
+  // has changed at all, so we store the original thread ID's of all threads 
and
+  // check what we get back against this list & bag out if anything 
diff ers.
+  std::vector> not_suspended_threads;
+  for (uint32_t idx = 0; idx < num_threads; ++idx) {
 lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx);
 
 /*
  Filter out all suspended threads, they could not be the reason
  of stop and no need to perform any actions on them.
  */
-if (thread_sp->GetResumeState() != eStateSuspended) {
-  not_suspended_thread_list.AddThread(thread_sp);
-  thread_index_array[not_suspended_idx] = thread_sp->GetIndexID();
-  not_suspended_idx++;
-}
+if (thread_sp->GetResumeState() != eStateSuspended)
+  not_suspended_threads.emplace_back(thread_sp, thread_sp->GetIndexID());
   }
 
   // Use this to track whether we should continue from here.  We will only
@@ -4194,8 +4188,7 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   // is, and it's better to let the user decide than continue behind their
   // backs.
 
-  for (idx = 0; idx < not_suspended_thread_list.GetSize(); ++idx) {
-curr_thread_list = process_sp->GetThreadList();
+  for (auto [thread_sp, thread_index] : not_suspended_threads) {
 if (curr_thread_list.GetSize() != num_threads) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
   LLDB_LOGF(
@@ -4205,14 +4198,11 @@ bool Process::ProcessEventData::ShouldStop(Event 
*event_ptr,
   break;
 }
 
-lldb::ThreadSP thread_sp = not_suspended_thread_list.GetThreadAtIndex(idx);
-
-if (thread_sp->GetIndexID() != thread_index_array[idx]) {
+if (thread_sp->GetIndexID() != thread_index) {
   Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
-  LLDB_LOGF(log,
-"The thread at position %u changed from %u to %u while "
-"processing event.",
-idx, thread_index_array[idx], thread_sp->GetIndexID());
+  LLDB_LOG(log,
+   "The thread {0} changed from {1} to {2} while processing 
event.",
+   thread_sp.get(), thread_index, thread_sp->GetIndexID());
   break;
 }
 



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


[Lldb-commits] [lldb] [lldb] Small cleanup of ProcessEventData::ShouldStop (PR #98154)

2024-07-09 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);

cmtice wrote:

They are all implemented in the parser file (which I did not include in this 
PR).  IsSmartPtr is called in both the DIL parser and the DIL evaluator; 
GetMemberInfo is called in both the DIL parser and the DIL AST implementation.  
Since the DILAST.h file needs to be included in both the parser and the 
evaluator (and the AST implementation), I put function declarations for 
functions called in multiple files into DILAST.h.  I can remove them if you 
want, but will then need to add them back in when for the parser PR.  Let me 
know what you would prefer.

Initially GetFieldWithNameIndexPath was also called from multiple files, but it 
looks like it's now only called from the parser, so I will move that function 
declaration to the parser header file.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};

cmtice wrote:

Frame var doesn't allow users to specify casts of variables, but it does do 
some implicit type conversions/casting when evaluating variables, e.g. 
arrays-to-pointers, and various implicit type promotions & conversions. The DIL 
stripped down parser/evaluator still needs to do these promotions & 
conversions, and uses these for that work.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.

cmtice wrote:

I don't understand what you're suggesting here. How would using the synthetic 
dereference operation help to determine if a pointer variable is a 'smart' 
pointer vs a regular one?

(I'll remove the second declaration; as mentioned above, this function is 
implemented in the parser file).

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,446 @@
+//===-- DILAST.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_DIL_AST_H_
+#define LLDB_DIL_AST_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Utility/ConstString.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+
+namespace lldb_private {
+
+/// Struct to hold information about member fields. Used by the parser for the
+/// Data Inspection Language (DIL).
+struct DILMemberInfo {
+  std::optional name;
+  CompilerType type;
+  bool is_bitfield;
+  uint32_t bitfield_size_in_bits;
+  bool is_synthetic;
+  bool is_dynamic;
+  lldb::ValueObjectSP val_obj_sp;
+
+  explicit operator bool() const { return type.IsValid(); }
+};
+
+/// This determines if the type is a shared, unique or weak pointer, either
+/// from stdlibc++ or libc+++.
+bool IsSmartPtrType(CompilerType type);
+
+/// Finds the member field with the given name and type, stores the child index
+/// corresponding to the field in the idx vector and returns a DILMemberInfo
+/// struct with appropriate information about the field.
+DILMemberInfo GetFieldWithNameIndexPath(lldb::ValueObjectSP lhs_val_sp,
+CompilerType type,
+const std::string &name,
+std::vector *idx,
+CompilerType empty_type,
+bool use_synthetic, bool is_dynamic);
+
+std::tuple>
+GetMemberInfo(lldb::ValueObjectSP lhs_val_sp, CompilerType type,
+  const std::string &name, bool use_synthetic);
+
+/// Get the appropriate ValueObjectSP, consulting the use_dynamic and
+/// use_synthetic options passed, acquiring the process & target locks if
+/// appropriate.
+lldb::ValueObjectSP
+DILGetSPWithLock(lldb::ValueObjectSP valobj_sp,
+ lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues,
+ bool use_synthetic = false);
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class DILNodeKind {
+  kDILErrorNode,
+  kLiteralNode,
+  kIdentifierNode,
+  kBuiltinFunctionCallNode,
+  kCStyleCastNode,
+  kMemberOfNode,
+  kArraySubscriptNode,
+  kUnaryOpNode,
+  kSmartPtrToPtrDecay
+};
+
+/// The C-Style casts allowed by DIL.
+enum class CStyleCastKind {
+  kArithmetic,
+  kEnumeration,
+  kPointer,
+  kNullptr,
+  kReference,
+};
+
+/// The Unary operators recognized by DIL.
+enum class UnaryOpKind {
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
+};
+
+/// Given a string representing a type, returns the CompilerType corresponding
+/// to the named type, if it exists.
+CompilerType
+ResolveTypeByName(const std::string &name,
+  std::shared_ptr ctx_scope);
+
+/// Quick lookup to check if a type name already exists in a
+/// name-to-CompilerType map the DIL parser keeps of previously found
+/// name/type pairs.
+bool IsContextVar(const std::string &name);
+
+/// Checks to see if the CompilerType is a Smart Pointer (shared, unique, weak)
+/// or not. Only applicable for C++, which is why this is here and not part of
+/// the CompilerType class.

labath wrote:

It wouldn't. I assumed that this was used to determine support dereferencing of 
smart pointers. If that's not true, then my question is: Why do we need to know 
if something is a (c++) smart pointer?

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