[Lldb-commits] [PATCH] D152708: [RFC][Draft] Enable primitive support for Two-Level Line Tables in LLVM

2023-06-12 Thread Stephen Tozer via Phabricator via lldb-commits
StephenTozer created this revision.
StephenTozer added a project: debug-info.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
StephenTozer requested review of this revision.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits, jplehr, 
sstefan1, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added projects: clang, LLDB, LLVM.

NOTE: This is not intended to be merged into LLVM, as the implementation is 
incomplete and hacked-in and **is not being actively developed**; the intention 
is simply to provide a basic working implementation that can be analyzed and 
potentially expanded on by any interested parties. For more information see 
this discourse post.

This patch implements the Two-Level Line Tables (TLLT) proposal 
 currently aiming for Dwarf 6. This 
proposal allows the line table, which is DWARF's data structure used to map 
instructions to source locations and vice versa, to be emitted as a pair of 
tables instead of one, one of which maps source locations to instructions (the 
Logicals table) and the other of which maps instructions to source locations 
(the Actuals table). The proposal then extends the Logicals table by adding a 
context column, allowing entries in that table that represent inlined 
instructions to refer to another Logicals entry as being the inlined call 
location for that instruction, creating records for an inlined call stack in 
the line table and allowing the inlined callsites to be mapped to an 
instruction in the debugger.

This solves one of the current weaknesses in DWARF debugging, which is the 
inability to set breakpoints or step onto inlined callsites. However, there are 
other proposals (such as Location View Numbering 
) that could achieve the same thing, 
and the costs of TLLT in storage size and design complexity may make it a 
non-ideal solution to this problem. We currently have no plans to develop this 
implementation further, but this small demo may be useful to other developers 
who have an interest in pursuing this, and it is still possible that a good 
case may be made for TLLT as the best solution to the problem of representing 
inlined callsites.

As mentioned in the header, this patch was the result of aiming to get a basic 
functioning implementation in a very short time; it is not intended to be 
merged and is not of suitable quality, particularly in LLDB (with which we have 
no familiarity).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152708

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  lldb/include/lldb/Symbol/LineTable.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Symbol/LineTable.cpp
  llvm/include/llvm/BinaryFormat/Dwarf.def
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/MC/MCDwarf.h
  llvm/include/llvm/MC/MCStreamer.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
  llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCStreamer.cpp

Index: llvm/lib/MC/MCStreamer.cpp
===
--- llvm/lib/MC/MCStreamer.cpp
+++ llvm/lib/MC/MCStreamer.cpp
@@ -268,6 +268,18 @@
   Discriminator);
 }
 
+void MCStreamer::emitDwarfLogicalLocDirective(
+unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags,
+unsigned Isa, unsigned Discriminator, StringRef FileName, unsigned Context,
+StringRef FunctionName) {
+  getContext().addCurrentDwarfLogicalLoc(FileNo, Line, Column, Flags, Isa,
+ Discriminator, Context, FunctionName);
+}
+
+void MCStreamer::emitDwarfActualLocDirective(unsigned Line, unsigned Flags) {
+  getContext().setCurrentDwarfActualLoc(Line, Flags);
+}
+
 MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) {
   MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
   if (!Table.getLabel()) {
Index: llvm/lib/MC/MCDwarf.cpp
===
--- llvm/lib/MC/MCDwarf.cpp
+++ llvm/lib/MC/MCDwarf.cpp
@@ -92,28 +92,69 @@
 // a line entry made for it is made.
 //
 void MCDwarfLineEntry::make(MCStreamer *MCOS, MCSection *Section) {
-  if (!MCOS->getContext().getDwarfLocSeen())
-return;
+  uint16_t VersionNumber = MCOS->getContext().getDwarfVersion();
+  // If we're emi

[Lldb-commits] [PATCH] D152569: [lldb] Introduce a tool to quickly generate projects with an arbitrary number of sources

2023-06-12 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

If you wanted to indent the long strings to the same level as the function's 
code you could use 
https://docs.python.org/3/library/textwrap.html#textwrap.dedent (but it's fine 
as is).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152569

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


[Lldb-commits] [PATCH] D152708: [RFC][Draft] Enable primitive support for Two-Level Line Tables in LLVM

2023-06-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

Thanks for prototyping this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152708

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


[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-12 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack created this revision.
Herald added a subscriber: danielkiss.
Herald added a project: All.
splhack added reviewers: clayborg, hans.
splhack published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

lldb-server for Android does not build with NDK r21 and above due to
RetryAfterSignal and Bionic ::open mismatch.
https://github.com/llvm/llvm-project/issues/54727

Apply the LLVM patch to LLDB.
https://github.com/llvm/llvm-project/commit/0a0e411204a2baa520fd73a8d69b664f98b428ba

> In Bionic, open can be overloaded for _FORTIFY_SOURCE support, causing
> compile errors of RetryAfterSignal due to overload resolution. Wrapping
> the call in a lambda avoids this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152712

Files:
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Host/posix/FileSystemPosix.cpp
  lldb/source/Host/posix/PipePosix.cpp
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp


Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -71,7 +71,10 @@
 }
 
 static void DupDescriptor(int error_fd, const char *file, int fd, int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open, file, flags, 0666);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(file, flags, 0666); };
+  int target_fd = llvm::sys::RetryAfterSignal(-1, Open);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
Index: lldb/source/Host/posix/PipePosix.cpp
===
--- lldb/source/Host/posix/PipePosix.cpp
+++ lldb/source/Host/posix/PipePosix.cpp
@@ -148,7 +148,10 @@
 flags |= O_CLOEXEC;
 
   Status error;
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.str().c_str(), flags);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(name.str().c_str(), flags); };
+  int fd = llvm::sys::RetryAfterSignal(-1, Open);
   if (fd != -1)
 m_fds[READ] = fd;
   else
Index: lldb/source/Host/posix/FileSystemPosix.cpp
===
--- lldb/source/Host/posix/FileSystemPosix.cpp
+++ lldb/source/Host/posix/FileSystemPosix.cpp
@@ -77,5 +77,8 @@
 }
 
 int FileSystem::Open(const char *path, int flags, int mode) {
-  return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(path, flags, mode); };
+  return llvm::sys::RetryAfterSignal(-1, Open);
 }
Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
===
--- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -726,7 +726,10 @@
 #if LLDB_ENABLE_POSIX
   std::string addr_str = s.str();
   // file:///PATH
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, addr_str.c_str(), O_RDWR);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(addr_str.c_str(), O_RDWR); };
+  int fd = llvm::sys::RetryAfterSignal(-1, Open);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
@@ -776,7 +779,10 @@
 return eConnectionStatusError;
   }
 
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, path.str().c_str(), O_RDWR);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(path.str().c_str(), O_RDWR); };
+  int fd = llvm::sys::RetryAfterSignal(-1, Open);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
Index: lldb/source/Host/common/PseudoTerminal.cpp
===
--- lldb/source/Host/common/PseudoTerminal.cpp
+++ lldb/source/Host/common/PseudoTerminal.cpp
@@ -95,7 +95,10 @@
   CloseSecondaryFileDescriptor();
 
   std::string name = GetSecondaryName();
-  m_secondary_fd = llvm::sys::RetryAfterSignal(-1, ::open, name.c_str(), 
oflag);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto Open = [&]() { return ::open(name.c_str(), oflag); };
+  m_secondary_fd = llvm::sys::RetryAfterSignal(-1, Open);
   if (m_secondary_fd >= 0)
 return llvm::Error::success();
 


