[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-01-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,191 @@
+//===-- DILLexer.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
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===--===//
+
+#include "lldb/ValueObject/DILLexer.h"
+
+namespace lldb_private {
+
+namespace dil {
+
+const std::string DILToken::getTokenName(dil::TokenKind kind) {
+  std::string retval;
+  switch (kind) {
+  case dil::TokenKind::coloncolon:
+retval = "coloncolon";
+break;
+  case dil::TokenKind::eof:
+retval = "eof";
+break;
+  case dil::TokenKind::identifier:
+retval = "identifier";
+break;
+  case dil::TokenKind::kw_namespace:
+retval = "namespace";
+break;
+  case dil::TokenKind::kw_this:
+retval = "this";
+break;
+  case dil::TokenKind::l_paren:
+retval = "l_paren";
+break;
+  case dil::TokenKind::r_paren:
+retval = "r_paren";
+break;
+  case dil::TokenKind::unknown:
+retval = "unknown";
+break;
+  default:
+retval = "token_name";
+break;
+  }
+  return retval;
+}
+
+static bool Is_Letter(char c) {
+  if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
+return true;
+  return false;
+}
+
+static bool Is_Digit(char c) { return ('0' <= c && c <= '9'); }
+
+bool DILLexer::Is_Word(std::string::iterator start, uint32_t &length) {
+  bool done = false;
+  for (; m_cur_pos != m_expr.end() && !done; ++m_cur_pos) {
+char c = *m_cur_pos;
+if (!Is_Letter(c) && !Is_Digit(c) && c != '_') {
+  done = true;
+  break;
+} else
+  length++;
+  }
+  if (length > 0)
+return true;
+  else
+m_cur_pos = start;
+  return false;
+}
+
+void DILLexer::UpdateLexedTokens(DILToken &result, dil::TokenKind tok_kind,
+ std::string tok_str, uint32_t tok_pos,
+ uint32_t tok_len) {
+  DILToken new_token;
+  result.setValues(tok_kind, tok_str, tok_pos, tok_len);
+  new_token = result;
+  m_lexed_tokens.push_back(std::move(new_token));
+}
+
+bool DILLexer::Lex(DILToken &result, bool look_ahead) {
+  bool retval = true;
+
+  if (!look_ahead) {
+// We're being asked for the 'next' token, and not a part of a LookAhead.
+// Check to see if we've already lexed it and pushed it onto our tokens
+// vector; if so, return the next token from the vector, rather than doing
+// more lexing.
+if ((m_tokens_idx != UINT_MAX) &&
+(m_tokens_idx < m_lexed_tokens.size() - 1)) {
+  result = m_lexed_tokens[m_tokens_idx + 1];
+  return retval;
+}
+  }
+
+  // Skip over whitespace (spaces).
+  while (m_cur_pos != m_expr.end() && *m_cur_pos == ' ')
+m_cur_pos++;
+
+  // Check to see if we've reached the end of our input string.
+  if (m_cur_pos == m_expr.end()) {
+UpdateLexedTokens(result, dil::TokenKind::eof, "", m_expr.length(), 0);
+return retval;
+  }
+
+  uint32_t position = m_cur_pos - m_expr.begin();
+  ;
+  std::string::iterator start = m_cur_pos;
+  uint32_t length = 0;
+  if (Is_Word(start, length)) {
+dil::TokenKind kind;
+std::string word = m_expr.substr(position, length);
+if (word == "this")

labath wrote:

I don't think handling `self` as well would make it better.

The question of modifying `this` is interesting, but I don't think it should 
require special handling here. As far as modification is concerned, I think 
`this` is not different from a variable of type (e.g.) `const int` -- the 
language forbids you from modifying it, the debugger can do that anyway if it 
really wants to, but the result may not be what you expect:
```
Process 48439 stopped
* thread #1, name = 'a.out', stop reason = step over
frame #0: 0x520b a.out`X::foo(this=0x7fffd7d7) at 
a.cc:7:5
   4public:
   5  void foo() {
   6const int x = 47;
-> 7printf("this = %p, x = %d\n", this, x);
   8  }
   9};
   10   
(lldb) v this x
(X *) this = 0x7fffd7d7
(const int) x = 47
(lldb) script lldb.frame.FindVariable("x").SetValueFromCString("74")
True
(lldb) script lldb.frame.FindVariable("this").SetValueFromCString("0")
True
(lldb) v this x
(X *) this = nullptr
(const int) x = 74
(lldb) c
Process 48439 resuming
this = 0x7fffd7d7, x = 47
Process 48439 exited with status = 0 (0x) 
```

Given that SBValue currently allows you to modify both variables, I think DIL 
(which is basically a domain-specific language for SBValue operations) should 
be doing the same. If that doesn't convince you, con

[Lldb-commits] [lldb] [lldb][AIX] Added support for AIX in HostInfo section (PR #122301)

2025-01-09 Thread Dhruv Srivastava via lldb-commits

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


[Lldb-commits] [lldb] b1893ca - [lldb][AIX] Added support for AIX in HostInfo section (#122301)

2025-01-09 Thread via lldb-commits

Author: Lakshmi-Surekha
Date: 2025-01-10T07:21:10+05:30
New Revision: b1893caeb6b6079a66ba146e73d68d6255d255ce

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

LOG: [lldb][AIX] Added support for AIX in HostInfo section (#122301)

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
https://github.com/llvm/llvm-project/issues/101657
2. The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
Added support for AIX in HostInfo section

Review Request : @DavidSpickett @labath @DhruvSrivastavaX

Added: 


Modified: 
lldb/include/lldb/Host/HostInfo.h

Removed: 




diff  --git a/lldb/include/lldb/Host/HostInfo.h 
b/lldb/include/lldb/Host/HostInfo.h
index b7010d69d88e7f..0f7ec0e0aa0d24 100644
--- a/lldb/include/lldb/Host/HostInfo.h
+++ b/lldb/include/lldb/Host/HostInfo.h
@@ -55,6 +55,9 @@
 #elif defined(__APPLE__)
 #include "lldb/Host/macosx/HostInfoMacOSX.h"
 #define HOST_INFO_TYPE HostInfoMacOSX
+#elif defined(_AIX)
+#include "lldb/Host/aix/HostInfoAIX.h"
+#define HOST_INFO_TYPE HostInfoAIX
 #else
 #include "lldb/Host/posix/HostInfoPosix.h"
 #define HOST_INFO_TYPE HostInfoPosix



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


[Lldb-commits] [lldb] [lldb][AIX] Added support for AIX in HostInfo section (PR #122301)

2025-01-09 Thread via lldb-commits

github-actions[bot] wrote:



@Lakshmi-Surekha Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[Lldb-commits] [lldb] [lldb][AIX] Added support for AIX in HostInfo section (PR #122301)

2025-01-09 Thread Dhruv Srivastava via lldb-commits

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


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


[Lldb-commits] [lldb] [llvm] Debuginfod cache use index cache settings and include real file name (PR #120814)

2025-01-09 Thread via lldb-commits

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


[Lldb-commits] [lldb] [llvm] Debuginfod cache use index cache settings and include real file name (PR #120814)

2025-01-09 Thread via lldb-commits

https://github.com/GeorgeHuyubo updated 
https://github.com/llvm/llvm-project/pull/120814

>From 6923737d728191816567e7874a01c5dfce68bfde Mon Sep 17 00:00:00 2001
From: George Hu 
Date: Fri, 20 Dec 2024 15:20:00 -0800
Subject: [PATCH 1/2] [lldb] Change debuginfod cache file name to include
 origin file name

---
 .../Debuginfod/SymbolLocatorDebuginfod.cpp| 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp 
b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
index 2cd7244902..c103c98d20ac27 100644
--- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
@@ -141,6 +141,25 @@ SymbolLocator *SymbolLocatorDebuginfod::CreateInstance() {
   return new SymbolLocatorDebuginfod();
 }
 
+static llvm::StringRef getFileName(const ModuleSpec &module_spec,
+   std::string url_path) {
+  // Check if the URL path requests an executable file or a symbol file
+  bool is_executable = url_path.find("debuginfo") == std::string::npos;
+  if (is_executable) {
+return module_spec.GetFileSpec().GetFilename().GetStringRef();
+  }
+  llvm::StringRef symbol_file =
+  module_spec.GetSymbolFileSpec().GetFilename().GetStringRef();
+  // Remove llvmcache- prefix and hash, keep origin file name
+  if (symbol_file.starts_with("llvmcache-")) {
+size_t pos = symbol_file.rfind('-');
+if (pos != llvm::StringRef::npos) {
+  symbol_file = symbol_file.substr(pos + 1);
+}
+  }
+  return symbol_file;
+}
+
 static std::optional
 GetFileForModule(const ModuleSpec &module_spec,
  std::function UrlBuilder) 
{
@@ -166,9 +185,13 @@ GetFileForModule(const ModuleSpec &module_spec,
   // We're ready to ask the Debuginfod library to find our file.
   llvm::object::BuildID build_id(module_uuid.GetBytes());
   std::string url_path = UrlBuilder(build_id);
-  std::string cache_key = llvm::getDebuginfodCacheKey(url_path);
+  llvm::StringRef file_name = getFileName(module_spec, url_path);
+  std::string cache_file_name = llvm::toHex(build_id, true);
+  if (!file_name.empty()) {
+cache_file_name += "-" + file_name.str();
+  }
   llvm::Expected result = llvm::getCachedOrDownloadArtifact(
-  cache_key, url_path, cache_path, debuginfod_urls, timeout);
+  cache_file_name, url_path, cache_path, debuginfod_urls, timeout);
   if (result)
 return FileSpec(*result);
 

>From 7b808e73aa0193c8a42eae8f2420a803f424bee1 Mon Sep 17 00:00:00 2001
From: George Hu 
Date: Fri, 20 Dec 2024 16:37:50 -0800
Subject: [PATCH 2/2] [lldb] Switch debuginfod cache to use lldb index cache
 settings

---
 .../Debuginfod/SymbolLocatorDebuginfod.cpp| 17 +++
 llvm/include/llvm/Debuginfod/Debuginfod.h |  4 ++-
 llvm/lib/Debuginfod/Debuginfod.cpp| 29 +--
 llvm/unittests/Debuginfod/DebuginfodTests.cpp |  3 +-
 4 files changed, 36 insertions(+), 17 deletions(-)

diff --git 
a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp 
b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
index c103c98d20ac27..00b4c9a45b5a76 100644
--- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp
@@ -8,6 +8,7 @@
 
 #include "SymbolLocatorDebuginfod.h"
 
+#include "lldb/Core/DataFileCache.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Interpreter/OptionValueString.h"
 #include "lldb/Utility/Args.h"
@@ -173,11 +174,14 @@ GetFileForModule(const ModuleSpec &module_spec,
   // Grab LLDB's Debuginfod overrides from the
   // plugin.symbol-locator.debuginfod.* settings.
   PluginProperties &plugin_props = GetGlobalPluginProperties();
-  llvm::Expected cache_path_or_err = plugin_props.GetCachePath();
-  // A cache location is *required*.
-  if (!cache_path_or_err)
-return {};
-  std::string cache_path = *cache_path_or_err;
+  // Grab the lldb index cache settings from the global module list properties.
+  ModuleListProperties &properties =
+  ModuleList::GetGlobalModuleListProperties();
+  std::string cache_path = properties.GetLLDBIndexCachePath().GetPath();
+
+  llvm::CachePruningPolicy pruning_policy =
+  DataFileCache::GetLLDBIndexCachePolicy();
+
   llvm::SmallVector debuginfod_urls =
   llvm::getDefaultDebuginfodUrls();
   std::chrono::milliseconds timeout = plugin_props.GetTimeout();
@@ -191,7 +195,8 @@ GetFileForModule(const ModuleSpec &module_spec,
 cache_file_name += "-" + file_name.str();
   }
   llvm::Expected result = llvm::getCachedOrDownloadArtifact(
-  cache_file_name, url_path, cache_path, debuginfod_urls, timeout);
+  cache_file_name, url_path, cache_path, debuginfod_urls, timeout,
+  pruning_policy);
   if (result)
 return FileSpec(*result);
 
diff --git 

[Lldb-commits] [lldb] Refactor `ThreadList::WillResume()` to prepare to support reverse execution (PR #120817)

2025-01-09 Thread via lldb-commits


@@ -582,31 +531,92 @@ bool ThreadList::WillResume() {
   // There are two special kinds of thread that have priority for "StopOthers":
   // a "ShouldRunBeforePublicStop thread, or the currently selected thread.  If
   // we find one satisfying that critereon, put it here.
-  ThreadSP stop_others_thread_sp;
-
+  ThreadSP thread_to_run;
   for (pos = m_threads.begin(); pos != end; ++pos) {
 ThreadSP thread_sp(*pos);
 if (thread_sp->GetResumeState() != eStateSuspended &&
 thread_sp->GetCurrentPlan()->StopOthers()) {
-  if ((*pos)->IsOperatingSystemPluginThread() &&
-  !(*pos)->GetBackingThread())
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
 continue;
 
   // You can't say "stop others" and also want yourself to be suspended.
   assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
   run_me_only_list.AddThread(thread_sp);
 
   if (thread_sp == GetSelectedThread())
-stop_others_thread_sp = thread_sp;
-
+thread_to_run = thread_sp;
+
   if (thread_sp->ShouldRunBeforePublicStop()) {
 // This takes precedence, so if we find one of these, service it:
-stop_others_thread_sp = thread_sp;
+thread_to_run = thread_sp;
 break;
   }
 }
   }
 
+  if (run_me_only_list.GetSize(false) > 0 && !thread_to_run) {
+if (run_me_only_list.GetSize(false) == 1) {
+  thread_to_run = run_me_only_list.GetThreadAtIndex(0);
+} else {
+  int random_thread =
+  (int)((run_me_only_list.GetSize(false) * (double)rand()) /
+(RAND_MAX + 1.0));
+  thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
+}
+  }
+
+  // Give all the threads that are likely to run a last chance to set up their
+  // state before we negotiate who is actually going to get a chance to run...
+  // Don't set to resume suspended threads, and if any thread wanted to stop
+  // others, only call setup on the threads that request StopOthers...
+  bool wants_solo_run = run_me_only_list.GetSize(false) > 0;
+  for (pos = m_threads.begin(); pos != end; ++pos) {
+ThreadSP thread_sp(*pos);
+// See if any thread wants to run stopping others.  If it does, then we
+// won't setup the other threads for resume, since they aren't going to get
+// a chance to run.  This is necessary because the SetupForResume might add
+// "StopOthers" plans which would then get to be part of the 
who-gets-to-run
+// negotiation, but they're coming in after the fact, and the threads that
+// are already set up should take priority.
+if (thread_sp->GetResumeState() != eStateSuspended &&
+(!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
+continue;
+  if (thread_sp->SetupForResume()) {
+// You can't say "stop others" and also want yourself to be suspended.
+assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
+run_me_only_list.AddThread(thread_sp);

jimingham wrote:

And anyway, if wants_solo_run is false, you end up adding every thread that 
needs to step over a breakpoint to the run_me_only list, but then don't do 
anything with any of them.

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


[Lldb-commits] [lldb] Refactor `ThreadList::WillResume()` to prepare to support reverse execution (PR #120817)

2025-01-09 Thread via lldb-commits


@@ -582,31 +531,92 @@ bool ThreadList::WillResume() {
   // There are two special kinds of thread that have priority for "StopOthers":
   // a "ShouldRunBeforePublicStop thread, or the currently selected thread.  If
   // we find one satisfying that critereon, put it here.
-  ThreadSP stop_others_thread_sp;
-
+  ThreadSP thread_to_run;
   for (pos = m_threads.begin(); pos != end; ++pos) {
 ThreadSP thread_sp(*pos);
 if (thread_sp->GetResumeState() != eStateSuspended &&
 thread_sp->GetCurrentPlan()->StopOthers()) {
-  if ((*pos)->IsOperatingSystemPluginThread() &&
-  !(*pos)->GetBackingThread())
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
 continue;
 
   // You can't say "stop others" and also want yourself to be suspended.
   assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
   run_me_only_list.AddThread(thread_sp);
 
   if (thread_sp == GetSelectedThread())
-stop_others_thread_sp = thread_sp;
-
+thread_to_run = thread_sp;
+
   if (thread_sp->ShouldRunBeforePublicStop()) {
 // This takes precedence, so if we find one of these, service it:
-stop_others_thread_sp = thread_sp;
+thread_to_run = thread_sp;
 break;
   }
 }
   }
 
+  if (run_me_only_list.GetSize(false) > 0 && !thread_to_run) {
+if (run_me_only_list.GetSize(false) == 1) {
+  thread_to_run = run_me_only_list.GetThreadAtIndex(0);
+} else {
+  int random_thread =
+  (int)((run_me_only_list.GetSize(false) * (double)rand()) /
+(RAND_MAX + 1.0));
+  thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
+}
+  }
+
+  // Give all the threads that are likely to run a last chance to set up their
+  // state before we negotiate who is actually going to get a chance to run...
+  // Don't set to resume suspended threads, and if any thread wanted to stop
+  // others, only call setup on the threads that request StopOthers...
+  bool wants_solo_run = run_me_only_list.GetSize(false) > 0;
+  for (pos = m_threads.begin(); pos != end; ++pos) {

jimingham wrote:

I must admit I find this version harder to reason about than the original.  
Particularly, I find this second loop confusing.  You have already figured out 
whether you are going to run solo and which thread you are going to run, by the 
time you get to this point.  Then it looks like you do that computation a 
second time in a slightly different way, overwriting the decisions you made 
above in a fairly head-scratching way.

I would have expected at this point that if `thread_to_run` is not empty, you 
could just call SetupForResume on that one thread, and then just that thread 
will run.  It's not at all clear to me what the purpose of redoing the 
computation is.

There's one difference between the two computations.  In the first loop, you 
give every thread that wants to run solo a chance to be the one to do that and 
pick among them equally.  Then in this loop if the thread you chose to run 
doesn't return `true` from `SetupForResume` (because it isn't at a breakpoint) 
but there's another wants to run solo thread that is at a breakpoint, we switch 
to that one.

You are changing behavior here because you prioritize threads that need to step 
over breakpoints in a way that we didn't before, but the logic seems unclear to 
me.

Can you say in words what behaviors you are intending to impose with this extra 
"am I stepping over a breakpoint" check?

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


[Lldb-commits] [lldb] Refactor `ThreadList::WillResume()` to prepare to support reverse execution (PR #120817)

2025-01-09 Thread via lldb-commits


@@ -582,31 +531,92 @@ bool ThreadList::WillResume() {
   // There are two special kinds of thread that have priority for "StopOthers":
   // a "ShouldRunBeforePublicStop thread, or the currently selected thread.  If
   // we find one satisfying that critereon, put it here.
-  ThreadSP stop_others_thread_sp;
-
+  ThreadSP thread_to_run;
   for (pos = m_threads.begin(); pos != end; ++pos) {
 ThreadSP thread_sp(*pos);
 if (thread_sp->GetResumeState() != eStateSuspended &&
 thread_sp->GetCurrentPlan()->StopOthers()) {
-  if ((*pos)->IsOperatingSystemPluginThread() &&
-  !(*pos)->GetBackingThread())
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
 continue;
 
   // You can't say "stop others" and also want yourself to be suspended.
   assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
   run_me_only_list.AddThread(thread_sp);
 
   if (thread_sp == GetSelectedThread())
-stop_others_thread_sp = thread_sp;
-
+thread_to_run = thread_sp;
+
   if (thread_sp->ShouldRunBeforePublicStop()) {
 // This takes precedence, so if we find one of these, service it:
-stop_others_thread_sp = thread_sp;
+thread_to_run = thread_sp;
 break;
   }
 }
   }
 
+  if (run_me_only_list.GetSize(false) > 0 && !thread_to_run) {
+if (run_me_only_list.GetSize(false) == 1) {
+  thread_to_run = run_me_only_list.GetThreadAtIndex(0);
+} else {
+  int random_thread =
+  (int)((run_me_only_list.GetSize(false) * (double)rand()) /
+(RAND_MAX + 1.0));
+  thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
+}
+  }
+
+  // Give all the threads that are likely to run a last chance to set up their
+  // state before we negotiate who is actually going to get a chance to run...
+  // Don't set to resume suspended threads, and if any thread wanted to stop
+  // others, only call setup on the threads that request StopOthers...
+  bool wants_solo_run = run_me_only_list.GetSize(false) > 0;
+  for (pos = m_threads.begin(); pos != end; ++pos) {
+ThreadSP thread_sp(*pos);
+// See if any thread wants to run stopping others.  If it does, then we
+// won't setup the other threads for resume, since they aren't going to get
+// a chance to run.  This is necessary because the SetupForResume might add
+// "StopOthers" plans which would then get to be part of the 
who-gets-to-run
+// negotiation, but they're coming in after the fact, and the threads that
+// are already set up should take priority.
+if (thread_sp->GetResumeState() != eStateSuspended &&
+(!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
+continue;
+  if (thread_sp->SetupForResume()) {
+// You can't say "stop others" and also want yourself to be suspended.
+assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
+run_me_only_list.AddThread(thread_sp);

jimingham wrote:

Why does this do any good?  You didn't clear the list, and you aren't going to 
add threads here that didn't get added in the first loop.  So you're just 
adding them twice.

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


[Lldb-commits] [lldb] Refactor `ThreadList::WillResume()` to prepare to support reverse execution (PR #120817)

2025-01-09 Thread via lldb-commits


@@ -582,31 +531,92 @@ bool ThreadList::WillResume() {
   // There are two special kinds of thread that have priority for "StopOthers":
   // a "ShouldRunBeforePublicStop thread, or the currently selected thread.  If
   // we find one satisfying that critereon, put it here.
-  ThreadSP stop_others_thread_sp;
-
+  ThreadSP thread_to_run;
   for (pos = m_threads.begin(); pos != end; ++pos) {
 ThreadSP thread_sp(*pos);
 if (thread_sp->GetResumeState() != eStateSuspended &&
 thread_sp->GetCurrentPlan()->StopOthers()) {
-  if ((*pos)->IsOperatingSystemPluginThread() &&
-  !(*pos)->GetBackingThread())
+  if (thread_sp->IsOperatingSystemPluginThread() &&
+  !thread_sp->GetBackingThread())
 continue;
 
   // You can't say "stop others" and also want yourself to be suspended.
   assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
   run_me_only_list.AddThread(thread_sp);
 
   if (thread_sp == GetSelectedThread())
-stop_others_thread_sp = thread_sp;
-
+thread_to_run = thread_sp;
+
   if (thread_sp->ShouldRunBeforePublicStop()) {
 // This takes precedence, so if we find one of these, service it:
-stop_others_thread_sp = thread_sp;
+thread_to_run = thread_sp;
 break;
   }
 }
   }
 
+  if (run_me_only_list.GetSize(false) > 0 && !thread_to_run) {
+if (run_me_only_list.GetSize(false) == 1) {
+  thread_to_run = run_me_only_list.GetThreadAtIndex(0);
+} else {
+  int random_thread =
+  (int)((run_me_only_list.GetSize(false) * (double)rand()) /
+(RAND_MAX + 1.0));
+  thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
+}
+  }
+
+  // Give all the threads that are likely to run a last chance to set up their
+  // state before we negotiate who is actually going to get a chance to run...
+  // Don't set to resume suspended threads, and if any thread wanted to stop
+  // others, only call setup on the threads that request StopOthers...
+  bool wants_solo_run = run_me_only_list.GetSize(false) > 0;
+  for (pos = m_threads.begin(); pos != end; ++pos) {
+ThreadSP thread_sp(*pos);
+// See if any thread wants to run stopping others.  If it does, then we
+// won't setup the other threads for resume, since they aren't going to get
+// a chance to run.  This is necessary because the SetupForResume might add
+// "StopOthers" plans which would then get to be part of the 
who-gets-to-run
+// negotiation, but they're coming in after the fact, and the threads that
+// are already set up should take priority.
+if (thread_sp->GetResumeState() != eStateSuspended &&
+(!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {

jimingham wrote:

*pos -> thread_sp

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


[Lldb-commits] [lldb] [lldb] Store *signed* ranges in lldb_private::Block (PR #120224)

2025-01-09 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] a261eee - [lldb] Store *signed* ranges in lldb_private::Block (#120224)

2025-01-09 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-01-09T10:52:04+01:00
New Revision: a261eee61200cb6aa3eac0e7dc03940a6afd7d54

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

LOG: [lldb] Store *signed* ranges in lldb_private::Block (#120224)

This is to support functions whose entry points aren't their lowest
address

(https://discourse.llvm.org/t/rfcish-support-for-discontinuous-functions/83244).
The alternative is to keep blocks relative to the lowest address, but
then introduce a separate concept for the function entry point, which I
think would be more confusing.

This patch just changes the type signedness, it doesn't create any
negative offsets yet. Since combining values with different signs can
sometimes produce unexpected results, and since this is the first use of
RangeVector with a signed type, I'm adding a test to verify that at
least the core functionality works correctly.

Added: 


Modified: 
lldb/include/lldb/Symbol/Block.h
lldb/unittests/Utility/RangeMapTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/Block.h 
b/lldb/include/lldb/Symbol/Block.h
index 7c7a66de831998..d0063f132cc0ff 100644
--- a/lldb/include/lldb/Symbol/Block.h
+++ b/lldb/include/lldb/Symbol/Block.h
@@ -40,7 +40,7 @@ namespace lldb_private {
 /// blocks.
 class Block : public UserID, public SymbolContextScope {
 public:
-  typedef RangeVector RangeList;
+  typedef RangeVector RangeList;
   typedef RangeList::Entry Range;
 
   // Creates a block representing the whole function. Only meant to be used 
from

diff  --git a/lldb/unittests/Utility/RangeMapTest.cpp 
b/lldb/unittests/Utility/RangeMapTest.cpp
index 0b4c236062f20b..981fa2a7d1c34e 100644
--- a/lldb/unittests/Utility/RangeMapTest.cpp
+++ b/lldb/unittests/Utility/RangeMapTest.cpp
@@ -12,6 +12,29 @@
 
 using namespace lldb_private;
 
+TEST(RangeVector, SignedBaseType) {
+  using RangeVector = RangeVector;
+  using Entry = RangeVector::Entry;
+
+  RangeVector V;
+  V.Append(10, 5);
+  V.Append(-3, 6);
+  V.Append(-10, 3);
+  V.Sort();
+  EXPECT_THAT(V,
+  testing::ElementsAre(Entry(-10, 3), Entry(-3, 6), Entry(10, 5)));
+  Entry e = *V.begin();
+  EXPECT_EQ(e.GetRangeBase(), -10);
+  EXPECT_EQ(e.GetByteSize(), 3u);
+  EXPECT_EQ(e.GetRangeEnd(), -7);
+  EXPECT_TRUE(e.Contains(-10));
+  EXPECT_TRUE(e.Contains(-8));
+  EXPECT_FALSE(e.Contains(-7));
+  EXPECT_TRUE(e.Union(Entry(-8, 2)));
+  EXPECT_EQ(e, Entry(-10, 4));
+  EXPECT_EQ(e.Intersect(Entry(-7, 3)), Entry(-7, 1));
+}
+
 TEST(RangeVector, CombineConsecutiveRanges) {
   using RangeVector = RangeVector;
   using Entry = RangeVector::Entry;



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


[Lldb-commits] [lldb] d3f1b86 - [lldb][NFC] clang-format MemoryRegionInfo.h

2025-01-09 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2025-01-09T10:54:52Z
New Revision: d3f1b864ae1b2c3fce343863d494a40fc231ca16

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

LOG: [lldb][NFC] clang-format MemoryRegionInfo.h

To clean up future changes for shadow stack regions.

Added: 


Modified: 
lldb/include/lldb/Target/MemoryRegionInfo.h

Removed: 




diff  --git a/lldb/include/lldb/Target/MemoryRegionInfo.h 
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 66a4b3ed1b42d5..7e1385b210b8c6 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -27,9 +27,9 @@ class MemoryRegionInfo {
   MemoryRegionInfo() = default;
   MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
OptionalBool execute, OptionalBool shared,
-   OptionalBool mapped, ConstString name,
-   OptionalBool flash, lldb::offset_t blocksize,
-   OptionalBool memory_tagged, OptionalBool stack_memory)
+   OptionalBool mapped, ConstString name, OptionalBool flash,
+   lldb::offset_t blocksize, OptionalBool memory_tagged,
+   OptionalBool stack_memory)
   : m_range(range), m_read(read), m_write(write), m_execute(execute),
 m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
 m_blocksize(blocksize), m_memory_tagged(memory_tagged),
@@ -101,9 +101,9 @@ class MemoryRegionInfo {
   bool operator==(const MemoryRegionInfo &rhs) const {
 return m_range == rhs.m_range && m_read == rhs.m_read &&
m_write == rhs.m_write && m_execute == rhs.m_execute &&
-   m_shared == rhs.m_shared &&
-   m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
-   m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
+   m_shared == rhs.m_shared && m_mapped == rhs.m_mapped &&
+   m_name == rhs.m_name && m_flash == rhs.m_flash &&
+   m_blocksize == rhs.m_blocksize &&
m_memory_tagged == rhs.m_memory_tagged &&
m_pagesize == rhs.m_pagesize &&
m_is_stack_memory == rhs.m_is_stack_memory;
@@ -174,7 +174,7 @@ class MemoryRegionInfos : public 
std::vector {
   using std::vector::vector;
 };
 
-}
+} // namespace lldb_private
 
 namespace llvm {
 template <>
@@ -186,6 +186,6 @@ struct 
format_provider {
   static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
  raw_ostream &OS, StringRef Options);
 };
-}
+} // namespace llvm
 
 #endif // LLDB_TARGET_MEMORYREGIONINFO_H



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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits

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

>From ecac70b8d7b00e729b3203c6d5e6aff827775467 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 19 Aug 2024 15:55:45 +0100
Subject: [PATCH 1/2] [lldb][Linux] Mark memory regions used for shadow stacks

This is intended for use with Arm's Guarded Control Stack extension
(GCS). Which reuses some existing shadow stack support in Linux.
It should also work with the x86 equivalent.

A "ss" flag is added to the "VmFlags" line of shadow stack memory
regions in /proc//smaps. To keep the naming generic I've called
it shadow stack instead of guarded control stack.

Also the wording is "shadow stack: yes" because the shadow stack
region is just where it's stored. It's enabled for the whole process
or it isn't. As opposed to memory tagging which can be enabled per
region, so "memory tagging: enabled" fits better for that.

I've added a test case that is also intended to be the start of
a set of tests for GCS. This should help me avoid duplicating the
inline assembly needed.

Note that no special compiler support is needed for the test.
However, for the intial enabling of GCS (assuming the libc isn't
doing it) we do need to use an inline assembly version of prctl.

This is because as soon as you enable GCS, all returns are checked
against the GCS. If the GCS is empty, the program will fault.
In other words, you can never return from the function that enabled
GCS, unless you push values onto it (which is possible but not needed
here).

So you cannot use the libc's prctl wrapper for this reason. You can
use that wrapper for anything else, as we do to check if GCS is
enabled.
---
 lldb/include/lldb/Target/MemoryRegionInfo.h   |  22 ++-
 .../Python/lldbsuite/test/lldbtest.py |   3 +
 lldb/source/Commands/CommandObjectMemory.cpp  |   3 +
 .../Plugins/Process/Utility/LinuxProcMaps.cpp |  15 +-
 .../GDBRemoteCommunicationClient.cpp  |   7 +-
 .../GDBRemoteCommunicationServerLLGS.cpp  |  12 +-
 lldb/source/Target/MemoryRegionInfo.cpp   |   5 +-
 lldb/test/API/linux/aarch64/gcs/Makefile  |   3 +
 .../linux/aarch64/gcs/TestAArch64LinuxGCS.py  |  63 +++
 lldb/test/API/linux/aarch64/gcs/main.c|  54 ++
 .../Process/Utility/LinuxProcMapsTest.cpp | 156 +-
 .../MemoryTagManagerAArch64MTETest.cpp|  10 +-
 .../GDBRemoteCommunicationClientTest.cpp  |   5 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  92 ++-
 14 files changed, 304 insertions(+), 146 deletions(-)
 create mode 100644 lldb/test/API/linux/aarch64/gcs/Makefile
 create mode 100644 lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
 create mode 100644 lldb/test/API/linux/aarch64/gcs/main.c

diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h 
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 66a4b3ed1b42d5..3e1272c2bba214 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -27,13 +27,13 @@ class MemoryRegionInfo {
   MemoryRegionInfo() = default;
   MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
OptionalBool execute, OptionalBool shared,
-   OptionalBool mapped, ConstString name,
-   OptionalBool flash, lldb::offset_t blocksize,
-   OptionalBool memory_tagged, OptionalBool stack_memory)
+   OptionalBool mapped, ConstString name, OptionalBool flash,
+   lldb::offset_t blocksize, OptionalBool memory_tagged,
+   OptionalBool stack_memory, OptionalBool shadow_stack)
   : m_range(range), m_read(read), m_write(write), m_execute(execute),
 m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
 m_blocksize(blocksize), m_memory_tagged(memory_tagged),
-m_is_stack_memory(stack_memory) {}
+m_is_stack_memory(stack_memory), m_is_shadow_stack(shadow_stack) {}
 
   RangeType &GetRange() { return m_range; }
 
@@ -55,6 +55,8 @@ class MemoryRegionInfo {
 
   OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
 
+  OptionalBool IsShadowStack() const { return m_is_shadow_stack; }
+
   void SetReadable(OptionalBool val) { m_read = val; }
 
   void SetWritable(OptionalBool val) { m_write = val; }
@@ -77,6 +79,8 @@ class MemoryRegionInfo {
 
   void SetMemoryTagged(OptionalBool val) { m_memory_tagged = val; }
 
+  void SetIsShadowStack(OptionalBool val) { m_is_shadow_stack = val; }
+
   // Get permissions as a uint32_t that is a mask of one or more bits from the
   // lldb::Permissions
   uint32_t GetLLDBPermissions() const {
@@ -101,12 +105,13 @@ class MemoryRegionInfo {
   bool operator==(const MemoryRegionInfo &rhs) const {
 return m_range == rhs.m_range && m_read == rhs.m_read &&
m_write == rhs.m_write && m_execute == rhs.m_execute &&
-   m_shared == rhs.m_shared &&
-   m_mapped == rhs.m_mapped && m_name == rhs.

[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -164,12 +164,17 @@ void lldb_private::ParseLinuxSMapRegions(llvm::StringRef 
linux_smap,
 if (!name.contains(' ')) {
   if (region) {
 if (name == "VmFlags") {
-  if (value.contains("mt"))
-region->SetMemoryTagged(MemoryRegionInfo::eYes);
-  else
-region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetIsShadowStack(MemoryRegionInfo::eNo);
+
+  llvm::SmallVector flags;
+  value.split(flags, ' ', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+  for (llvm::StringRef flag : flags)

DavidSpickett wrote:

> It would be nice to be lazy and only tokenise as much as we need from the 
> string though. I'll see if there's an iterator version I can use.

You can do something like:
```
while value
  split by space
  if flag is not empty: check flag
```
But to make this early exit we'd need to know what we're looking for up front, 
which I can do but it's a bit complex for a single line that's going to be 
small 99% of the time.

I do use this strategy for patching in register information, but there it's 
because we're iterating over 100s of registers each time.

> You made me realise I don't actually have a test case to check we don't match 
> on substrings though, so I will add that.

I added this in LinuxProcMapsTest.cpp

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -276,20 +278,35 @@ INSTANTIATE_TEST_SUITE_P(
 "MMUPageSize:   4 kB\n",
 MemoryRegionInfos{
 MemoryRegionInfo(
-make_range(0x, 0x),
-MemoryRegionInfo::eYes, MemoryRegionInfo::eYes, 
MemoryRegionInfo::eNo,
-MemoryRegionInfo::eNo,
-MemoryRegionInfo::eYes, ConstString(nullptr),
-MemoryRegionInfo::eDontKnow, 0, 
MemoryRegionInfo::eDontKnow,
+make_range(0x, 0x), MemoryRegionInfo::eYes,
+MemoryRegionInfo::eYes, MemoryRegionInfo::eNo,
+MemoryRegionInfo::eNo, MemoryRegionInfo::eYes,
+ConstString(nullptr), MemoryRegionInfo::eDontKnow, 0,
+MemoryRegionInfo::eDontKnow, MemoryRegionInfo::eDontKnow,
 MemoryRegionInfo::eDontKnow),
 MemoryRegionInfo(
-make_range(0x, 0x),
-MemoryRegionInfo::eYes, MemoryRegionInfo::eNo, 
MemoryRegionInfo::eYes,
-MemoryRegionInfo::eNo,
-MemoryRegionInfo::eYes, ConstString(nullptr),
-MemoryRegionInfo::eDontKnow, 0, 
MemoryRegionInfo::eDontKnow,
+make_range(0x, 0x), MemoryRegionInfo::eYes,
+MemoryRegionInfo::eNo, MemoryRegionInfo::eYes,
+MemoryRegionInfo::eNo, MemoryRegionInfo::eYes,
+ConstString(nullptr), MemoryRegionInfo::eDontKnow, 0,
+MemoryRegionInfo::eDontKnow, MemoryRegionInfo::eDontKnow,
 MemoryRegionInfo::eDontKnow),
 },
+""),
+// We must look for exact flag strings, ignoring substrings of longer
+// flag names.
+std::make_tuple(
+"0-0 rw-p  00:00 0\n"
+"VmFlags: amt mtb amtb",

DavidSpickett wrote:

New test added here.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -2796,11 +2796,17 @@ 
GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
 // Flags
 MemoryRegionInfo::OptionalBool memory_tagged =
 region_info.GetMemoryTagged();
-if (memory_tagged != MemoryRegionInfo::eDontKnow) {
+MemoryRegionInfo::OptionalBool is_shadow_stack =
+region_info.IsShadowStack();
+
+if (memory_tagged != MemoryRegionInfo::eDontKnow ||
+is_shadow_stack != MemoryRegionInfo::eDontKnow) {
   response.PutCString("flags:");
-  if (memory_tagged == MemoryRegionInfo::eYes) {
+  if (memory_tagged == MemoryRegionInfo::eYes)
 response.PutCString("mt");
-  }
+  if (is_shadow_stack == MemoryRegionInfo::eYes)

DavidSpickett wrote:

Fixed.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits

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

>From 17f7ee60f32194aa60b9aed3fd92618cd31b020a Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 19 Aug 2024 15:55:45 +0100
Subject: [PATCH 1/2] [lldb][Linux] Mark memory regions used for shadow stacks

This is intended for use with Arm's Guarded Control Stack extension
(GCS). Which reuses some existing shadow stack support in Linux.
It should also work with the x86 equivalent.

A "ss" flag is added to the "VmFlags" line of shadow stack memory
regions in /proc//smaps. To keep the naming generic I've called
it shadow stack instead of guarded control stack.

Also the wording is "shadow stack: yes" because the shadow stack
region is just where it's stored. It's enabled for the whole process
or it isn't. As opposed to memory tagging which can be enabled per
region, so "memory tagging: enabled" fits better for that.

I've added a test case that is also intended to be the start of
a set of tests for GCS. This should help me avoid duplicating the
inline assembly needed.

Note that no special compiler support is needed for the test.
However, for the intial enabling of GCS (assuming the libc isn't
doing it) we do need to use an inline assembly version of prctl.

This is because as soon as you enable GCS, all returns are checked
against the GCS. If the GCS is empty, the program will fault.
In other words, you can never return from the function that enabled
GCS, unless you push values onto it (which is possible but not needed
here).

So you cannot use the libc's prctl wrapper for this reason. You can
use that wrapper for anything else, as we do to check if GCS is
enabled.
---
 lldb/include/lldb/Target/MemoryRegionInfo.h   |  12 +-
 .../Python/lldbsuite/test/lldbtest.py |   3 +
 lldb/source/Commands/CommandObjectMemory.cpp  |   3 +
 .../Plugins/Process/Utility/LinuxProcMaps.cpp |  15 +-
 .../GDBRemoteCommunicationClient.cpp  |   7 +-
 .../GDBRemoteCommunicationServerLLGS.cpp  |  12 +-
 lldb/source/Target/MemoryRegionInfo.cpp   |   5 +-
 lldb/test/API/linux/aarch64/gcs/Makefile  |   3 +
 .../linux/aarch64/gcs/TestAArch64LinuxGCS.py  |  63 +++
 lldb/test/API/linux/aarch64/gcs/main.c|  54 ++
 .../Process/Utility/LinuxProcMapsTest.cpp | 156 +-
 .../MemoryTagManagerAArch64MTETest.cpp|  10 +-
 .../GDBRemoteCommunicationClientTest.cpp  |   5 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  92 ++-
 14 files changed, 299 insertions(+), 141 deletions(-)
 create mode 100644 lldb/test/API/linux/aarch64/gcs/Makefile
 create mode 100644 lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
 create mode 100644 lldb/test/API/linux/aarch64/gcs/main.c

diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h 
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 7e1385b210b8c6..dc37a7dbeda52a 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -29,11 +29,11 @@ class MemoryRegionInfo {
OptionalBool execute, OptionalBool shared,
OptionalBool mapped, ConstString name, OptionalBool flash,
lldb::offset_t blocksize, OptionalBool memory_tagged,
-   OptionalBool stack_memory)
+   OptionalBool stack_memory, OptionalBool shadow_stack)
   : m_range(range), m_read(read), m_write(write), m_execute(execute),
 m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
 m_blocksize(blocksize), m_memory_tagged(memory_tagged),
-m_is_stack_memory(stack_memory) {}
+m_is_stack_memory(stack_memory), m_is_shadow_stack(shadow_stack) {}
 
   RangeType &GetRange() { return m_range; }
 
@@ -55,6 +55,8 @@ class MemoryRegionInfo {
 
   OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
 
+  OptionalBool IsShadowStack() const { return m_is_shadow_stack; }
+
   void SetReadable(OptionalBool val) { m_read = val; }
 
   void SetWritable(OptionalBool val) { m_write = val; }
@@ -77,6 +79,8 @@ class MemoryRegionInfo {
 
   void SetMemoryTagged(OptionalBool val) { m_memory_tagged = val; }
 
+  void SetIsShadowStack(OptionalBool val) { m_is_shadow_stack = val; }
+
   // Get permissions as a uint32_t that is a mask of one or more bits from the
   // lldb::Permissions
   uint32_t GetLLDBPermissions() const {
@@ -106,7 +110,8 @@ class MemoryRegionInfo {
m_blocksize == rhs.m_blocksize &&
m_memory_tagged == rhs.m_memory_tagged &&
m_pagesize == rhs.m_pagesize &&
-   m_is_stack_memory == rhs.m_is_stack_memory;
+   m_is_stack_memory == rhs.m_is_stack_memory &&
+   m_is_shadow_stack == rhs.m_is_shadow_stack;
   }
 
   bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); 
}
@@ -148,6 +153,7 @@ class MemoryRegionInfo {
   lldb::offset_t m_blocksize = 0;
   OptionalBool m_memory_tagged = eDontKnow;
   OptionalBool 

[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -101,12 +105,13 @@ class MemoryRegionInfo {
   bool operator==(const MemoryRegionInfo &rhs) const {
 return m_range == rhs.m_range && m_read == rhs.m_read &&
m_write == rhs.m_write && m_execute == rhs.m_execute &&
-   m_shared == rhs.m_shared &&
-   m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
-   m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
+   m_shared == rhs.m_shared && m_mapped == rhs.m_mapped &&

DavidSpickett wrote:

It was, I've fixed this.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)

2025-01-09 Thread via lldb-commits


@@ -0,0 +1,66 @@
+"""
+Test lldb's ability to read and write the LoongArch LASX registers.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class LoongArch64LinuxRegisters(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def make_lasx_value(self, n):
+return "{" + " ".join(["0x{:02x}".format(n)] * 32) + "}" 
+
+def check_lasx_values(self, value_offset):
+for i in range(32):
+self.expect(
+"register read xr{}".format(i),
+substrs=[self.make_lasx_value(i + value_offset)],
+)
+
+def lasx_registers_impl(self):
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"main.c",
+line_number("main.c", "// Set break point at this line."),
+num_expected_locations=1,
+)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+if self.process().GetState() == lldb.eStateExited:
+self.fail("Test program failed to run.")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+self.check_lasx_values(0)
+self.runCmd("expression write_lasx_regs(2)")

wangleiat wrote:

I'm not sure why this is happening, but these registers are indeed being 
modified on the LoongArch system. It's too late today, so I'll analyze the 
issue tomorrow.
```
Process 3442462 stopped 

* thread #1, name = 'a.out', stop reason = breakpoint 1.1   

frame #0: 0x4784 a.out`main(argc=1, argv=0x7ffef918) at 
lsx.c:13:10 
   10   }   

   11   

   12   int main(int argc, char *argv[]) {  

-> 13 return 0; 

   14   }   

(lldb) register read vr0

 vr0 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00}
(lldb) p write_lsx_regs(1)  

(lldb) register read vr0

 vr0 = {0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 
0x01 0x01 0x01}
(lldb)  

```

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


[Lldb-commits] [lldb] [lldb] Regularize DWARFDIE::Get{TypeLookup, Decl}Context names (PR #122273)

2025-01-09 Thread Michael Buch via lldb-commits

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


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


[Lldb-commits] [lldb] cb04bc0 - [lldb] Move GetEnvironment function into common code (#122173)

2025-01-09 Thread via lldb-commits

Author: Brad Smith
Date: 2025-01-09T09:41:32-05:00
New Revision: cb04bc05ebab5f44b13639c0e3613506180bdbac

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

LOG: [lldb] Move GetEnvironment function into common code (#122173)

Added: 


Modified: 
lldb/source/Host/common/Host.cpp
lldb/source/Host/freebsd/Host.cpp
lldb/source/Host/linux/Host.cpp
lldb/source/Host/netbsd/HostNetBSD.cpp
lldb/source/Host/openbsd/Host.cpp

Removed: 




diff  --git a/lldb/source/Host/common/Host.cpp 
b/lldb/source/Host/common/Host.cpp
index 03ea2f242d3c78..7b2bae74e196fe 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -114,6 +114,10 @@ void LogChannelSystem::Initialize() {
 void LogChannelSystem::Terminate() { g_system_log.Disable(); }
 
 #if !defined(__APPLE__) && !defined(_WIN32)
+extern "C" char **environ;
+
+Environment Host::GetEnvironment() { return Environment(environ); }
+
 static thread_result_t
 MonitorChildProcessThreadFunction(::pid_t pid,
   Host::MonitorChildProcessCallback callback);

diff  --git a/lldb/source/Host/freebsd/Host.cpp 
b/lldb/source/Host/freebsd/Host.cpp
index 89ebe714f095f8..14c0e9f2209d24 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -33,10 +33,6 @@
 
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 namespace lldb_private {
 class ProcessLaunchInfo;
 }
@@ -241,8 +237,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, 
ProcessInstanceInfo &process_info) {
   return false;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
   return Status::FromErrorString("unimplemented");
 }

diff  --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index f5ec2e187af196..25bef9b0e7151b 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -411,8 +411,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, 
ProcessInstanceInfo &process_info) {
   return GetProcessAndStatInfo(pid, process_info, State, tracerpid);
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
   return Status::FromErrorString("unimplemented");
 }

diff  --git a/lldb/source/Host/netbsd/HostNetBSD.cpp 
b/lldb/source/Host/netbsd/HostNetBSD.cpp
index 49ff342fe152f6..8904df5eba03eb 100644
--- a/lldb/source/Host/netbsd/HostNetBSD.cpp
+++ b/lldb/source/Host/netbsd/HostNetBSD.cpp
@@ -35,10 +35,6 @@
 #include "llvm/Object/ELF.h"
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -46,8 +42,6 @@ namespace lldb_private {
 class ProcessLaunchInfo;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch 
*match_info_ptr,
  ProcessInstanceInfo &process_info) {
   if (!process_info.ProcessIDIsValid())

diff  --git a/lldb/source/Host/openbsd/Host.cpp 
b/lldb/source/Host/openbsd/Host.cpp
index 24650ff97075ea..2b66a3c8696b10 100644
--- a/lldb/source/Host/openbsd/Host.cpp
+++ b/lldb/source/Host/openbsd/Host.cpp
@@ -30,10 +30,6 @@
 
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -41,8 +37,6 @@ namespace lldb_private {
 class ProcessLaunchInfo;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 static bool
 GetOpenBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
   ProcessInstanceInfo &process_info) {



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


[Lldb-commits] [lldb] [lldb] Move GetEnvironment function into common code (PR #122173)

2025-01-09 Thread Brad Smith via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add Function::GetAddress and redirect some uses (PR #115836)

2025-01-09 Thread David Spickett via lldb-commits

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

I thought maybe you could call it GetEntryPoint, but I don't think it helps 
much. The answer to which address it is is one "go to definition" away, and 
your point is that the obvious guess is that it's the entry point anyway.

LGTM.

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


[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-backend-x86

Author: Timm Baeder (tbaederr)


Changes



---

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


40 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+1-1) 
- (modified) 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(+1-1) 
- (modified) clang-tools-extra/clangd/Hover.cpp (+1-1) 
- (modified) clang/include/clang/AST/Decl.h (+4-2) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5-5) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+4-6) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+11-5) 
- (modified) clang/lib/AST/DeclCXX.cpp (+1-1) 
- (modified) clang/lib/AST/Expr.cpp (+1-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (modified) clang/lib/AST/Randstruct.cpp (+1-1) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-5) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+10-10) 
- (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/XCore.cpp (+1-1) 
- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11-10) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+1-1) 
- (modified) clang/tools/libclang/CXType.cpp (+1-1) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-2) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp 
(+27-9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Timm Baeder (tbaederr)


Changes



---

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


40 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+1-1) 
- (modified) 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(+1-1) 
- (modified) clang-tools-extra/clangd/Hover.cpp (+1-1) 
- (modified) clang/include/clang/AST/Decl.h (+4-2) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5-5) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+4-6) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+11-5) 
- (modified) clang/lib/AST/DeclCXX.cpp (+1-1) 
- (modified) clang/lib/AST/Expr.cpp (+1-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (modified) clang/lib/AST/Randstruct.cpp (+1-1) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-5) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+10-10) 
- (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/XCore.cpp (+1-1) 
- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11-10) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+1-1) 
- (modified) clang/tools/libclang/CXType.cpp (+1-1) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-2) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp 
(+27-9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/c

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Timm Baeder (tbaederr)


Changes



---

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


40 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+1-1) 
- (modified) 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(+1-1) 
- (modified) clang-tools-extra/clangd/Hover.cpp (+1-1) 
- (modified) clang/include/clang/AST/Decl.h (+4-2) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5-5) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+4-6) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+11-5) 
- (modified) clang/lib/AST/DeclCXX.cpp (+1-1) 
- (modified) clang/lib/AST/Expr.cpp (+1-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (modified) clang/lib/AST/Randstruct.cpp (+1-1) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-5) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+10-10) 
- (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/XCore.cpp (+1-1) 
- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11-10) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+1-1) 
- (modified) clang/tools/libclang/CXType.cpp (+1-1) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-2) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp 
(+27-9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clang

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread Timm Baeder via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID: 
In-Reply-To:


https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/122289

None

>From 813b4bee5bddfbbc3eec8a7047c51cfde825bcee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 9 Jan 2025 16:01:59 +0100
Subject: [PATCH 1/2] Reapply "[clang] Avoid re-evaluating field bitwidth
 (#117732)"

This reverts commit 59bdea24b09bca9332a7092b583ebf377efb0d50.
---
 .../bugprone/NarrowingConversionsCheck.cpp|  2 +-
 .../bugprone/TooSmallLoopVariableCheck.cpp|  2 +-
 .../hicpp/MultiwayPathsCoveredCheck.cpp   |  2 +-
 clang-tools-extra/clangd/Hover.cpp|  2 +-
 clang/include/clang/AST/Decl.h|  6 --
 clang/include/clang/ASTMatchers/ASTMatchers.h |  3 +--
 clang/lib/AST/ASTContext.cpp  | 10 -
 clang/lib/AST/ByteCode/Interp.h   | 10 -
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  8 +++
 clang/lib/AST/Decl.cpp| 16 +-
 clang/lib/AST/DeclCXX.cpp |  2 +-
 clang/lib/AST/Expr.cpp|  3 +--
 clang/lib/AST/ExprConstant.cpp|  2 +-
 clang/lib/AST/Randstruct.cpp  |  2 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  6 +++---
 clang/lib/CodeGen/ABIInfo.cpp |  2 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp |  2 +-
 clang/lib/CodeGen/CGCall.cpp  |  6 +++---
 clang/lib/CodeGen/CGClass.cpp |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++
 clang/lib/CodeGen/CGNonTrivialStruct.cpp  |  6 +++---
 clang/lib/CodeGen/CGObjCMac.cpp   |  3 +--
 clang/lib/CodeGen/CGObjCRuntime.cpp   |  2 +-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 20 +-
 clang/lib/CodeGen/SwiftCallingConv.cpp|  2 +-
 clang/lib/CodeGen/Targets/LoongArch.cpp   |  2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  2 +-
 clang/lib/CodeGen/Targets/X86.cpp |  2 +-
 clang/lib/CodeGen/Targets/XCore.cpp   |  2 +-
 .../Frontend/Rewrite/RewriteModernObjC.cpp|  3 ++-
 clang/lib/Sema/SemaChecking.cpp   | 10 -
 clang/lib/Sema/SemaDecl.cpp   | 21 ++-
 clang/lib/Sema/SemaDeclCXX.cpp|  6 +++---
 clang/lib/Sema/SemaDeclObjC.cpp   |  3 +--
 clang/lib/Sema/SemaOverload.cpp   |  2 +-
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  2 +-
 clang/tools/libclang/CXType.cpp   |  2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  4 ++--
 38 files changed, 96 insertions(+), 94 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread Timm Baeder via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/122289

>From 813b4bee5bddfbbc3eec8a7047c51cfde825bcee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 9 Jan 2025 16:01:59 +0100
Subject: [PATCH 1/2] Reapply "[clang] Avoid re-evaluating field bitwidth
 (#117732)"

This reverts commit 59bdea24b09bca9332a7092b583ebf377efb0d50.
---
 .../bugprone/NarrowingConversionsCheck.cpp|  2 +-
 .../bugprone/TooSmallLoopVariableCheck.cpp|  2 +-
 .../hicpp/MultiwayPathsCoveredCheck.cpp   |  2 +-
 clang-tools-extra/clangd/Hover.cpp|  2 +-
 clang/include/clang/AST/Decl.h|  6 --
 clang/include/clang/ASTMatchers/ASTMatchers.h |  3 +--
 clang/lib/AST/ASTContext.cpp  | 10 -
 clang/lib/AST/ByteCode/Interp.h   | 10 -
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  8 +++
 clang/lib/AST/Decl.cpp| 16 +-
 clang/lib/AST/DeclCXX.cpp |  2 +-
 clang/lib/AST/Expr.cpp|  3 +--
 clang/lib/AST/ExprConstant.cpp|  2 +-
 clang/lib/AST/Randstruct.cpp  |  2 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  6 +++---
 clang/lib/CodeGen/ABIInfo.cpp |  2 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp |  2 +-
 clang/lib/CodeGen/CGCall.cpp  |  6 +++---
 clang/lib/CodeGen/CGClass.cpp |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++
 clang/lib/CodeGen/CGNonTrivialStruct.cpp  |  6 +++---
 clang/lib/CodeGen/CGObjCMac.cpp   |  3 +--
 clang/lib/CodeGen/CGObjCRuntime.cpp   |  2 +-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 20 +-
 clang/lib/CodeGen/SwiftCallingConv.cpp|  2 +-
 clang/lib/CodeGen/Targets/LoongArch.cpp   |  2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  2 +-
 clang/lib/CodeGen/Targets/X86.cpp |  2 +-
 clang/lib/CodeGen/Targets/XCore.cpp   |  2 +-
 .../Frontend/Rewrite/RewriteModernObjC.cpp|  3 ++-
 clang/lib/Sema/SemaChecking.cpp   | 10 -
 clang/lib/Sema/SemaDecl.cpp   | 21 ++-
 clang/lib/Sema/SemaDeclCXX.cpp|  6 +++---
 clang/lib/Sema/SemaDeclObjC.cpp   |  3 +--
 clang/lib/Sema/SemaOverload.cpp   |  2 +-
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  2 +-
 clang/tools/libclang/CXType.cpp   |  2 +-
 clang/unittests/AST/ASTImporterTest.cpp   |  4 ++--
 38 files changed, 96 insertions(+), 94 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Timm Baeder (tbaederr)


Changes



---

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


40 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+1-1) 
- (modified) 
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(+1-1) 
- (modified) clang-tools-extra/clangd/Hover.cpp (+1-1) 
- (modified) clang/include/clang/AST/Decl.h (+4-2) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5-5) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+4-6) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+4-4) 
- (modified) clang/lib/AST/Decl.cpp (+11-5) 
- (modified) clang/lib/AST/DeclCXX.cpp (+1-1) 
- (modified) clang/lib/AST/Expr.cpp (+1-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1) 
- (modified) clang/lib/AST/Randstruct.cpp (+1-1) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+1-1) 
- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-5) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+10-10) 
- (modified) clang/lib/CodeGen/SwiftCallingConv.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/XCore.cpp (+1-1) 
- (modified) clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-5) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11-10) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+1-1) 
- (modified) clang/tools/libclang/CXType.cpp (+1-1) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-2) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp 
(+27-9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index a950704208c73b..408390ebc70b64 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
   assert(Node.isBitField());
   const ASTContext &Ctx = Node.getASTContext();
   unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
-  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  unsigned CurrentBitWidth = Node.getBitWidthValue();
   return IntBitWidth == CurrentBitWidth;
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index a73d46f01d9b2d..4ceeefb78ee824 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext 
&Context,
   unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
 
   if (const auto *BitField = IntExpr->getSourceBitField()) {
-unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
+unsigned BitFieldWidth = BitField->getBitWidthValue();
 return {BitFieldWidth - SignedBits, BitFieldWidth};
   }
 
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index 47dafca2d03ff0..7028c3958f103e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
 }
 if (const auto *BitfieldDecl =
 Result.Nodes.getNodeAs("bitfield")) {
-  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+  return twoPow(BitfieldDecl->getBitWidthValue());
 }
 
 return static_cast(0);
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 298fa79e3fd0ba..5e136d0e76ece7 100644
--- a/clang-tools-extra/clangd/Hover.cp

[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reapply "[clang] Avoid re-evaluating field bitwidth" (PR #122289)

2025-01-09 Thread Timm Baeder via lldb-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

@JDevlieghere The previous attempt made some lldb build bots fail. I've now 
changed `TypeSystemClang.cpp` to create `ConstantExpr`s for the bitwidth values 
and adapted one of the tests. Please review.

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-01-09 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,117 @@
+//===-- DILEval.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/ValueObject/DILEval.h"
+
+#include 
+
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "llvm/Support/FormatAdapters.h"
+
+namespace lldb_private {
+
+namespace dil {
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+   std::shared_ptr sm)
+: m_target(std::move(target)), m_sm(std::move(sm)) {
+  m_default_dynamic = lldb::eNoDynamicValues;
+}
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+   std::shared_ptr sm,
+   lldb::DynamicValueType use_dynamic)
+: m_target(std::move(target)), m_sm(std::move(sm)),
+  m_default_dynamic(use_dynamic) {}
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+   std::shared_ptr sm,
+   lldb::ValueObjectSP scope)
+: m_target(std::move(target)), m_sm(std::move(sm)),
+  m_scope(std::move(scope)) {
+  m_default_dynamic = lldb::eNoDynamicValues;
+  // If `m_scope` is a reference, dereference it. All operations on a reference
+  // should be operations on the referent.
+  if (m_scope->GetCompilerType().IsValid() &&
+  m_scope->GetCompilerType().IsReferenceType()) {
+Status error;
+m_scope = m_scope->Dereference(error);

labath wrote:

The function seems to think it can, though I haven't been able to make it do 
that (for a null reference it just returns an new ValueObject containing an 
error). So, ignoring the error *might* be okay here, but in that case it 
deserves an explanation. The existing callers generally seem to check this 
though...

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits

DavidSpickett wrote:

> have you posted rest of the patches for GCS other than this one?

https://github.com/DavidSpickett/llvm-project/commits/gcs-work/ has all the 
patches but I was avoiding doing stacked PRs. I can figure that out if it'd 
help you review.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -101,12 +105,13 @@ class MemoryRegionInfo {
   bool operator==(const MemoryRegionInfo &rhs) const {
 return m_range == rhs.m_range && m_read == rhs.m_read &&
m_write == rhs.m_write && m_execute == rhs.m_execute &&
-   m_shared == rhs.m_shared &&
-   m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
-   m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
+   m_shared == rhs.m_shared && m_mapped == rhs.m_mapped &&

DavidSpickett wrote:

Probably clang-format, I will push something directly and rebase this.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -164,12 +164,17 @@ void lldb_private::ParseLinuxSMapRegions(llvm::StringRef 
linux_smap,
 if (!name.contains(' ')) {
   if (region) {
 if (name == "VmFlags") {
-  if (value.contains("mt"))
-region->SetMemoryTagged(MemoryRegionInfo::eYes);
-  else
-region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetIsShadowStack(MemoryRegionInfo::eNo);
+
+  llvm::SmallVector flags;
+  value.split(flags, ' ', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+  for (llvm::StringRef flag : flags)

DavidSpickett wrote:

The line we are parsing looks like:
```
VmFlags: rd ex mr mw me de sd
```
And I wouldn't want to see "amtb" and assume that memory tagging is set. We 
could do `contains(" mt ")` buy relying on that trailing space being there is 
risky.

It would be nice to be lazy and only tokenise as much as we need from the 
string though. I'll see if there's an iterator version I can use.

You made me realise I don't actually have a test case to check we don't match 
on substrings though, so I will add that.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -164,12 +164,17 @@ void lldb_private::ParseLinuxSMapRegions(llvm::StringRef 
linux_smap,
 if (!name.contains(' ')) {
   if (region) {
 if (name == "VmFlags") {
-  if (value.contains("mt"))
-region->SetMemoryTagged(MemoryRegionInfo::eYes);
-  else
-region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetMemoryTagged(MemoryRegionInfo::eNo);
+  region->SetIsShadowStack(MemoryRegionInfo::eNo);
+
+  llvm::SmallVector flags;
+  value.split(flags, ' ', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+  for (llvm::StringRef flag : flags)

DavidSpickett wrote:

Current flags are only two characters, but again, risky to assume that will 
continue.

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add Function::GetAddress and redirect some uses (PR #115836)

2025-01-09 Thread Pavel Labath via lldb-commits

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

>From 3053907387634c8b0be9667441535828b034a3db Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 12 Nov 2024 10:17:42 +0100
Subject: [PATCH] [lldb] Add Function::GetAddress and redirect some uses

Many calls to Function::GetAddressRange() were not interested in the
range itself. Instead they wanted to find the address of the function
(its entry point) or the base address for relocation of function-scoped
entities. This PR creates a separate function for retrieving this, and
changes the existing (non-controversial) uses to call that instead.
---
 lldb/include/lldb/Symbol/Function.h   |  8 
 lldb/source/API/SBBlock.cpp   |  3 +--
 lldb/source/API/SBFunction.cpp|  3 +--
 lldb/source/Breakpoint/BreakpointResolver.cpp |  2 +-
 lldb/source/Breakpoint/BreakpointResolverName.cpp |  2 +-
 lldb/source/Core/SearchFilter.cpp |  2 +-
 lldb/source/Expression/DWARFExpressionList.cpp|  3 +--
 lldb/source/Expression/IRExecutionUnit.cpp|  3 +--
 .../Architecture/Mips/ArchitectureMips.cpp|  2 +-
 .../MacOSX-DYLD/DynamicLoaderDarwin.cpp   |  6 ++
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp |  3 +--
 .../Clang/ClangExpressionDeclMap.cpp  |  2 +-
 .../SymbolFile/Breakpad/SymbolFileBreakpad.cpp|  4 ++--
 .../SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp  |  3 +--
 .../SymbolFile/NativePDB/SymbolFileNativePDB.cpp  | 12 
 lldb/source/Symbol/Block.cpp  | 14 ++
 lldb/source/Symbol/Function.cpp   | 15 +++
 lldb/source/Symbol/SymbolContext.cpp  | 10 +++---
 lldb/source/Symbol/Variable.cpp   |  8 +++-
 lldb/source/Target/StackFrame.cpp |  3 +--
 lldb/source/Target/ThreadPlanStepInRange.cpp  |  2 +-
 lldb/source/ValueObject/ValueObjectVariable.cpp   |  3 +--
 22 files changed, 49 insertions(+), 64 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index e4118c1f9be867..157c007bdf0e84 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -449,6 +449,11 @@ class Function : public UserID, public SymbolContextScope {
 
   AddressRanges GetAddressRanges() { return m_block.GetRanges(); }
 
+  /// Return the address of the function (its entry point). This address is 
also
+  /// used as a base address for relocation of function-scope entities (blocks
+  /// and variables).
+  const Address &GetAddress() const { return m_address; }
+
   lldb::LanguageType GetLanguage() const;
   /// Find the file and line number of the source location of the start of the
   /// function.  This will use the declaration if present and fall back on the
@@ -658,6 +663,9 @@ class Function : public UserID, public SymbolContextScope {
   /// include addresses belonging to other functions.
   AddressRange m_range;
 
+  /// The address (entry point) of the function.
+  Address m_address;
+
   /// The frame base expression for variables that are relative to the frame
   /// pointer.
   DWARFExpressionList m_frame_base;
diff --git a/lldb/source/API/SBBlock.cpp b/lldb/source/API/SBBlock.cpp
index b921ccd9802454..2ef4cc7227cf95 100644
--- a/lldb/source/API/SBBlock.cpp
+++ b/lldb/source/API/SBBlock.cpp
@@ -176,8 +176,7 @@ bool SBBlock::GetDescription(SBStream &description) {
 m_opaque_ptr->CalculateSymbolContext(&sc);
 if (sc.function) {
   m_opaque_ptr->DumpAddressRanges(
-  &strm,
-  sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
+  &strm, sc.function->GetAddress().GetFileAddress());
 }
   } else
 strm.PutCString("No value");
diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp
index 3f6b4eea983187..414eccc357c0e4 100644
--- a/lldb/source/API/SBFunction.cpp
+++ b/lldb/source/API/SBFunction.cpp
@@ -120,8 +120,7 @@ SBInstructionList SBFunction::GetInstructions(SBTarget 
target,
   if (m_opaque_ptr) {
 TargetSP target_sp(target.GetSP());
 std::unique_lock lock;
-ModuleSP module_sp(
-m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
+ModuleSP module_sp(m_opaque_ptr->GetAddress().GetModule());
 if (target_sp && module_sp) {
   lock = std::unique_lock(target_sp->GetAPIMutex());
   const bool force_live_memory = true;
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp 
b/lldb/source/Breakpoint/BreakpointResolver.cpp
index 9643602d78c751..5fe544908c39e2 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -325,7 +325,7 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
   // If the line number is before the prologue end, move it there...
   bool skipped_prologue = false;
   if (skip_prologue && sc.function) {
-Address prologue_

[Lldb-commits] [lldb] [lldb] Add Function::GetAddress and redirect some uses (PR #115836)

2025-01-09 Thread Pavel Labath via lldb-commits


@@ -407,6 +406,15 @@ CompileUnit *Function::GetCompileUnit() { return 
m_comp_unit; }
 
 const CompileUnit *Function::GetCompileUnit() const { return m_comp_unit; }
 
+Address Function::GetAddress() const {
+  if (m_ranges.empty())
+return Address();
+  // We're using a (DWARF-like) convention where the base address of the first
+  // interval denotes the entry point of the function. If that turns out to be
+  // insufficient, we can introduce a separate "entry point address" field.
+  return m_ranges[0].GetBaseAddress();

labath wrote:

Finally got back to this. The main change is that the Function class now has a 
separate member for the function address. Right now it's still the lowest 
function address, but in the next patch I'll change it to pass the function 
address explicitly (and independently of the sorted ranges of the function).

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


[Lldb-commits] [lldb] [lldb] Add Function::GetAddress and redirect some uses (PR #115836)

2025-01-09 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)

2025-01-09 Thread via lldb-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/120664

>From 7e56f86ec79865de0c2bc49ffa3f9f2b17a6f36f Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Fri, 20 Dec 2024 09:10:10 +0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 ...NativeRegisterContextLinux_loongarch64.cpp | 168 ++
 .../NativeRegisterContextLinux_loongarch64.h  |  21 ++-
 .../RegisterContextPOSIX_loongarch64.cpp  |  10 ++
 .../RegisterContextPOSIX_loongarch64.h|   8 +
 .../Utility/RegisterInfoPOSIX_loongarch64.cpp |  63 ++-
 .../Utility/RegisterInfoPOSIX_loongarch64.h   |  12 ++
 .../Utility/RegisterInfos_loongarch64.h   |  89 ++
 .../Utility/lldb-loongarch-register-enums.h   |  70 
 .../RegisterContextPOSIXCore_loongarch64.cpp  |  14 ++
 .../RegisterContextPOSIXCore_loongarch64.h|   8 +
 .../Utility/LoongArch_DWARF_Registers.h   |  66 +++
 11 files changed, 525 insertions(+), 4 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
index 9ffc8ada920cb8..2eeea46f7f6836 100644
--- 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
+++ 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
@@ -27,6 +27,14 @@
 // struct iovec definition
 #include 
 
+#ifndef NT_LARCH_LSX
+#define NT_LARCH_LSX 0xa02 /* LoongArch SIMD eXtension registers */
+#endif
+
+#ifndef NT_LARCH_LASX
+#define NT_LARCH_LASX 0xa03 /* LoongArch Advanced SIMD eXtension registers */
+#endif
+
 #define REG_CONTEXT_SIZE (GetGPRSize() + GetFPRSize())
 
 using namespace lldb;
@@ -62,6 +70,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
   NativeRegisterContextLinux(native_thread) {
   ::memset(&m_fpr, 0, sizeof(m_fpr));
   ::memset(&m_gpr, 0, sizeof(m_gpr));
+  ::memset(&m_lsx, 0, sizeof(m_lsx));
+  ::memset(&m_lasx, 0, sizeof(m_lasx));
 
   ::memset(&m_hwp_regs, 0, sizeof(m_hwp_regs));
   ::memset(&m_hbp_regs, 0, sizeof(m_hbp_regs));
@@ -75,6 +85,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
 
   m_gpr_is_valid = false;
   m_fpu_is_valid = false;
+  m_lsx_is_valid = false;
+  m_lasx_is_valid = false;
 }
 
 const RegisterInfoPOSIX_loongarch64 &
@@ -135,6 +147,22 @@ Status 
NativeRegisterContextLinux_loongarch64::ReadRegister(
 offset = CalculateFprOffset(reg_info);
 assert(offset < GetFPRSize());
 src = (uint8_t *)GetFPRBuffer() + offset;
+  } else if (IsLSX(reg)) {
+error = ReadLSX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLsxOffset(reg_info);
+assert(offset < sizeof(m_lsx));
+src = (uint8_t *)&m_lsx + offset;
+  } else if (IsLASX(reg)) {
+error = ReadLASX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLasxOffset(reg_info);
+assert(offset < sizeof(m_lasx));
+src = (uint8_t *)&m_lasx + offset;
   } else
 return Status::FromErrorString(
 "failed - register wasn't recognized to be a GPR or an FPR, "
@@ -184,6 +212,28 @@ Status 
NativeRegisterContextLinux_loongarch64::WriteRegister(
 ::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
 
 return WriteFPR();
+  } else if (IsLSX(reg)) {
+error = ReadLSX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLsxOffset(reg_info);
+assert(offset < sizeof(m_lsx));
+dst = (uint8_t *)&m_lsx + offset;
+::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
+
+return WriteLSX();
+  } else if (IsLASX(reg)) {
+error = ReadLASX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLasxOffset(reg_info);
+assert(offset < sizeof(m_lasx));
+dst = (uint8_t *)&m_lasx + offset;
+::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
+
+return WriteLASX();
   }
 
   return Status::FromErrorString("Failed to write register value");
@@ -203,10 +253,22 @@ Status 
NativeRegisterContextLinux_loongarch64::ReadAllRegisterValues(
   if (error.Fail())
 return error;
 
+  error = ReadLSX();
+  if (error.Fail())
+return error;
+
+  error = ReadLASX();
+  if (error.Fail())
+return error;
+
   uint8_t *dst = data_sp->GetBytes();
   ::memcpy(dst, GetGPRBuffer(), GetGPRSize());
   dst += GetGPRSize();
   ::memcpy(dst, GetFPRBuffer(), GetFPRSize());
+  dst += GetFPRSize();
+  ::memcpy(dst, &m_lsx, sizeof(m_lsx));
+  dst += sizeof(m_lsx);
+  ::memcpy(dst, &m_lasx, sizeof(m_lasx));
 
   return error;
 }
@@ -252,6 +314,20 @@ Status 
NativeRegisterContextLinux_loongarch64::WriteAllRegisterValues(
   if (error.Fail())
 return error;
 
+  src += GetFPRSize();
+  ::memcpy(&m_lsx, src, sizeof(m_lsx));
+
+  error = WriteLSX();
+  i

[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)

2025-01-09 Thread via lldb-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/120664

>From 7e56f86ec79865de0c2bc49ffa3f9f2b17a6f36f Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Fri, 20 Dec 2024 09:10:10 +0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 ...NativeRegisterContextLinux_loongarch64.cpp | 168 ++
 .../NativeRegisterContextLinux_loongarch64.h  |  21 ++-
 .../RegisterContextPOSIX_loongarch64.cpp  |  10 ++
 .../RegisterContextPOSIX_loongarch64.h|   8 +
 .../Utility/RegisterInfoPOSIX_loongarch64.cpp |  63 ++-
 .../Utility/RegisterInfoPOSIX_loongarch64.h   |  12 ++
 .../Utility/RegisterInfos_loongarch64.h   |  89 ++
 .../Utility/lldb-loongarch-register-enums.h   |  70 
 .../RegisterContextPOSIXCore_loongarch64.cpp  |  14 ++
 .../RegisterContextPOSIXCore_loongarch64.h|   8 +
 .../Utility/LoongArch_DWARF_Registers.h   |  66 +++
 11 files changed, 525 insertions(+), 4 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
index 9ffc8ada920cb8..2eeea46f7f6836 100644
--- 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
+++ 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
@@ -27,6 +27,14 @@
 // struct iovec definition
 #include 
 
+#ifndef NT_LARCH_LSX
+#define NT_LARCH_LSX 0xa02 /* LoongArch SIMD eXtension registers */
+#endif
+
+#ifndef NT_LARCH_LASX
+#define NT_LARCH_LASX 0xa03 /* LoongArch Advanced SIMD eXtension registers */
+#endif
+
 #define REG_CONTEXT_SIZE (GetGPRSize() + GetFPRSize())
 
 using namespace lldb;
@@ -62,6 +70,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
   NativeRegisterContextLinux(native_thread) {
   ::memset(&m_fpr, 0, sizeof(m_fpr));
   ::memset(&m_gpr, 0, sizeof(m_gpr));
+  ::memset(&m_lsx, 0, sizeof(m_lsx));
+  ::memset(&m_lasx, 0, sizeof(m_lasx));
 
   ::memset(&m_hwp_regs, 0, sizeof(m_hwp_regs));
   ::memset(&m_hbp_regs, 0, sizeof(m_hbp_regs));
@@ -75,6 +85,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
 
   m_gpr_is_valid = false;
   m_fpu_is_valid = false;
+  m_lsx_is_valid = false;
+  m_lasx_is_valid = false;
 }
 
 const RegisterInfoPOSIX_loongarch64 &
@@ -135,6 +147,22 @@ Status 
NativeRegisterContextLinux_loongarch64::ReadRegister(
 offset = CalculateFprOffset(reg_info);
 assert(offset < GetFPRSize());
 src = (uint8_t *)GetFPRBuffer() + offset;
+  } else if (IsLSX(reg)) {
+error = ReadLSX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLsxOffset(reg_info);
+assert(offset < sizeof(m_lsx));
+src = (uint8_t *)&m_lsx + offset;
+  } else if (IsLASX(reg)) {
+error = ReadLASX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLasxOffset(reg_info);
+assert(offset < sizeof(m_lasx));
+src = (uint8_t *)&m_lasx + offset;
   } else
 return Status::FromErrorString(
 "failed - register wasn't recognized to be a GPR or an FPR, "
@@ -184,6 +212,28 @@ Status 
NativeRegisterContextLinux_loongarch64::WriteRegister(
 ::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
 
 return WriteFPR();
+  } else if (IsLSX(reg)) {
+error = ReadLSX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLsxOffset(reg_info);
+assert(offset < sizeof(m_lsx));
+dst = (uint8_t *)&m_lsx + offset;
+::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
+
+return WriteLSX();
+  } else if (IsLASX(reg)) {
+error = ReadLASX();
+if (error.Fail())
+  return error;
+
+offset = CalculateLasxOffset(reg_info);
+assert(offset < sizeof(m_lasx));
+dst = (uint8_t *)&m_lasx + offset;
+::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
+
+return WriteLASX();
   }
 
   return Status::FromErrorString("Failed to write register value");
@@ -203,10 +253,22 @@ Status 
NativeRegisterContextLinux_loongarch64::ReadAllRegisterValues(
   if (error.Fail())
 return error;
 
+  error = ReadLSX();
+  if (error.Fail())
+return error;
+
+  error = ReadLASX();
+  if (error.Fail())
+return error;
+
   uint8_t *dst = data_sp->GetBytes();
   ::memcpy(dst, GetGPRBuffer(), GetGPRSize());
   dst += GetGPRSize();
   ::memcpy(dst, GetFPRBuffer(), GetFPRSize());
+  dst += GetFPRSize();
+  ::memcpy(dst, &m_lsx, sizeof(m_lsx));
+  dst += sizeof(m_lsx);
+  ::memcpy(dst, &m_lasx, sizeof(m_lasx));
 
   return error;
 }
@@ -252,6 +314,20 @@ Status 
NativeRegisterContextLinux_loongarch64::WriteAllRegisterValues(
   if (error.Fail())
 return error;
 
+  src += GetFPRSize();
+  ::memcpy(&m_lsx, src, sizeof(m_lsx));
+
+  error = WriteLSX();
+  i

[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)

2025-01-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 
5ae44bf718a460a2d5fd3636c8182093e1e27e7a...bdba932eb0aa30cac5a1e24dbe4074406f684605
 
lldb/test/API/linux/loongarch64/lasx_registers/TestLoongArch64LinuxLASXRegisters.py
 
lldb/test/API/linux/loongarch64/lsx_registers/TestLoongArch64LinuxLSXRegisters.py
 lldb/packages/Python/lldbsuite/test/lldbtest.py
``





View the diff from darker here.


``diff
--- 
test/API/linux/loongarch64/lasx_registers/TestLoongArch64LinuxLASXRegisters.py  
2025-01-09 12:01:34.00 +
+++ 
test/API/linux/loongarch64/lasx_registers/TestLoongArch64LinuxLASXRegisters.py  
2025-01-09 12:04:56.469705 +
@@ -10,11 +10,11 @@
 
 class LoongArch64LinuxRegisters(TestBase):
 NO_DEBUG_INFO_TESTCASE = True
 
 def make_lasx_value(self, n):
-return "{" + " ".join(["0x{:02x}".format(n)] * 32) + "}" 
+return "{" + " ".join(["0x{:02x}".format(n)] * 32) + "}"
 
 def check_lasx_values(self, value_offset):
 for i in range(32):
 self.expect(
 "register read xr{}".format(i),
--- 
test/API/linux/loongarch64/lsx_registers/TestLoongArch64LinuxLSXRegisters.py
2025-01-09 12:01:34.00 +
+++ 
test/API/linux/loongarch64/lsx_registers/TestLoongArch64LinuxLSXRegisters.py
2025-01-09 12:04:56.491760 +
@@ -10,11 +10,11 @@
 
 class LoongArch64LinuxRegisters(TestBase):
 NO_DEBUG_INFO_TESTCASE = True
 
 def make_lsx_value(self, n):
-return "{" + " ".join(["0x{:02x}".format(n)] * 16) + "}" 
+return "{" + " ".join(["0x{:02x}".format(n)] * 16) + "}"
 
 def check_lsx_values(self, value_offset):
 for i in range(32):
 self.expect(
 "register read vr{}".format(i),

``




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


[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)

2025-01-09 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Move GetEnvironment function into common code (PR #122173)

2025-01-09 Thread Brad Smith via lldb-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/122173

>From d6663bdbf2a7cdf0c8289573cf9caefc15f7338f Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Wed, 8 Jan 2025 16:23:11 -0500
Subject: [PATCH] [lldb] Move GetEnvironment function into common code

---
 lldb/source/Host/common/Host.cpp   | 4 
 lldb/source/Host/freebsd/Host.cpp  | 6 --
 lldb/source/Host/linux/Host.cpp| 2 --
 lldb/source/Host/netbsd/HostNetBSD.cpp | 6 --
 lldb/source/Host/openbsd/Host.cpp  | 6 --
 5 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 03ea2f242d3c78..7b2bae74e196fe 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -114,6 +114,10 @@ void LogChannelSystem::Initialize() {
 void LogChannelSystem::Terminate() { g_system_log.Disable(); }
 
 #if !defined(__APPLE__) && !defined(_WIN32)
+extern "C" char **environ;
+
+Environment Host::GetEnvironment() { return Environment(environ); }
+
 static thread_result_t
 MonitorChildProcessThreadFunction(::pid_t pid,
   Host::MonitorChildProcessCallback callback);
diff --git a/lldb/source/Host/freebsd/Host.cpp 
b/lldb/source/Host/freebsd/Host.cpp
index 89ebe714f095f8..14c0e9f2209d24 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -33,10 +33,6 @@
 
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 namespace lldb_private {
 class ProcessLaunchInfo;
 }
@@ -241,8 +237,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, 
ProcessInstanceInfo &process_info) {
   return false;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
   return Status::FromErrorString("unimplemented");
 }
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index f5ec2e187af196..25bef9b0e7151b 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -411,8 +411,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, 
ProcessInstanceInfo &process_info) {
   return GetProcessAndStatInfo(pid, process_info, State, tracerpid);
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
   return Status::FromErrorString("unimplemented");
 }
diff --git a/lldb/source/Host/netbsd/HostNetBSD.cpp 
b/lldb/source/Host/netbsd/HostNetBSD.cpp
index 49ff342fe152f6..8904df5eba03eb 100644
--- a/lldb/source/Host/netbsd/HostNetBSD.cpp
+++ b/lldb/source/Host/netbsd/HostNetBSD.cpp
@@ -35,10 +35,6 @@
 #include "llvm/Object/ELF.h"
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -46,8 +42,6 @@ namespace lldb_private {
 class ProcessLaunchInfo;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch 
*match_info_ptr,
  ProcessInstanceInfo &process_info) {
   if (!process_info.ProcessIDIsValid())
diff --git a/lldb/source/Host/openbsd/Host.cpp 
b/lldb/source/Host/openbsd/Host.cpp
index 24650ff97075ea..2b66a3c8696b10 100644
--- a/lldb/source/Host/openbsd/Host.cpp
+++ b/lldb/source/Host/openbsd/Host.cpp
@@ -30,10 +30,6 @@
 
 #include "llvm/TargetParser/Host.h"
 
-extern "C" {
-extern char **environ;
-}
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -41,8 +37,6 @@ namespace lldb_private {
 class ProcessLaunchInfo;
 }
 
-Environment Host::GetEnvironment() { return Environment(environ); }
-
 static bool
 GetOpenBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
   ProcessInstanceInfo &process_info) {

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


[Lldb-commits] [lldb] [lldb][AIX] Added support for AIX in HostInfo section (PR #122301)

2025-01-09 Thread David Spickett via lldb-commits

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

LGTM.

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


[Lldb-commits] [clang] [lldb] [clang][DebugInfo] Expand detection of structured bindings to account for std::get free function (PR #122265)

2025-01-09 Thread via lldb-commits

cor3ntin wrote:

Did you try to modify `IgnoreUnlessSpelledInSource`  to support CallExpr?

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


[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -2796,11 +2796,17 @@ 
GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
 // Flags
 MemoryRegionInfo::OptionalBool memory_tagged =
 region_info.GetMemoryTagged();
-if (memory_tagged != MemoryRegionInfo::eDontKnow) {
+MemoryRegionInfo::OptionalBool is_shadow_stack =
+region_info.IsShadowStack();
+
+if (memory_tagged != MemoryRegionInfo::eDontKnow ||
+is_shadow_stack != MemoryRegionInfo::eDontKnow) {
   response.PutCString("flags:");
-  if (memory_tagged == MemoryRegionInfo::eYes) {
+  if (memory_tagged == MemoryRegionInfo::eYes)
 response.PutCString("mt");
-  }
+  if (is_shadow_stack == MemoryRegionInfo::eYes)

DavidSpickett wrote:

Yes!

I will fix this but I don't think I will be able to test it because the shadow 
stack mapping is done by the kernel and it won't enable memory tagging.

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


[Lldb-commits] [lldb] [lldb][Docs] Add Guarded Control Stack to AArch64 Linux page (PR #117860)

2025-01-09 Thread David Spickett via lldb-commits

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

>From 4838ed0ef8a62041981e61a8d405251bb32c147d Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Tue, 27 Aug 2024 15:22:10 +0100
Subject: [PATCH 1/3] [lldb][Docs] Add Guarded Control Stack to AArch64 Linux
 page

The meat of this is how we execute expressions and deal with the
aftermath. For most users this will never be a concern, so it
functions more as a design doc than anything else.
---
 lldb/docs/use/aarch64-linux.md | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/lldb/docs/use/aarch64-linux.md b/lldb/docs/use/aarch64-linux.md
index 393838dc0bb4f5..425336ddd81e2f 100644
--- a/lldb/docs/use/aarch64-linux.md
+++ b/lldb/docs/use/aarch64-linux.md
@@ -229,3 +229,54 @@ bytes.
 
 `zt0`'s value and whether it is active or not will be saved prior to
 expression evaluation and restored afterwards.
+
+## Guarded Control Stack Extension (GCS)
+
+GCS support includes the following new registers:
+
+* `gcs_features_enabled`
+* `gcs_features_locked`
+* `gcspr_el0`
+
+These map to the registers ptrace provides. The first two have had a `gcs_`
+prefix added as their names are too generic without it.
+
+When the GCS is enabled the kernel allocates a memory region for it. This 
region
+has a special attribute that LLDB will detect and presents like this:
+```
+  (lldb) memory region --all
+  <...>
+  [0xf7a0-0xf7e0) rw-
+  shadow stack: yes
+  [0xf7e0-0xf7e1) ---
+```
+
+`shadow stack` is a generic term used in the kernel for secure stack
+extensions like GCS.
+
+### Expression Evaluation
+
+To execute an expression, LLDB must push the return address of the expression
+wrapper (usually the entry point of the program) to the Guarded Control Stack.
+It does this by decrementing `gcspr_el0` and writing to the location that
+`gcspr_el0` then points to (instead of using the GCS push instructions).
+
+After an expression finishes, LLDB will restore the contents of all 3 
registers,
+apart from the enable bit of `gcs_features_enabled`.
+
+This is because there are limits on how often and from where you can set this
+value. We cannot enable GCS from ptrace at all and it is expected that a 
process
+that has enabled GCS then disabled it, will not enable it again. The simplest
+choice was to not restore the enable bit at all. It's up to the user or
+program to manage that value.
+
+The return address that was pushed onto the Guarded Control Stack will be left
+in place. As will any values that were pushed to the stack by functions run
+during the expresison.
+
+When the process resumes, `gcspr_el0` will be pointing to the original entry
+on the stack. So the other values will have no effect and likely be overwritten
+by future function calls.
+
+LLDB does not track and restore changes to general memory during expressions,
+so not restoring the GCS contents fits with the current behaviour.

>From 4916c3c3aa74eb586d4b70792922fb12d4021dae Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 11 Dec 2024 13:57:16 +
Subject: [PATCH 2/3] Address Omair's comments

---
 lldb/docs/use/aarch64-linux.md | 40 +-
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/lldb/docs/use/aarch64-linux.md b/lldb/docs/use/aarch64-linux.md
index 425336ddd81e2f..7c6157ce9df2af 100644
--- a/lldb/docs/use/aarch64-linux.md
+++ b/lldb/docs/use/aarch64-linux.md
@@ -256,27 +256,37 @@ extensions like GCS.
 
 ### Expression Evaluation
 
-To execute an expression, LLDB must push the return address of the expression
-wrapper (usually the entry point of the program) to the Guarded Control Stack.
-It does this by decrementing `gcspr_el0` and writing to the location that
-`gcspr_el0` then points to (instead of using the GCS push instructions).
-
-After an expression finishes, LLDB will restore the contents of all 3 
registers,
-apart from the enable bit of `gcs_features_enabled`.
-
-This is because there are limits on how often and from where you can set this
-value. We cannot enable GCS from ptrace at all and it is expected that a 
process
+To execute an expression when GCS is enabled, LLDB must push the return
+address of the expression wrapper (usually the entry point of the program)
+to the Guarded Control Stack. It does this by decrementing `gcspr_el0` and
+writing to the location now pointed to by `gcspr_el0` (instead of using the
+GCS push instructions).
+
+After an expression finishes, LLDB will restore the contents of all 3
+GCS registers, apart from the enable bit of `gcs_features_enabled`. This is
+because there are limits on how often and from where you can set this
+bit.
+
+We cannot enable GCS from ptrace at all and it is expected that a process
 that has enabled GCS then disabled it, will not enable it again. The simplest
-choice was to not restore the enable bit at all. It's up to the user or
-program to manage that val

[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

2025-01-09 Thread David Spickett via lldb-commits


@@ -2796,11 +2796,17 @@ 
GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
 // Flags
 MemoryRegionInfo::OptionalBool memory_tagged =
 region_info.GetMemoryTagged();
-if (memory_tagged != MemoryRegionInfo::eDontKnow) {
+MemoryRegionInfo::OptionalBool is_shadow_stack =
+region_info.IsShadowStack();
+
+if (memory_tagged != MemoryRegionInfo::eDontKnow ||
+is_shadow_stack != MemoryRegionInfo::eDontKnow) {
   response.PutCString("flags:");
-  if (memory_tagged == MemoryRegionInfo::eYes) {
+  if (memory_tagged == MemoryRegionInfo::eYes)
 response.PutCString("mt");
-  }
+  if (is_shadow_stack == MemoryRegionInfo::eYes)

DavidSpickett wrote:

We're expecting at least one space between flags, according to the packet tests 
below.

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


[Lldb-commits] [lldb] [lldb] Regularize DWARFDIE::Get{TypeLookup, Decl}Context names (PR #122273)

2025-01-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

The functions call GetName for everything except variables, where they call 
GetPubname instead. The difference is that the latter prefers to return the 
linkage name, if it is available.

This doesn't seem particularly useful given that the linkage name already kind 
of contains the context of the variable, and I doubt that anything depends on 
it as these functions are currently called on type and subprogram DIEs -- not 
variables.

This makes it easier to simplify/deduplicate these functions later.

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


1 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (+2-2) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index 96b13efe583513..4b864b549f8ce6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -412,7 +412,7 @@ static void GetDeclContextImpl(DWARFDIE die,
   push_ctx(CompilerContextKind::Function, die.GetName());
   break;
 case DW_TAG_variable:
-  push_ctx(CompilerContextKind::Variable, die.GetPubname());
+  push_ctx(CompilerContextKind::Variable, die.GetName());
   break;
 case DW_TAG_typedef:
   push_ctx(CompilerContextKind::Typedef, die.GetName());
@@ -457,7 +457,7 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
   push_ctx(CompilerContextKind::Enum, die.GetName());
   break;
 case DW_TAG_variable:
-  push_ctx(CompilerContextKind::Variable, die.GetPubname());
+  push_ctx(CompilerContextKind::Variable, die.GetName());
   break;
 case DW_TAG_typedef:
   push_ctx(CompilerContextKind::Typedef, die.GetName());

``




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


[Lldb-commits] [lldb] [lldb] Regularize DWARFDIE::Get{TypeLookup, Decl}Context names (PR #122273)

2025-01-09 Thread Pavel Labath via lldb-commits

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

The functions call GetName for everything except variables, where they call 
GetPubname instead. The difference is that the latter prefers to return the 
linkage name, if it is available.

This doesn't seem particularly useful given that the linkage name already kind 
of contains the context of the variable, and I doubt that anything depends on 
it as these functions are currently called on type and subprogram DIEs -- not 
variables.

This makes it easier to simplify/deduplicate these functions later.

>From c65e70faf378998a53a5ad645dbae2353bf251a5 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 9 Jan 2025 14:18:39 +0100
Subject: [PATCH] [lldb] Regularize DWARFDIE::Get{TypeLookup,Decl}Context names

The functions call GetName for everything except variables, where they
call GetPubname instead. The difference is that the latter prefers to
return the linkage name, if it is available.

This doesn't seem particularly useful given that the linkage name
already kind of contains the context of the variable, and I doubt that
anything depends on it as these functions are currently called on type
and subprogram DIEs -- not variables.

This makes it easier to simplify/deduplicate these functions later.
---
 lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index 96b13efe583513..4b864b549f8ce6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -412,7 +412,7 @@ static void GetDeclContextImpl(DWARFDIE die,
   push_ctx(CompilerContextKind::Function, die.GetName());
   break;
 case DW_TAG_variable:
-  push_ctx(CompilerContextKind::Variable, die.GetPubname());
+  push_ctx(CompilerContextKind::Variable, die.GetName());
   break;
 case DW_TAG_typedef:
   push_ctx(CompilerContextKind::Typedef, die.GetName());
@@ -457,7 +457,7 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
   push_ctx(CompilerContextKind::Enum, die.GetName());
   break;
 case DW_TAG_variable:
-  push_ctx(CompilerContextKind::Variable, die.GetPubname());
+  push_ctx(CompilerContextKind::Variable, die.GetName());
   break;
 case DW_TAG_typedef:
   push_ctx(CompilerContextKind::Typedef, die.GetName());

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


[Lldb-commits] [clang] [lldb] [clang][DebugInfo] Expand detection of structured bindings to account for std::get free function (PR #122265)

2025-01-09 Thread Michael Buch via lldb-commits

Michael137 wrote:

> Did you try to modify `IgnoreUnlessSpelledInSource` to support CallExpr?

Yea I was thinking about it initially. But I wasn't sure what that would look 
like tbh. IIUC `IgnoreImplicitMemberCallSingleStep` will unwrap 
`CXXMemberCallExpr` into the underlying `MemberExpr`. And then further until we 
hit the implicit object argument? But what would we do with `CallExpr`s? Do we 
return the `CalleeDecl`? In our use-case, the `Decomposition` decl is the first 
argument of the `CallExpr`.

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


[Lldb-commits] [clang] [lldb] [clang][DebugInfo] Expand detection of structured bindings to account for std::get free function (PR #122265)

2025-01-09 Thread Michael Buch via lldb-commits

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

>From f56f9469e5465f38f6252b2c8c2136473187969b Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 9 Jan 2025 10:01:31 +
Subject: [PATCH 1/3] [clang][DebugInfo] Expand detection of structured
 bindings to account for std::get free function

When we generate the debug-info for a `VarDecl` we try
to determine whether it was introduced as part of a structure
binding (aka a "holding var"). If it was,
we don't mark it as `artificial`.

The heuristic to determine a holding var uses
`IgnoreUnlessSpelledInSource` to unwrap the `VarDecl` initializer
until we hit a `DeclRefExpr` that refers to a `Decomposition`.
For "tuple-like decompositions", Clang will generate a call to
a `template Foo get(Bar)` function that retrieves the
`Ith` element from the tuple-like structure. If that function is a
member function, we get an AST that looks as follows:
```
VarDecl implicit used z1 'std::tuple_element<0, B>::type &&' cinit
`-ExprWithCleanups  'int' xvalue
  `-MaterializeTemporaryExpr  'int' xvalue extended by Var 0x11d110cf8 
'z1' 'std::tuple_element<0, B>::type &&'
`-CXXMemberCallExpr  'int'
  `-MemberExpr  '' .get 0x11d104390
`-ImplicitCastExpr  'B' xvalue 
  `-DeclRefExpr  'B' lvalue Decomposition 0x11d1100a8 '' 'B'
```
`IgnoreUnlessSpelledInSource` happily unwraps this down to the
`DeclRefExpr`. However, when the `get` helper is a free function
(which it is for `std::pair` in libc++ for example), then the AST
is:
```
VarDecl col:16 implicit used k 'std::tuple_element<0, const std::tuple>::type &' cinit
`-CallExpr  'const typename tuple_element<0UL, tuple>::type':'const int' lvalue adl
  |-ImplicitCastExpr  'const typename tuple_element<0UL, tuple>::type &(*)(const tuple &) noexcept' 
  | `-DeclRefExpr  'const typename tuple_element<0UL, tuple>::type &(const tuple &) noexcept' lvalue Function 0x1210262d8 
'get' 'const typename tuple_element<0UL, tuple>::type &(const 
tuple &) noexcept' (FunctionTemplate 0x11d068088 'get')
  `-DeclRefExpr  'const std::tuple' lvalue Decomposition 
0x121021518 '' 'const std::tuple &'
```
`IgnoreUnlessSpelledInSource` doesn't unwrap this `CallExpr`, so we
incorrectly mark the binding as `artificial` in debug-info.

This patch adjusts our heuristic to account for `CallExpr` nodes.

Fixes https://github.com/llvm/llvm-project/issues/122028
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 28 ++-
 .../debug-info-structured-binding.cpp | 28 ++-
 .../TestStructuredBinding.py  | 11 +++
 .../API/lang/cpp/structured-binding/main.cpp  | 81 +--
 4 files changed, 140 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 560d4ce293365e..e0fdde460c8758 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -85,12 +85,38 @@ static bool IsDecomposedVarDecl(VarDecl const *VD) {
   if (!Init)
 return false;
 
+  Init = Init->IgnoreUnlessSpelledInSource();
+  if (!Init)
+return false;
+
+  // For tuple-like decompositions, if the `get` function
+  // is not a member of the decomposed type, but instead a
+  // free function (e.g., how std::get is specialized for
+  // std::pair), then the initializer is a `CallExpr` and
+  // we need to dig into the argument before unwrapping it
+  // with IgnoreUnlessSpelledInSource.
+  if (auto const *CE = llvm::dyn_cast(Init)) {
+if (CE->getNumArgs() == 0)
+  return false;
+
+// The first argument will be the type we're decomposing.
+// Technically the getter could have more than 1 argument
+// (e.g., if they're defaulted arguments), but we don't care
+// about them because we just need to check whether the
+// first argument is a DecompositionDecl.
+auto const *Arg = CE->getArg(0);
+if (!Arg)
+  return false;
+
+Init = Arg;
+  }
+
   auto const *RefExpr =
   llvm::dyn_cast_or_null(Init->IgnoreUnlessSpelledInSource());
   if (!RefExpr)
 return false;
 
-  return llvm::dyn_cast_or_null(RefExpr->getDecl());
+  return llvm::isa_and_nonnull(RefExpr->getDecl());
 }
 
 /// Returns true if \ref VD is a compiler-generated variable
diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp 
b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
index 5fbd54c16382c0..55a84a65015842 100644
--- a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
+++ b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple 
%itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void 
@llvm.dbg.declare"
 
+// CHECK: define noundef i32 @_Z1fv
 // CHECK: #dbg_declare(ptr %{{[a-z]+}}, ![[VAR_0:[0-9]+]], !DIExpression(),
 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_1:[0-9]+]], !DIExpression(),
 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_2:[0-9]+]], 
!DIExpre

[Lldb-commits] [lldb] [lldb][test] Link certain libc++ tests with the whole library (PR #122358)

2025-01-09 Thread Vladislav Dzhidzhoev via lldb-commits

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

Some tests from 'import-std-module' used to fail on the builder
https://lab.llvm.org/staging/#/builders/195/builds/4470,
since libcxx is set up to be linked statically with test binaries
on it.

Thus, they were temporarily disabled in #112530. Here, this commit
is reverted.

Jitted expressions from the tests try to call __libcpp_verbose_abort
function that is not present in the process image, which causes
the failure.

Here, this symbol is explicitly referenced from the test source files.

>From 6e0c074b75d72c589cf15323f4b309ee5ece4875 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Thu, 9 Jan 2025 13:18:09 +0100
Subject: [PATCH 1/2] Revert "[lldb][test] Skip Test*FromStdModule tests on
 Linux for now (#112530)"

This reverts commit 87f126243beb69b8b02e5cd4df762bc8a6f1f8cc.
---
 .../expression/import-std-module/array/TestArrayFromStdModule.py | 1 -
 .../TestDbgInfoContentVectorFromStdModule.py | 1 -
 .../vector-of-vectors/TestVectorOfVectorsFromStdModule.py| 1 -
 3 files changed, 3 deletions(-)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
index bafc7628296217..13ab6b0c9ac1fb 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
@@ -10,7 +10,6 @@
 class TestCase(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 71eaeef20e792d..1c3e64f14c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -14,7 +14,6 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
 @skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
index e9415fd53651f7..a1f33271f39d2f 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
@@ -10,7 +10,6 @@
 class TestVectorOfVectors(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 

>From 48a1874b9b1f2424ea28f965c21175d175676afb Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Thu, 9 Jan 2025 20:22:20 +0100
Subject: [PATCH 2/2] [lldb][test] Link certain libc++ tests with the whole
 library

Some tests from 'import-std-module' used to fail on the builder
https://lab.llvm.org/staging/#/builders/195/builds/4470,
since libcxx is set up to be linked statically with test binaries
on it.

Thus, they were temporarily disabled in #112530. Here, this commit
is reverted.

Jitted expressions from the tests try to call __libcpp_verbose_abort
function that is not present in the process image, which causes
the failure.

Here, this symbol is explicitly referenced from the test source files.
---
 .../API/commands/expression/import-std-module/array/main.cpp   | 3 +++
 .../import-std-module/vector-dbg-info-content/main.cpp | 3 +++
 .../expression/import-std-module/vector-of-vectors/main.cpp| 3 +++
 3 files changed, 9 insertions(+)

diff --git a/lldb/test/API/commands/expression/import-std-module/array/main.cpp 
b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
index 9bcd0b574042a4..dae5db34b6f794 100644
--- a/lldb/test/API/commands/expression/import-std-module/array/main.cpp
+++ b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
@@ -1,4 +1,7 @@
 #include 
+#include <__verbose_abort>
+
+void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
 
 struct DbgInfo {
   int v = 4;
diff --git 
a/lldb/test/API/commands/exp

[Lldb-commits] [lldb] [lldb][test] Link certain libc++ tests with the whole library (PR #122358)

2025-01-09 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vladislav Dzhidzhoev (dzhidzhoev)


Changes

Some tests from 'import-std-module' used to fail on the builder
https://lab.llvm.org/staging/#/builders/195/builds/4470,
since libcxx is set up to be linked statically with test binaries
on it.

Thus, they were temporarily disabled in #112530. Here, this commit
is reverted.

Jitted expressions from the tests try to call __libcpp_verbose_abort
function that is not present in the process image, which causes
the failure.

Here, this symbol is explicitly referenced from the test source files.

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


6 Files Affected:

- (modified) 
lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
 (-1) 
- (modified) lldb/test/API/commands/expression/import-std-module/array/main.cpp 
(+3) 
- (modified) 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 (-1) 
- (modified) 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
 (+3) 
- (modified) 
lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
 (-1) 
- (modified) 
lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp 
(+3) 


``diff
diff --git 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
index bafc7628296217..13ab6b0c9ac1fb 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
@@ -10,7 +10,6 @@
 class TestCase(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git a/lldb/test/API/commands/expression/import-std-module/array/main.cpp 
b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
index 9bcd0b574042a4..dae5db34b6f794 100644
--- a/lldb/test/API/commands/expression/import-std-module/array/main.cpp
+++ b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
@@ -1,4 +1,7 @@
 #include 
+#include <__verbose_abort>
+
+void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
 
 struct DbgInfo {
   int v = 4;
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 71eaeef20e792d..1c3e64f14c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -14,7 +14,6 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
 @skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
index 24c3fec75d2f5f..ecb36ef6ccac23 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
@@ -1,4 +1,7 @@
 #include 
+#include <__verbose_abort>
+
+void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
 
 struct Foo {
   int a;
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
index e9415fd53651f7..a1f33271f39d2f 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
@@ -10,7 +10,6 @@
 class TestVectorOfVectors(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
index b5ada909e43976..596bbef163df0b 10

[Lldb-commits] [lldb] [lldb][test] Link certain libc++ tests with the whole library (PR #118986)

2025-01-09 Thread Vladislav Dzhidzhoev via lldb-commits

dzhidzhoev wrote:

> It's definitely better, but I'm still not particularly thrilled with this 
> approach. IIUC, you made this work by changing the buildbot configuration, 
> which is fine if you control all the buildbots that build this way, but it's 
> definitely not ideal. The linker flags are skipped on darwin because their 
> linker doesn't understand them, which works because darwin currently always 
> builds libc++ dynamically, but if that changed, we'd need a darwin-specific 
> version of this. The same goes for windows, which currently works only 
> because we're always using lld.
> 
> OTOH, pulling in a symbol by referencing it from a C++ file should work under 
> pretty much any configuration.

Thank you! Could you take a look at this 
https://github.com/llvm/llvm-project/pull/122358?

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


[Lldb-commits] [lldb] [lldb][test] Fix some 'import-std-module' tests (PR #122358)

2025-01-09 Thread Vladislav Dzhidzhoev via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Fix some 'import-std-module' tests (PR #122358)

2025-01-09 Thread Vladislav Dzhidzhoev via lldb-commits

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

>From 6e0c074b75d72c589cf15323f4b309ee5ece4875 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Thu, 9 Jan 2025 13:18:09 +0100
Subject: [PATCH 1/2] Revert "[lldb][test] Skip Test*FromStdModule tests on
 Linux for now (#112530)"

This reverts commit 87f126243beb69b8b02e5cd4df762bc8a6f1f8cc.
---
 .../expression/import-std-module/array/TestArrayFromStdModule.py | 1 -
 .../TestDbgInfoContentVectorFromStdModule.py | 1 -
 .../vector-of-vectors/TestVectorOfVectorsFromStdModule.py| 1 -
 3 files changed, 3 deletions(-)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
index bafc7628296217..13ab6b0c9ac1fb 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/array/TestArrayFromStdModule.py
@@ -10,7 +10,6 @@
 class TestCase(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 71eaeef20e792d..1c3e64f14c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -14,7 +14,6 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
 @skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
index e9415fd53651f7..a1f33271f39d2f 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
@@ -10,7 +10,6 @@
 class TestVectorOfVectors(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
-@skipIfLinux  # 
https://discourse.llvm.org/t/lldb-test-failures-on-linux/80095
 def test(self):
 self.build()
 

>From 0c88cd45b5fe2f9330a377dbc74b5d84e7a6568c Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Thu, 9 Jan 2025 20:22:20 +0100
Subject: [PATCH 2/2] [lldb][test] Fix some 'import-std-module' tests

Some tests from 'import-std-module' used to fail on the builder
https://lab.llvm.org/staging/#/builders/195/builds/4470,
since libcxx is set up to be linked statically with test binaries
on it.

Thus, they were temporarily disabled in #112530. Here, this commit
is reverted.

Jitted expressions from the tests try to call __libcpp_verbose_abort
function that is not present in the process image, which causes
the failure.

Here, this symbol is explicitly referenced from the test source files.
---
 .../API/commands/expression/import-std-module/array/main.cpp   | 3 +++
 .../import-std-module/vector-dbg-info-content/main.cpp | 3 +++
 .../expression/import-std-module/vector-of-vectors/main.cpp| 3 +++
 3 files changed, 9 insertions(+)

diff --git a/lldb/test/API/commands/expression/import-std-module/array/main.cpp 
b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
index 9bcd0b574042a4..dae5db34b6f794 100644
--- a/lldb/test/API/commands/expression/import-std-module/array/main.cpp
+++ b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
@@ -1,4 +1,7 @@
 #include 
+#include <__verbose_abort>
+
+void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
 
 struct DbgInfo {
   int v = 4;
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
index 24c3fec75d2f5f..ecb36ef6ccac23 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
@@ -1,4 +1,7 @@
 #include 
+#include <__verbose_abort>
+
+void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
 
 s

[Lldb-commits] [lldb] [lldb][test] Fix some 'import-std-module' tests (PR #122358)

2025-01-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 c05fc9b6d5559cc37e389f20a6c0c7b6f291b70e 
0c88cd45b5fe2f9330a377dbc74b5d84e7a6568c --extensions cpp -- 
lldb/test/API/commands/expression/import-std-module/array/main.cpp 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
 lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/test/API/commands/expression/import-std-module/array/main.cpp 
b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
index dae5db34b6..cb28fc5d7c 100644
--- a/lldb/test/API/commands/expression/import-std-module/array/main.cpp
+++ b/lldb/test/API/commands/expression/import-std-module/array/main.cpp
@@ -1,7 +1,7 @@
-#include 
 #include <__verbose_abort>
+#include 
 
-void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
+void *libcpp_verbose_abort_ptr = (void *)&std::__libcpp_verbose_abort;
 
 struct DbgInfo {
   int v = 4;
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
index ecb36ef6cc..5cb115cb19 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
@@ -1,7 +1,7 @@
-#include 
 #include <__verbose_abort>
+#include 
 
-void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
+void *libcpp_verbose_abort_ptr = (void *)&std::__libcpp_verbose_abort;
 
 struct Foo {
   int a;
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
index 596bbef163..1f4e653cb0 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/main.cpp
@@ -1,7 +1,7 @@
-#include 
 #include <__verbose_abort>
+#include 
 
-void *libcpp_verbose_abort_ptr = (void *) &std::__libcpp_verbose_abort;
+void *libcpp_verbose_abort_ptr = (void *)&std::__libcpp_verbose_abort;
 
 int main(int argc, char **argv) {
   std::vector > a = {{1, 2, 3}, {3, 2, 1}};

``




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