Index: lldb/source/Host/pos

[Lldb-commits] [PATCH] D152590: Streamline expression parser error messages

2023-06-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

pinging after the weekend.


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

https://reviews.llvm.org/D152590

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


[Lldb-commits] [PATCH] D152590: Streamline expression parser error messages

2023-06-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Ship it


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

https://reviews.llvm.org/D152590

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


[Lldb-commits] [PATCH] D152708: [RFC][Draft] Enable primitive support for Two-Level Line Tables in LLVM

2023-06-12 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added a comment.

Really appreciate you providing this prototype.

> This solves one of the current weaknesses in DWARF debugging, which is the 
> inability to set breakpoints or step onto inlined callsites. However, there 
> are other proposals (such as Location View Numbering) that could achieve the 
> same thing, and the costs of TLLT in storage size and design complexity may 
> make it a non-ideal solution to this problem.

FWIW, one of the major motivations for this was not only to include the stop 
points, but also to allow symbolizing including stack frames - so you'd need to 
know that all the inlined instructions come from the inlined call site. I 
think, maybe, my vague understanding of Location View Numbering wouldn't cover 
that case, and only covers the "how do I describe the variable when I'm stopped 
at this synthetic location that exists just before or after the call", for 
instance?

It is unfortunate to hear that TLLT are a significant size increase, though not 
entirely surprising - it's a bunch of extra info to encode. I'll be glad to 
have this example to experiment with.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152708

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


[Lldb-commits] [PATCH] D152708: [RFC][Draft] Enable primitive support for Two-Level Line Tables in LLVM

2023-06-12 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added a comment.

Are there any known (or vague/unknown) limitations on the implementation with 
respect to the actual output/on-disk representation? (like, would doing some 
kind of size analysis of the output when using this patch/feature lead to 
incorrect conclusions about the cost of the feature?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152708

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


[Lldb-commits] [lldb] 133c3ea - Streamline expression parser error messages.

2023-06-12 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2023-06-12T10:29:48-07:00
New Revision: 133c3eaac0a532380c3d6ad21a60da1490f51fb8

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

LOG: Streamline expression parser error messages.

Currently the expression parser prints a mostly useless generic error before 
printing the compiler error:

  (lldb) p 1+x)
  error: expression failed to parse:
  error: :1:3: use of undeclared identifier 'x'
  1+x)
 ^

This is distracting and as far as I can tell only exists to work
around the fact that the first "error: " is unconditionally injected
by CommandReturnObject. The solution is not very elegant, but the
result looks much better.

(Partially addresses rdar://110492710)

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

Added: 


Modified: 
lldb/source/Expression/UserExpression.cpp
lldb/source/Interpreter/CommandReturnObject.cpp
lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
lldb/test/API/commands/expression/fixits/TestFixIts.py

Removed: 




diff  --git a/lldb/source/Expression/UserExpression.cpp 
b/lldb/source/Expression/UserExpression.cpp
index b250177db9979..8e1cac7099dc2 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -330,11 +330,10 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
   std::string msg;
   {
 llvm::raw_string_ostream os(msg);
-os << "expression failed to parse:\n";
 if (!diagnostic_manager.Diagnostics().empty())
   os << diagnostic_manager.GetString();
 else
-  os << "unknown error";
+  os << "expression failed to parse (no further compiler diagnostics)";
 if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
 !fixed_expression->empty())
   os << "\nfixed expression suggested:\n  " << *fixed_expression;

diff  --git a/lldb/source/Interpreter/CommandReturnObject.cpp 
b/lldb/source/Interpreter/CommandReturnObject.cpp
index 4433c43ff6d46..0bc58124f3941 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -101,7 +101,10 @@ void CommandReturnObject::AppendError(llvm::StringRef 
in_string) {
   SetStatus(eReturnStatusFailed);
   if (in_string.empty())
 return;
-  error(GetErrorStream()) << in_string.rtrim() << '\n';
+  // Workaround to deal with already fully formatted compiler diagnostics.
+  llvm::StringRef msg(in_string.rtrim());
+  msg.consume_front("error: ");
+  error(GetErrorStream()) << msg << '\n';
 }
 
 void CommandReturnObject::SetError(const Status &error,

diff  --git 
a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py 
b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
index bf1fc8e4e0e0a..d64e9897a844f 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -151,8 +151,7 @@ def test_source_and_caret_printing(self):
 value = frame.EvaluateExpression("struct Redef { float y; };", 
top_level_opts)
 self.assertFalse(value.GetError().Success())
 self.assertIn(
-"""
-error: :1:8: redefinition of 'Redef'
+"""error: :1:8: redefinition of 'Redef'
 1 | struct Redef { float y; };
   |^
 :1:8: previous definition is here

diff  --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py 
b/lldb/test/API/commands/expression/fixits/TestFixIts.py
index 484c255e06860..3bdeb84b4e797 100644
--- a/lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -154,7 +154,6 @@ def test_with_multiple_retries(self):
 multiple_runs_options.SetRetriesWithFixIts(0)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("using declaration resolved to type without 'typename'", 
errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 self.assertIn("using typename T::TypeDef", errmsg)
@@ -166,7 +165,6 @@ def test_with_multiple_retries(self):
 multiple_runs_options.SetRetriesWithFixIts(1)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 # Both our fixed expressions should be in the suggested expression.
 self.assertIn("using typename T::TypeDef", errmsg)



___
lldb-

[Lldb-commits] [PATCH] D152590: Streamline expression parser error messages

2023-06-12 Thread Adrian Prantl via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG133c3eaac0a5: Streamline expression parser error messages. 
(authored by aprantl).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152590

Files:
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Interpreter/CommandReturnObject.cpp
  lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
  lldb/test/API/commands/expression/fixits/TestFixIts.py


Index: lldb/test/API/commands/expression/fixits/TestFixIts.py
===
--- lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -154,7 +154,6 @@
 multiple_runs_options.SetRetriesWithFixIts(0)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("using declaration resolved to type without 'typename'", 
errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 self.assertIn("using typename T::TypeDef", errmsg)
@@ -166,7 +165,6 @@
 multiple_runs_options.SetRetriesWithFixIts(1)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 # Both our fixed expressions should be in the suggested expression.
 self.assertIn("using typename T::TypeDef", errmsg)
Index: lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
===
--- lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -151,8 +151,7 @@
 value = frame.EvaluateExpression("struct Redef { float y; };", 
top_level_opts)
 self.assertFalse(value.GetError().Success())
 self.assertIn(
-"""
-error: :1:8: redefinition of 'Redef'
+"""error: :1:8: redefinition of 'Redef'
 1 | struct Redef { float y; };
   |^
 :1:8: previous definition is here
Index: lldb/source/Interpreter/CommandReturnObject.cpp
===
--- lldb/source/Interpreter/CommandReturnObject.cpp
+++ lldb/source/Interpreter/CommandReturnObject.cpp
@@ -101,7 +101,10 @@
   SetStatus(eReturnStatusFailed);
   if (in_string.empty())
 return;
-  error(GetErrorStream()) << in_string.rtrim() << '\n';
+  // Workaround to deal with already fully formatted compiler diagnostics.
+  llvm::StringRef msg(in_string.rtrim());
+  msg.consume_front("error: ");
+  error(GetErrorStream()) << msg << '\n';
 }
 
 void CommandReturnObject::SetError(const Status &error,
Index: lldb/source/Expression/UserExpression.cpp
===
--- lldb/source/Expression/UserExpression.cpp
+++ lldb/source/Expression/UserExpression.cpp
@@ -330,11 +330,10 @@
   std::string msg;
   {
 llvm::raw_string_ostream os(msg);
-os << "expression failed to parse:\n";
 if (!diagnostic_manager.Diagnostics().empty())
   os << diagnostic_manager.GetString();
 else
-  os << "unknown error";
+  os << "expression failed to parse (no further compiler diagnostics)";
 if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
 !fixed_expression->empty())
   os << "\nfixed expression suggested:\n  " << *fixed_expression;


Index: lldb/test/API/commands/expression/fixits/TestFixIts.py
===
--- lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -154,7 +154,6 @@
 multiple_runs_options.SetRetriesWithFixIts(0)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("using declaration resolved to type without 'typename'", errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 self.assertIn("using typename T::TypeDef", errmsg)
@@ -166,7 +165,6 @@
 multiple_runs_options.SetRetriesWithFixIts(1)
 value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
 errmsg = value.GetError().GetCString()
-self.assertIn("expression failed to parse", errmsg)
 self.assertIn("fixed expression suggested:", errmsg)
 # Both our fixed expressions should be in the s

[Lldb-commits] [PATCH] D152590: Streamline expression parser error messages

2023-06-12 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.
Herald added a subscriber: Michael137.



Comment at: lldb/source/Interpreter/CommandReturnObject.cpp:104
 return;
-  error(GetErrorStream()) << in_string.rtrim() << '\n';
+  // Workaround to deal with already fully formatted compiler diagnostics.
+  llvm::StringRef msg(in_string.rtrim());

nice


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152590

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


[Lldb-commits] [lldb] 73927d5 - [lldb][test] incomplete-tag-type.cpp: fix expected error message

2023-06-12 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2023-06-12T19:33:10+01:00
New Revision: 73927d574f57c1bdf792e2cefe2974b7e9375ed6

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

LOG: [lldb][test] incomplete-tag-type.cpp: fix expected error message

Follow up to 133c3eaac0a532380c3d6ad21a60da1490f51fb8

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

Added: 


Modified: 
lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp 
b/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
index f27b186345224..f81f91af661bb 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
+++ b/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
@@ -13,7 +13,6 @@
 // CHECK: (lldb) expression d
 // CHECK: (D) $1 = {}
 // CHECK: (lldb) expression static_e_ref
-// CHECK: error: expression failed to parse:
 // CHECK: error: {{.*}}: incomplete type 'E' where a complete type is required
 // CHECK: static_e_ref
 // CHECK: ^



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


[Lldb-commits] [PATCH] D152494: [lldb][Android] Fix adb shell cat

2023-06-12 Thread Nathan Lanza via Phabricator via lldb-commits
lanza accepted this revision.
lanza added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: JDevlieghere.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152494

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


[Lldb-commits] [PATCH] D152573: [lldb][NFCI] Remove use of ConstString from Listener

2023-06-12 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

LGTM, if no one has found a use for this way of filtering by this point, there 
probably isn't a good one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152573

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


[Lldb-commits] [PATCH] D152324: [lldb][NFCI] Change return type of PersistentExpressionState::GetNextPersistentVariableName

2023-06-12 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I wonder about this one.  In every instance where the API is used, its result 
is turned into a ConstString first.  That's because this variable name lives in 
the same slot as normal variable names, which come from the debug information 
and so tend to be in the ConstString pool for better reasons.  Do you project 
being able to get rid of that latter requirement?  If not, it seems a bit odd 
to go to the trouble to avoid this value starting life as a ConstString when 
the first thing everybody does with it is to turn it into a ConstString.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152324

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


[Lldb-commits] [PATCH] D151597: [lldb][NFCI] Remove use of ConstString from IOHandler

2023-06-12 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I don't think we need to support the case where the "end line token" doesn't 
have to stand on its own line.  It's reasonable for lldb to impose this policy, 
and if we are going to do that then requiring the "\n" after the end line token 
also seems odd.  The way this is done seems okay to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151597

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


[Lldb-commits] [PATCH] D151597: [lldb][NFCI] Remove use of ConstString from IOHandler

2023-06-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/Core/IOHandler.h:110
+  virtual llvm::StringRef GetControlSequence(char ch) {
+return llvm::StringRef();
+  }

I would `return {}` or `return ""`. 



Comment at: lldb/include/lldb/Core/IOHandler.h:302-303
   : IOHandlerDelegate(completion),
-m_end_line((end_line && end_line[0]) ? end_line : "") {}
+m_end_line((end_line && end_line[0]) ? std::string(end_line) + "\n"
+ : "\n") {}
 

Can we make end_line a `StringRef`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151597

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


[Lldb-commits] [lldb] 59b5581 - Speculative fix for windows test

2023-06-12 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2023-06-12T14:51:24-07:00
New Revision: 59b55818337b59f3e75511d9fb2b0b7b5e3d14a7

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

LOG: Speculative fix for windows test

Added: 


Modified: 
lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp 
b/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
index f81f91af661bb..a249057282d89 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
+++ b/lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp
@@ -13,7 +13,7 @@
 // CHECK: (lldb) expression d
 // CHECK: (D) $1 = {}
 // CHECK: (lldb) expression static_e_ref
-// CHECK: error: {{.*}}: incomplete type 'E' where a complete type is required
+// CHECK: error: {{.*}}incomplete type 'E' where a complete type is required
 // CHECK: static_e_ref
 // CHECK: ^
 



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


[Lldb-commits] [lldb] f09cca4 - [lldb] Remove lldb's DWARFAbbreviationDeclarationSet in favor of llvm's

2023-06-12 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-06-12T14:53:44-07:00
New Revision: f09cca4c6f67c2ab135c391ea8090130c5327c02

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

LOG: [lldb] Remove lldb's DWARFAbbreviationDeclarationSet in favor of llvm's

lldb's and llvm's implementations of DWARFAbbreviationDeclarationSet are
now close enough (almost the same, actually) to replace lldb's with
llvm's wholesale. llvm's is also tested against the same kinds of
scenarios that lldb's is tested against so we can remove lldb's tests
here. (see: llvm/unittests/DebugInfo/DWARF/DWARFDebugAbbrevTest.cpp).

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

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
index c8d5aad2ef8e7..0cd53463ee65e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -14,96 +14,20 @@
 using namespace lldb;
 using namespace lldb_private;
 
-// DWARFAbbreviationDeclarationSet::Clear()
-void DWARFAbbreviationDeclarationSet::Clear() {
-  m_idx_offset = 0;
-  m_decls.clear();
-}
-
-// DWARFAbbreviationDeclarationSet::Extract()
-llvm::Error
-DWARFAbbreviationDeclarationSet::extract(const DWARFDataExtractor &data,
- lldb::offset_t *offset_ptr) {
-  llvm::DataExtractor llvm_data = data.GetAsLLVM();
-  const lldb::offset_t begin_offset = *offset_ptr;
-  m_offset = begin_offset;
-  Clear();
-  DWARFAbbreviationDeclaration abbrevDeclaration;
-  uint32_t prev_abbr_code = 0;
-  while (true) {
-llvm::Expected es =
-abbrevDeclaration.extract(llvm_data, offset_ptr);
-if (!es)
-  return es.takeError();
-if (*es == llvm::DWARFAbbreviationDeclaration::ExtractState::Complete)
-  break;
-if (m_idx_offset == 0)
-  m_idx_offset = abbrevDeclaration.getCode();
-else if (prev_abbr_code + 1 != abbrevDeclaration.getCode())
-  m_idx_offset = UINT32_MAX;
-
-prev_abbr_code = abbrevDeclaration.getCode();
-m_decls.push_back(abbrevDeclaration);
-  }
-  return llvm::ErrorSuccess();
-}
-
-// DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration()
-const DWARFAbbreviationDeclaration *
-DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
-uint32_t abbrCode) const {
-  if (m_idx_offset == UINT32_MAX) {
-for (const auto &decl : m_decls) {
-  if (decl.getCode() == abbrCode)
-return &decl;
-}
-return nullptr;
-  }
-  if (abbrCode < m_idx_offset || abbrCode >= m_idx_offset + m_decls.size())
-return nullptr;
-  return &m_decls[abbrCode - m_idx_offset];
-}
-
-// DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
-void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
-std::set &invalid_forms) const {
-  for (const auto &decl : m_decls) {
-for (const auto &attr : decl.attributes()) {
-  if (!DWARFFormValue::FormIsSupported(attr.Form))
-invalid_forms.insert(attr.Form);
-}
-  }
-}
-
-// Encode
-//
-// Encode the abbreviation table onto the end of the buffer provided into a
-// byte representation as would be found in a ".debug_abbrev" debug information
-// section.
-// void
-// DWARFAbbreviationDeclarationSet::Encode(BinaryStreamBuf& debug_abbrev_buf)
-// const
-//{
-//  DWARFAbbreviationDeclarationCollConstIter pos;
-//  DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
-//  for (pos = m_decls.begin(); pos != end; ++pos)
-//  pos->Append(debug_abbrev_buf);
-//  debug_abbrev_buf.Append8(0);
-//}
-
 // DWARFDebugAbbrev constructor
 DWARFDebugAbbrev::DWARFDebugAbbrev()
 : m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
 
 // DWARFDebugAbbrev::Parse()
 llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
+  llvm::DataExtractor llvm_data = data.GetAsLLVM();
   lldb::offset_t offset = 0;
 
-  while (data.ValidOffset(offset)) {
+  while (llvm_data.isValidOffset(offset)) {
 uint32_t initial_cu_offset = offset;
 DWARFAbbreviationDeclarationSet abbrevDeclSet;
 
-llvm::Error error = abbrevDeclSet.extract(data, &offset);
+llvm::Error error = abbrevDeclSet.extract(llvm_data, &offset);
 if (error)
   return error;
 
@@ -136,5 +60,8 @@ DWARFDebugAbbrev::GetAbbreviationDeclarationSet(
 void DWARFDebugAbbrev::GetUnsupportedForms(
 std:

[Lldb-commits] [PATCH] D152476: [lldb] Remove lldb's DWARFAbbreviationDeclarationSet in favor of llvm's

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf09cca4c6f67: [lldb] Remove lldb's 
DWARFAbbreviationDeclarationSet in favor of llvm's (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152476

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -16,7 +16,6 @@
 
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
-#include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAranges.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
@@ -68,252 +67,6 @@
   EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
 }
 
-TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start1) {
-  // Test that if we have a .debug_abbrev that contains ordered abbreviation
-  // codes that start at 1, that we get O(1) access.
-
-  const auto byte_order = eByteOrderLittle;
-  const uint8_t addr_size = 4;
-  StreamString encoder(Stream::eBinary, addr_size, byte_order);
-  encoder.PutULEB128(1); // Abbrev code 1
-  encoder.PutULEB128(DW_TAG_compile_unit);
-  encoder.PutHex8(DW_CHILDREN_yes);
-  encoder.PutULEB128(DW_AT_name);
-  encoder.PutULEB128(DW_FORM_strp);
-  encoder.PutULEB128(0);
-  encoder.PutULEB128(0);
-
-  encoder.PutULEB128(2); // Abbrev code 2
-  encoder.PutULEB128(DW_TAG_subprogram);
-  encoder.PutHex8(DW_CHILDREN_no);
-  encoder.PutULEB128(DW_AT_name);
-  encoder.PutULEB128(DW_FORM_strp);
-  encoder.PutULEB128(0);
-  encoder.PutULEB128(0);
-
-  encoder.PutULEB128(0); // Abbrev code 0 (termination)
-
-  DWARFDataExtractor data;
-  data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
-  DWARFAbbreviationDeclarationSet abbrev_set;
-  lldb::offset_t data_offset = 0;
-  llvm::Error error = abbrev_set.extract(data, &data_offset);
-  EXPECT_FALSE(bool(error));
-  // Make sure we have O(1) access to each abbreviation by making sure the
-  // index offset is 1 and not UINT32_MAX
-  EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
-
-  auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->hasChildren());
-  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
-  auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->hasChildren());
-  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
-}
-
-TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
-  // Test that if we have a .debug_abbrev that contains ordered abbreviation
-  // codes that start at 5, that we get O(1) access.
-
-  const auto byte_order = eByteOrderLittle;
-  const uint8_t addr_size = 4;
-  StreamString encoder(Stream::eBinary, addr_size, byte_order);
-  encoder.PutULEB128(5); // Abbrev code 5
-  encoder.PutULEB128(DW_TAG_compile_unit);
-  encoder.PutHex8(DW_CHILDREN_yes);
-  encoder.PutULEB128(DW_AT_name);
-  encoder.PutULEB128(DW_FORM_strp);
-  encoder.PutULEB128(0);
-  encoder.PutULEB128(0);
-
-  encoder.PutULEB128(6); // Abbrev code 6
-  encoder.PutULEB128(DW_TAG_subprogram);
-  encoder.PutHex8(DW_CHILDREN_no);
-  encoder.PutULEB128(DW_AT_name);
-  encoder.PutULEB128(DW_FORM_strp);
-  encoder.PutULEB128(0);
-  encoder.PutULEB128(0);
-
-  encoder.PutULEB128(0); // Abbrev code 0 (termination)
-
-  DWARFDataExtractor data;
-  data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
-  DWARFAbbreviationDeclarationSet abbrev_set;
-  lldb::offset_t data_offset = 0;
-  llvm::Error error = abbrev_set.extract(data, &data_offset);
-  EXPECT_FALSE(bool(error));
-  // Make sure we have O(1) access to each abbreviation by making sure the
-  // index offset is 5 and not UINT32_MAX
-  EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
-
-  auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
-  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->hasChildren());
-  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
-  auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(6);
-  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->hasChildren());
-  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
-}
-
-TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
-  // Test that if we have a .debug_abbrev that contains unordered abbr

[Lldb-commits] [PATCH] D152569: [lldb] Introduce a tool to quickly generate projects with an arbitrary number of sources

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 530692.
bulbazord added a comment.

Remove temp variables
More multiline string literals


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152569

Files:
  lldb/scripts/generate-project.py

Index: lldb/scripts/generate-project.py
===
--- /dev/null
+++ lldb/scripts/generate-project.py
@@ -0,0 +1,303 @@
+#!/usr/bin/env python3
+
+# Project generation script
+# =
+# The purpose of this script is to generate a project with an arbitrary amount
+# of source files. This is useful for testing the performance impact of a given
+# LLDB change. For example, you can use this tool to generate a project with
+# 10,000 C++ source files and see how quickly LLDB processes the resulting
+# binary and related metadata (e.g. debug info).
+
+import os
+import sys
+import typing
+
+
+def print_usage() -> None:
+print("Usage: generate-project.py   ")
+
+
+def generate_c_header(directory: str, index: int) -> None:
+header_path = f"{directory}/obj{index}.h"
+with open(header_path, "w") as f:
+f.write(
+f"#ifndef _OBJ{index}_H\n"
+f"#define _OBJ{index}_H\n"
+f"extern int obj{index};\n"
+f"void call_obj{index}(void);\n"
+f"#endif // _OBJ{index}_H\n"
+)
+
+
+def generate_c_impl(directory: str, index: int) -> None:
+impl_path = f"{directory}/obj{index}.c"
+with open(impl_path, "w") as f:
+f.write(
+"#include \n"
+f'#include "obj{index}.h"\n\n'
+f"int obj{index} = {index};\n"
+f"void call_obj{index}(void)"
+" {\n"
+f'  printf("%d\\n", obj{index});\n'
+"}\n"
+)
+
+
+def generate_cpp_header(directory: str, index: int) -> None:
+header_path = f"{directory}/obj{index}.h"
+with open(header_path, "w") as f:
+f.write(
+f"#ifndef _OBJ{index}_H\n"
+f"#define _OBJ{index}_H\n"
+"namespace obj {\n"
+f"class Obj{index}"
+" {\n"
+"public:\n"
+"  static void Call(void);\n"
+"}; // class\n"
+"} // namespace\n"
+f"#endif // _OBJ{index}_H\n"
+)
+
+
+def generate_cpp_impl(directory: str, index: int) -> None:
+impl_path = f"{directory}/obj{index}.cpp"
+with open(impl_path, "w") as f:
+f.write(
+"#include \n"
+f'#include "obj{index}.h"\n\n'
+"namespace obj {\n"
+f"void Obj{index}::Call(void)"
+" {\n"
+f"  std::cout << {index} << std::endl;;\n"
+"}\n"
+"} // namespace\n"
+)
+
+
+def generate_swift_impl(directory: str, index: int) -> None:
+impl_path = f"{directory}/obj{index}.swift"
+with open(impl_path, "w") as f:
+f.write(f"public func call_obj{index}()" " {\n" f'  print("{index}")\n' "}\n")
+
+
+def generate_c_driver(directory: str, number_of_objects: int) -> None:
+main_path = f"{directory}/main.c"
+with open(main_path, "w") as f:
+for i in range(number_of_objects):
+f.write(f'#include "obj{i}.h"\n')
+
+f.write("int main() {\n")
+for i in range(number_of_objects):
+f.write(f"  call_obj{i}();\n")
+
+f.write("  return 0;\n")
+f.write("}\n")
+
+
+def generate_cpp_driver(directory: str, number_of_objects: int) -> None:
+main_path = f"{directory}/main.cpp"
+with open(main_path, "w") as f:
+for i in range(number_of_objects):
+f.write(f'#include "obj{i}.h"\n')
+
+f.write("using namespace obj;\n")
+f.write("int main() {\n")
+for i in range(number_of_objects):
+f.write(f"  Obj{i}::Call();\n")
+
+f.write("  return 0;\n")
+f.write("}\n")
+
+
+def generate_swift_driver(directory: str, number_of_objects: int) -> None:
+main_path = f"{directory}/main.swift"
+with open(main_path, "w") as f:
+for i in range(number_of_objects):
+f.write(f"import obj{i}\n")
+
+f.write("public func main() {\n")
+for i in range(number_of_objects):
+f.write(f"  call_obj{i}()\n")
+f.write("}\n")
+f.write("main()\n")
+
+
+def generate_c_makefile(directory: str, number_of_objects: int) -> None:
+makefile_path = f"{directory}/Makefile"
+with open(makefile_path, "w") as f:
+f.write("OBJDIR=objs\n\n")
+f.write("objects = \\\n")
+for i in range(number_of_objects):
+f.write(f"  $(OBJDIR)/obj{i}.o \\\n")
+f.write("  $(OBJDIR)/main.o\n")
+f.write("\n")
+f.write(
+"""
+all: many-objects
+objdir:
+\tmkdir -p $(OBJDIR)
+$(OBJDIR)/%.o: %.c objdir
+\t$(CC) -g -c -o $@ $<
+many-objects: $(objects)
+\t$(CC) -g -o $@ $^
+clean:
+\trm -

[Lldb-commits] [PATCH] D151597: [lldb][NFCI] Remove use of ConstString from IOHandler

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 530694.
bulbazord added a comment.

Address Jonas's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151597

Files:
  lldb/include/lldb/Core/Debugger.h
  lldb/include/lldb/Core/IOHandler.h
  lldb/include/lldb/Expression/REPL.h
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Expression/REPL.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -434,10 +434,11 @@
 
   ~IOHandlerPythonInterpreter() override = default;
 
-  ConstString GetControlSequence(char ch) override {
+  llvm::StringRef GetControlSequence(char ch) override {
+static constexpr llvm::StringLiteral control_sequence("quit()\n");
 if (ch == 'd')
-  return ConstString("quit()\n");
-return ConstString();
+  return control_sequence;
+return {};
   }
 
   void Run() override {
Index: lldb/source/Expression/REPL.cpp
===
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -117,10 +117,11 @@
   return (m_enable_auto_indent ? GetAutoIndentCharacters() : nullptr);
 }
 
-ConstString REPL::IOHandlerGetControlSequence(char ch) {
+llvm::StringRef REPL::IOHandlerGetControlSequence(char ch) {
+  static constexpr llvm::StringLiteral control_sequence(":quit\n");
   if (ch == 'd')
-return ConstString(":quit\n");
-  return ConstString();
+return control_sequence;
+  return {};
 }
 
 const char *REPL::IOHandlerGetCommandPrefix() { return ":"; }
Index: lldb/source/Core/Debugger.cpp
===
--- lldb/source/Core/Debugger.cpp
+++ lldb/source/Core/Debugger.cpp
@@ -1127,7 +1127,7 @@
   }
 }
 
-ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {
+llvm::StringRef Debugger::GetTopIOHandlerControlSequence(char ch) {
   return m_io_handler_stack.GetTopIOHandlerControlSequence(ch);
 }
 
Index: lldb/source/API/SBCommandInterpreter.cpp
===
--- lldb/source/API/SBCommandInterpreter.cpp
+++ lldb/source/API/SBCommandInterpreter.cpp
@@ -155,11 +155,12 @@
 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) {
   LLDB_INSTRUMENT_VA(this, ch);
 
-  return (IsValid()
-  ? m_opaque_ptr->GetDebugger()
-.GetTopIOHandlerControlSequence(ch)
-.GetCString()
-  : nullptr);
+  if (!IsValid())
+return nullptr;
+
+  return ConstString(
+ m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch))
+  .GetCString();
 }
 
 lldb::ReturnStatus
Index: lldb/include/lldb/Interpreter/CommandInterpreter.h
===
--- lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -652,10 +652,11 @@
   void IOHandlerInputComplete(IOHandler &io_handler,
   std::string &line) override;
 
-  ConstString IOHandlerGetControlSequence(char ch) override {
+  llvm::StringRef IOHandlerGetControlSequence(char ch) override {
+static constexpr llvm::StringLiteral control_sequence("quit\n");
 if (ch == 'd')
-  return ConstString("quit\n");
-return ConstString();
+  return control_sequence;
+return {};
   }
 
   void GetProcessOutput();
Index: lldb/include/lldb/Expression/REPL.h
===
--- lldb/include/lldb/Expression/REPL.h
+++ lldb/include/lldb/Expression/REPL.h
@@ -88,7 +88,7 @@
 
   const char *IOHandlerGetFixIndentationCharacters() override;
 
-  ConstString IOHandlerGetControlSequence(char ch) override;
+  llvm::StringRef IOHandlerGetControlSequence(char ch) override;
 
   const char *IOHandlerGetCommandPrefix() override;
 
Index: lldb/include/lldb/Core/IOHandler.h
===
--- lldb/include/lldb/Core/IOHandler.h
+++ lldb/include/lldb/Core/IOHandler.h
@@ -12,7 +12,6 @@
 #include "lldb/Core/ValueObjectList.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Utility/CompletionRequest.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Flags.h"
 #include "lldb/Utility/Predicate.h"
 #include "lldb/Utility/Stream.h"
@@ -107,7 +106,7 @@
   }
   bool SetPrompt(const char *) = delete;
 
-  virtual ConstString GetControlSequence(char ch) { return ConstString(); }
+  virtual llvm::StringRef GetControlSequence(char ch) { return {}; 

[Lldb-commits] [PATCH] D152324: [lldb][NFCI] Change return type of PersistentExpressionState::GetNextPersistentVariableName

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D152324#4415324 , @jingham wrote:

> I wonder about this one.  In every instance where the API is used, its result 
> is turned into a ConstString first.  That's because this variable name lives 
> in the same slot as normal variable names, which come from the debug 
> information and so tend to be in the ConstString pool for better reasons.  Do 
> you project being able to get rid of that latter requirement?  If not, it 
> seems a bit odd to go to the trouble to avoid this value starting life as a 
> ConstString when the first thing everybody does with it is to turn it into a 
> ConstString.

That's the major reason I'm sitting on this right now. I want to gather some 
more evidence and test things more before deciding this is the direction to go 
in. I'm pretty sure `ConstString` in its current form is the wrong abstraction 
for this, but perhaps some kind of variation of `ConstString` is the right 
call? We'll see...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152324

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


[Lldb-commits] [lldb] f687850 - [lldb] Change return type of UnixSignals::GetShortName

2023-06-12 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-06-12T16:44:05-07:00
New Revision: f687850de87759fa4a76a883971c2f909ae4d1b9

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

LOG: [lldb] Change return type of UnixSignals::GetShortName

The short names of each signal name and alias only exist as ConstStrings
in this one scenario. For example, GetShortName("SIGHUP") will just give
you "HUP". There's not a good reason the string "HUP" needs to be in the
ConstString StringPool, and that's true for just about every signal
name.

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

Added: 


Modified: 
lldb/include/lldb/Target/UnixSignals.h
lldb/source/Target/UnixSignals.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/UnixSignals.h 
b/lldb/include/lldb/Target/UnixSignals.h
index 74eb75fa23aa4..7b6060b9343c8 100644
--- a/lldb/include/lldb/Target/UnixSignals.h
+++ b/lldb/include/lldb/Target/UnixSignals.h
@@ -77,8 +77,6 @@ class UnixSignals {
 
   int32_t GetSignalAtIndex(int32_t index) const;
 
-  ConstString GetShortName(ConstString name) const;
-
   // We assume that the elements of this object are constant once it is
   // constructed, since a process should never need to add or remove symbols as
   // it runs.  So don't call these functions anywhere but the constructor of
@@ -147,6 +145,8 @@ class UnixSignals {
 void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
   };
 
+  llvm::StringRef GetShortName(llvm::StringRef name) const;
+
   virtual void Reset();
 
   typedef std::map collection;

diff  --git a/lldb/source/Target/UnixSignals.cpp 
b/lldb/source/Target/UnixSignals.cpp
index 5d0f687b8ba6f..0e738241b1c56 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -195,10 +195,8 @@ bool UnixSignals::SignalIsValid(int32_t signo) const {
   return m_signals.find(signo) != m_signals.end();
 }
 
-ConstString UnixSignals::GetShortName(ConstString name) const {
-  if (name)
-return ConstString(name.GetStringRef().substr(3)); // Remove "SIG" from 
name
-  return name;
+llvm::StringRef UnixSignals::GetShortName(llvm::StringRef name) const {
+  return name.substr(3); // Remove "SIG" from name
 }
 
 int32_t UnixSignals::GetSignalNumberFromName(const char *name) const {



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


[Lldb-commits] [PATCH] D152582: [lldb] Change return type of UnixSignals::GetShortName

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf687850de877: [lldb] Change return type of 
UnixSignals::GetShortName (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152582

Files:
  lldb/include/lldb/Target/UnixSignals.h
  lldb/source/Target/UnixSignals.cpp


Index: lldb/source/Target/UnixSignals.cpp
===
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -195,10 +195,8 @@
   return m_signals.find(signo) != m_signals.end();
 }
 
-ConstString UnixSignals::GetShortName(ConstString name) const {
-  if (name)
-return ConstString(name.GetStringRef().substr(3)); // Remove "SIG" from 
name
-  return name;
+llvm::StringRef UnixSignals::GetShortName(llvm::StringRef name) const {
+  return name.substr(3); // Remove "SIG" from name
 }
 
 int32_t UnixSignals::GetSignalNumberFromName(const char *name) const {
Index: lldb/include/lldb/Target/UnixSignals.h
===
--- lldb/include/lldb/Target/UnixSignals.h
+++ lldb/include/lldb/Target/UnixSignals.h
@@ -77,8 +77,6 @@
 
   int32_t GetSignalAtIndex(int32_t index) const;
 
-  ConstString GetShortName(ConstString name) const;
-
   // We assume that the elements of this object are constant once it is
   // constructed, since a process should never need to add or remove symbols as
   // it runs.  So don't call these functions anywhere but the constructor of
@@ -147,6 +145,8 @@
 void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
   };
 
+  llvm::StringRef GetShortName(llvm::StringRef name) const;
+
   virtual void Reset();
 
   typedef std::map collection;


Index: lldb/source/Target/UnixSignals.cpp
===
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -195,10 +195,8 @@
   return m_signals.find(signo) != m_signals.end();
 }
 
-ConstString UnixSignals::GetShortName(ConstString name) const {
-  if (name)
-return ConstString(name.GetStringRef().substr(3)); // Remove "SIG" from name
-  return name;
+llvm::StringRef UnixSignals::GetShortName(llvm::StringRef name) const {
+  return name.substr(3); // Remove "SIG" from name
 }
 
 int32_t UnixSignals::GetSignalNumberFromName(const char *name) const {
Index: lldb/include/lldb/Target/UnixSignals.h
===
--- lldb/include/lldb/Target/UnixSignals.h
+++ lldb/include/lldb/Target/UnixSignals.h
@@ -77,8 +77,6 @@
 
   int32_t GetSignalAtIndex(int32_t index) const;
 
-  ConstString GetShortName(ConstString name) const;
-
   // We assume that the elements of this object are constant once it is
   // constructed, since a process should never need to add or remove symbols as
   // it runs.  So don't call these functions anywhere but the constructor of
@@ -147,6 +145,8 @@
 void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
   };
 
+  llvm::StringRef GetShortName(llvm::StringRef name) const;
+
   virtual void Reset();
 
   typedef std::map collection;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D151597: [lldb][NFCI] Remove use of ConstString from IOHandler

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 530712.
bulbazord marked an inline comment as done.
bulbazord added a comment.

Address the other suggestion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151597

Files:
  lldb/include/lldb/Core/Debugger.h
  lldb/include/lldb/Core/IOHandler.h
  lldb/include/lldb/Expression/REPL.h
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Expression/REPL.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -434,10 +434,11 @@
 
   ~IOHandlerPythonInterpreter() override = default;
 
-  ConstString GetControlSequence(char ch) override {
+  llvm::StringRef GetControlSequence(char ch) override {
+static constexpr llvm::StringLiteral control_sequence("quit()\n");
 if (ch == 'd')
-  return ConstString("quit()\n");
-return ConstString();
+  return control_sequence;
+return {};
   }
 
   void Run() override {
Index: lldb/source/Expression/REPL.cpp
===
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -117,10 +117,11 @@
   return (m_enable_auto_indent ? GetAutoIndentCharacters() : nullptr);
 }
 
-ConstString REPL::IOHandlerGetControlSequence(char ch) {
+llvm::StringRef REPL::IOHandlerGetControlSequence(char ch) {
+  static constexpr llvm::StringLiteral control_sequence(":quit\n");
   if (ch == 'd')
-return ConstString(":quit\n");
-  return ConstString();
+return control_sequence;
+  return {};
 }
 
 const char *REPL::IOHandlerGetCommandPrefix() { return ":"; }
Index: lldb/source/Core/Debugger.cpp
===
--- lldb/source/Core/Debugger.cpp
+++ lldb/source/Core/Debugger.cpp
@@ -1127,7 +1127,7 @@
   }
 }
 
-ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {
+llvm::StringRef Debugger::GetTopIOHandlerControlSequence(char ch) {
   return m_io_handler_stack.GetTopIOHandlerControlSequence(ch);
 }
 
Index: lldb/source/API/SBCommandInterpreter.cpp
===
--- lldb/source/API/SBCommandInterpreter.cpp
+++ lldb/source/API/SBCommandInterpreter.cpp
@@ -155,11 +155,12 @@
 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) {
   LLDB_INSTRUMENT_VA(this, ch);
 
-  return (IsValid()
-  ? m_opaque_ptr->GetDebugger()
-.GetTopIOHandlerControlSequence(ch)
-.GetCString()
-  : nullptr);
+  if (!IsValid())
+return nullptr;
+
+  return ConstString(
+ m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch))
+  .GetCString();
 }
 
 lldb::ReturnStatus
Index: lldb/include/lldb/Interpreter/CommandInterpreter.h
===
--- lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -652,10 +652,11 @@
   void IOHandlerInputComplete(IOHandler &io_handler,
   std::string &line) override;
 
-  ConstString IOHandlerGetControlSequence(char ch) override {
+  llvm::StringRef IOHandlerGetControlSequence(char ch) override {
+static constexpr llvm::StringLiteral control_sequence("quit\n");
 if (ch == 'd')
-  return ConstString("quit\n");
-return ConstString();
+  return control_sequence;
+return {};
   }
 
   void GetProcessOutput();
Index: lldb/include/lldb/Expression/REPL.h
===
--- lldb/include/lldb/Expression/REPL.h
+++ lldb/include/lldb/Expression/REPL.h
@@ -88,7 +88,7 @@
 
   const char *IOHandlerGetFixIndentationCharacters() override;
 
-  ConstString IOHandlerGetControlSequence(char ch) override;
+  llvm::StringRef IOHandlerGetControlSequence(char ch) override;
 
   const char *IOHandlerGetCommandPrefix() override;
 
Index: lldb/include/lldb/Core/IOHandler.h
===
--- lldb/include/lldb/Core/IOHandler.h
+++ lldb/include/lldb/Core/IOHandler.h
@@ -12,7 +12,6 @@
 #include "lldb/Core/ValueObjectList.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Utility/CompletionRequest.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Flags.h"
 #include "lldb/Utility/Predicate.h"
 #include "lldb/Utility/Stream.h"
@@ -107,7 +106,7 @@
   }
   bool SetPrompt(const char *) = delete;
 
-  virtual ConstString GetControlSequence(char ch) { return ConstString(); }
+  virtual llvm::Str

[Lldb-commits] [PATCH] D152757: [lldb][ObjectFileELF] Set ModuleSpec file offset and size

2023-06-12 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack created this revision.
Herald added a subscriber: emaste.
Herald added a project: All.
splhack added reviewers: clayborg, labath, friss, lanza.
splhack published this revision for review.
Herald added subscribers: lldb-commits, MaskRay.
Herald added a project: LLDB.

In Android API level 23 and above, dynamic loader is able to load .so file
directly from APK.
https://android.googlesource.com/platform/bionic/+/master/
android-changes-for-ndk-developers.md#
opening-shared-libraries-directly-from-an-apk

ObjectFileELF::GetModuleSpecifications will load a .so file, which is page
aligned and uncompressed, directly from a zip file. However it does not
set the .so file offset and size to the ModuleSpec. Also crc32 calculation
uses more data than the .so file size.

Set the .so file offset and size to the ModuleSpec, and set the size to
MapFileData length argument. For normal file, file_offset should be zero,
and length should be the size of the file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152757

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/CMakeLists.txt
  lldb/unittests/ObjectFile/ELF/Inputs/liboffset-test.so
  lldb/unittests/ObjectFile/ELF/Inputs/offset-test.bin
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, 
Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 3600);
+}
+
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
+  std::string SO = GetInputFilePath("offset-test.bin");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 1024, 3600,
+Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 1024);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640);
+}
+
 TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
   /*
   // nosym-entrypoint-arm-thumb.s
Index: lldb/unittests/ObjectFile/ELF/CMakeLists.txt
===
--- lldb/unittests/ObjectFile/ELF/CMakeLists.txt
+++ lldb/unittests/ObjectFile/ELF/CMakeLists.txt
@@ -11,5 +11,7 @@
 
 set(test_inputs
   early-section-headers.so
+  liboffset-test.so
+  offset-test.bin
   )
 add_unittest_inputs(ObjectFileELFTests "${test_inputs}")
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -555,6 +555,8 @@
 if (header.Parse(data, &header_offset)) {
   if (data_sp) {
 ModuleSpec spec(file);
+spec.SetObjectOffset(file_offset);
+spec.SetObjectSize(length);
 
 const uint32_t sub_type = subTypeFromElfHeader(header);
 spec.GetArchitecture().SetArchitecture(
@@ -587,7 +589,7 @@
   }
 
   if (data_sp->GetByteSize() < length)
-data_sp = MapFileData(file, -1, file_offset);
+data_sp = MapFileData(file, length, file_offset);
   if (data_sp)
 data.SetData(data_sp);
   // In case there is header extension in the section #0, the header we


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0);
+  EXPECT_EQ(Spec.GetObjectSi

[Lldb-commits] [PATCH] D152594: [lldb] Introduce DynamicRegisterInfo::CreateFromDict

2023-06-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 530720.
bulbazord added a comment.

Renamed from `CreateFromDict` to `Create` to be more consistent with the rest 
of LLDB


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152594

Files:
  lldb/include/lldb/Target/DynamicRegisterInfo.h
  lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Target/DynamicRegisterInfo.cpp


Index: lldb/source/Target/DynamicRegisterInfo.cpp
===
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -20,10 +20,17 @@
 using namespace lldb;
 using namespace lldb_private;
 
-DynamicRegisterInfo::DynamicRegisterInfo(
-const lldb_private::StructuredData::Dictionary &dict,
-const lldb_private::ArchSpec &arch) {
-  SetRegisterInfo(dict, arch);
+std::unique_ptr
+DynamicRegisterInfo::Create(const StructuredData::Dictionary &dict,
+const ArchSpec &arch) {
+  auto dyn_reg_info = std::make_unique();
+  if (!dyn_reg_info)
+return nullptr;
+
+  if (dyn_reg_info->SetRegisterInfo(dict, arch) == 0)
+return nullptr;
+
+  return dyn_reg_info;
 }
 
 DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) {
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -341,7 +341,7 @@
   LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers 
info.",
   error, LLDBLog::Thread);
 
-m_register_info_sp = std::make_shared(
+m_register_info_sp = DynamicRegisterInfo::Create(
 *reg_info, m_scripted_process.GetTarget().GetArchitecture());
   }
 
Index: lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
===
--- lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
+++ lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
@@ -128,8 +128,9 @@
 if (!dictionary)
   return nullptr;
 
-m_register_info_up = std::make_unique(
+m_register_info_up = DynamicRegisterInfo::Create(
 *dictionary, m_process->GetTarget().GetArchitecture());
+assert(m_register_info_up);
 assert(m_register_info_up->GetNumRegisters() > 0);
 assert(m_register_info_up->GetNumRegisterSets() > 0);
   }
Index: lldb/include/lldb/Target/DynamicRegisterInfo.h
===
--- lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -46,8 +46,8 @@
 
   DynamicRegisterInfo() = default;
 
-  DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
-  const lldb_private::ArchSpec &arch);
+  static std::unique_ptr
+  Create(const StructuredData::Dictionary &dict, const ArchSpec &arch);
 
   virtual ~DynamicRegisterInfo() = default;
 


Index: lldb/source/Target/DynamicRegisterInfo.cpp
===
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -20,10 +20,17 @@
 using namespace lldb;
 using namespace lldb_private;
 
-DynamicRegisterInfo::DynamicRegisterInfo(
-const lldb_private::StructuredData::Dictionary &dict,
-const lldb_private::ArchSpec &arch) {
-  SetRegisterInfo(dict, arch);
+std::unique_ptr
+DynamicRegisterInfo::Create(const StructuredData::Dictionary &dict,
+const ArchSpec &arch) {
+  auto dyn_reg_info = std::make_unique();
+  if (!dyn_reg_info)
+return nullptr;
+
+  if (dyn_reg_info->SetRegisterInfo(dict, arch) == 0)
+return nullptr;
+
+  return dyn_reg_info;
 }
 
 DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) {
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -341,7 +341,7 @@
   LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers info.",
   error, LLDBLog::Thread);
 
-m_register_info_sp = std::make_shared(
+m_register_info_sp = DynamicRegisterInfo::Create(
 *reg_info, m_scripted_process.GetTarget().GetArchitecture());
   }
 
Index: lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
===
--- lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
+++ lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
@@ -128,8 +128,9 @@
 if (!dictionary)
   r

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-12 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack created this revision.
Herald added subscribers: danielkiss, krytarowski.
Herald added a project: All.
splhack added reviewers: clayborg, labath, lanza, srhines.
splhack published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In Android API level 23 and above, dynamic loader is able to load .so file
directly from APK, which is zip file.
https://android.googlesource.com/platform/bionic/+/master/
android-changes-for-ndk-developers.md#
opening-shared-libraries-directly-from-an-apk

The .so file is page aligned and uncompressed, so
ObjectFileELF::GetModuleSpecifications works with .so file offset and size
directly from zip file without extracting it. (D152757 
)

GDBRemoteCommunicationServerCommon::GetModuleInfo returns a module spec to LLDB
with "zip_path!/so_path" file spec, which is passed through from Android
dynamic loader, and the .so file offset and size.

PlatformAndroid::DownloadModuleSlice uses 'shell dd' to download the .so file
slice from the zip file with the .so file offset and size.

Depends on D152494  and D152712 
 and D152757 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/android/HostInfoAndroid.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/android/HostInfoAndroid.cpp
  lldb/source/Host/android/ZipFile.cpp
  lldb/source/Host/android/ZipFile.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/android/CMakeLists.txt
  lldb/unittests/Host/android/HostInfoAndroidTest.cpp
  lldb/unittests/Host/android/Inputs/zip-test.zip

Index: lldb/unittests/Host/android/HostInfoAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/android/HostInfoAndroidTest.cpp
@@ -0,0 +1,67 @@
+//===-- HostInfoAndroidTest.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/Host/android/HostInfoAndroid.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class HostInfoAndroidTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(HostInfoAndroidTest, ResolveZipPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(HostInfoAndroid::ResolveZipPath(file_spec, file_path,
+  file_offset, file_size));
+
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(HostInfoAndroidTest, ResolveZipPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(HostInfoAndroid::ResolveZipPath(file_spec, file_path,
+   file_offset, file_size));
+}
+
+TEST_F(HostInfoAndroidTest, ResolveZipPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(HostInfoAndroid::ResolveZipPath(file_spec, file_path,
+  file_offset, file_size));
+
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/android/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/android/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  HostInfoAndroidTest.cpp
+)
+
+add_lldb_unittest(HostAndroidTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostAndroidTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38

[Lldb-commits] [PATCH] D152569: [lldb] Introduce a tool to quickly generate projects with an arbitrary number of sources

2023-06-12 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.



Comment at: lldb/scripts/generate-project.py:21
+def generate_c_header(directory: str, index: int) -> None:
+header_path = f"{directory}/obj{index}.h"
+with open(header_path, "w") as f:

os.path.join to be windows friendly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152569

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


[Lldb-commits] [PATCH] D152569: [lldb] Introduce a tool to quickly generate projects with an arbitrary number of sources

2023-06-12 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.



Comment at: lldb/scripts/generate-project.py:21
+def generate_c_header(directory: str, index: int) -> None:
+header_path = f"{directory}/obj{index}.h"
+with open(header_path, "w") as f:

kastiglione wrote:
> os.path.join to be windows friendly?
I just noticed the contents of the makefiles also have forward slashes, so I 
retract my comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152569

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


[Lldb-commits] [PATCH] D152594: [lldb] Introduce DynamicRegisterInfo::CreateFromDict

2023-06-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152594

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


[Lldb-commits] [PATCH] D152331: [lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory strings

2023-06-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere requested changes to this revision.
JDevlieghere added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/include/lldb/Interpreter/OptionGroupPlatform.h:52
 
-  void SetSDKRootDirectory(ConstString sdk_root_directory) {
-m_sdk_sysroot = sdk_root_directory;
+  void SetSDKRootDirectory(llvm::StringRef sdk_root_directory) {
+m_sdk_sysroot = sdk_root_directory.str();

This should take a std::string by value and move it.



Comment at: lldb/include/lldb/Interpreter/OptionGroupPlatform.h:58
 
-  void SetSDKBuild(ConstString sdk_build) { m_sdk_build = sdk_build; }
+  void SetSDKBuild(llvm::StringRef sdk_build) { m_sdk_build = sdk_build.str(); 
}
 

Same here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152331

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