[Lldb-commits] [lldb] 529e03e - [lldb] Remove named function arguments from TestQemuLaunch

2021-12-13 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2021-12-13T15:30:26+01:00
New Revision: 529e03ea650a8eb3327c697c9c930793ab54c0af

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

LOG: [lldb] Remove named function arguments from TestQemuLaunch

This is a swig-4 feature.

Added: 


Modified: 
lldb/test/API/qemu/TestQemuLaunch.py

Removed: 




diff  --git a/lldb/test/API/qemu/TestQemuLaunch.py 
b/lldb/test/API/qemu/TestQemuLaunch.py
index 54312495393ef..07d7cb6a82f9d 100644
--- a/lldb/test/API/qemu/TestQemuLaunch.py
+++ b/lldb/test/API/qemu/TestQemuLaunch.py
@@ -202,9 +202,9 @@ def cleanup():
 self.assertEqual(env.Get(var(3)), "from host")
 
 # Finally, make some launch_info specific changes.
-env.Set(var(2), "from target", overwrite=True)
+env.Set(var(2), "from target", True)
 env.Unset(var(3))
-info.SetEnvironment(env, append=False)
+info.SetEnvironment(env, False)
 
 # Now check everything. Launch info changes should trump everything, 
but
 # only for the target environment -- the emulator should still get the



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


[Lldb-commits] [PATCH] D115494: Add support to lldb for reading a "load binary" LC_NOTE with Mach-O corefiles

2021-12-13 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

LGTM assuming the change in TestFunctionStarts.py wasn't meant to be included.




Comment at: lldb/test/API/macosx/function-starts/TestFunctionStarts.py:68
 bkpt = target.BreakpointCreateByName("dont_strip_me", exe)
+self.runCmd("b dont_strip_me")
 self.assertTrue(bkpt.GetNumLocations() > 0, "Didn't set the 
dont_strip_me bkpt.")

Stray change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115494

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


[Lldb-commits] [PATCH] D115308: [LLDB] Uniquify Type in type list.

2021-12-13 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I don't know whether the types should be uniqued at this level (obviously, they 
should be uniqued somewhere), but these are the thoughts that spring to mind:

- if this is a problem for lldb-test, then it would be preferable to come up 
with a solution that does not negatively impact the performance and memory 
consumption of the production code
- it seems like this patch essentially implements its own copy of 
llvm::SetVector
- It's unfortunate to have set-like semanticts in TypeList, when we already 
have a type called TypeSet.




Comment at: lldb/test/Shell/SymbolFile/DWARF/x86/dump-types.cpp:3-13
+// RUN: %clang %s -g -c -o %t.o --target=x86_64-pc-linux -gno-pubnames
+// RUN: ld.lld %t.o -o %t
+// RUN: lldb-test symbols --find=none %t | FileCheck %s
+
+// RUN: %clang %s -g -c -o %t --target=x86_64-apple-macosx
+// RUN: lldb-test symbols --find=none %t | FileCheck %s
+

It doesn't seem necessary to run all three accelerator flavours for this kind 
of a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115308

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


[Lldb-commits] [PATCH] D115494: Add support to lldb for reading a "load binary" LC_NOTE with Mach-O corefiles

2021-12-13 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added inline comments.



Comment at: lldb/test/API/macosx/function-starts/TestFunctionStarts.py:68
 bkpt = target.BreakpointCreateByName("dont_strip_me", exe)
+self.runCmd("b dont_strip_me")
 self.assertTrue(bkpt.GetNumLocations() > 0, "Didn't set the 
dont_strip_me bkpt.")

DavidSpickett wrote:
> Stray change?
*cough* lol I was looking into a testsuite failure and forgot ;) 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115494

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


[Lldb-commits] [PATCH] D115201: [lldb] Move UpdateSymbolContextScopeForType

2021-12-13 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 added a comment.

In D115201#3176955 , @shafik wrote:

> Can you add a motivation for this to your summary, thank you!

I added some description to it. I don't think it is worth mentioning my work on 
upstreaming the D lldb plugin, but I'm doing some effort to decouple non-clang 
specific code from Clang DWARF Parser. I believe this is an important step to 
generalize and modularize Symbol File parsers for other languages.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115201

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


[Lldb-commits] [PATCH] D115652: [lldb/API] Add SetDataWithOwnership method to SBData

2021-12-13 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
Herald added a subscriber: yaxunl.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch introduces a new method to SBData: SetDataWithOwnership.

Instead of referencing the pointer to the data, this method copies the
data buffer into lldb's heap memory.

This can prevent having the underlying DataExtractor object point to
freed/garbage-collected memory.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115652

Files:
  lldb/bindings/interface/SBData.i
  lldb/include/lldb/API/SBData.h
  lldb/source/API/SBData.cpp
  lldb/test/API/python_api/sbdata/TestSBData.py


Index: lldb/test/API/python_api/sbdata/TestSBData.py
===
--- lldb/test/API/python_api/sbdata/TestSBData.py
+++ lldb/test/API/python_api/sbdata/TestSBData.py
@@ -39,6 +39,17 @@
 addr = data.GetAddress(error, 0)
 self.assertEqual(addr, 0x8877665544332211);
 
+def test_byte_order_and_address_byte_size_with_ownership(self):
+"""Test the SBData::SetDataWithOwnership() to ensure the byte order
+and address byte size are obeyed even when source date is released"""
+addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetDataWithOwnership(error, addr_data, lldb.eByteOrderBig, 8)
+del addr_data
+addr = data.GetAddress(error, 0)
+self.assertEqual(addr, 0x1122334455667788);
+
 def test_with_run_command(self):
 """Test the SBData APIs."""
 self.build()
Index: lldb/source/API/SBData.cpp
===
--- lldb/source/API/SBData.cpp
+++ lldb/source/API/SBData.cpp
@@ -374,6 +374,25 @@
   }
 }
 
+void SBData::SetDataWithOwnership(lldb::SBError &error, const void *buf,
+  size_t size, lldb::ByteOrder endian,
+  uint8_t addr_size) {
+  LLDB_RECORD_DUMMY(
+  void, SBData, SetData,
+  (lldb::SBError &, const void *, size_t, lldb::ByteOrder, uint8_t, bool),
+  error, buf, size, endian, addr_size, copy);
+
+  lldb::DataBufferSP buffer_sp = std::make_shared(buf, size);
+
+  if (!m_opaque_sp.get())
+m_opaque_sp = std::make_shared(buf, size, endian, 
addr_size);
+  else {
+m_opaque_sp->SetData(buffer_sp);
+m_opaque_sp->SetByteOrder(endian);
+m_opaque_sp->SetAddressByteSize(addr_size);
+  }
+}
+
 bool SBData::Append(const SBData &rhs) {
   LLDB_RECORD_METHOD(bool, SBData, Append, (const lldb::SBData &), rhs);
 
Index: lldb/include/lldb/API/SBData.h
===
--- lldb/include/lldb/API/SBData.h
+++ lldb/include/lldb/API/SBData.h
@@ -83,6 +83,9 @@
   void SetData(lldb::SBError &error, const void *buf, size_t size,
lldb::ByteOrder endian, uint8_t addr_size);
 
+  void SetDataWithOwnership(lldb::SBError &error, const void *buf, size_t size,
+lldb::ByteOrder endian, uint8_t addr_size);
+
   // see SetData() for why we don't have Append(const void* buf, size_t size)
   bool Append(const SBData &rhs);
 
Index: lldb/bindings/interface/SBData.i
===
--- lldb/bindings/interface/SBData.i
+++ lldb/bindings/interface/SBData.i
@@ -96,6 +96,10 @@
 void
 SetData (lldb::SBError& error, const void *buf, size_t size, 
lldb::ByteOrder endian, uint8_t addr_size);
 
+void
+SetDataWithOwnership (lldb::SBError& error, const void *buf, size_t size,
+  lldb::ByteOrder endian, uint8_t addr_size);
+
 bool
 Append (const SBData& rhs);
 


Index: lldb/test/API/python_api/sbdata/TestSBData.py
===
--- lldb/test/API/python_api/sbdata/TestSBData.py
+++ lldb/test/API/python_api/sbdata/TestSBData.py
@@ -39,6 +39,17 @@
 addr = data.GetAddress(error, 0)
 self.assertEqual(addr, 0x8877665544332211);
 
+def test_byte_order_and_address_byte_size_with_ownership(self):
+"""Test the SBData::SetDataWithOwnership() to ensure the byte order
+and address byte size are obeyed even when source date is released"""
+addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetDataWithOwnership(error, addr_data, lldb.eByteOrderBig, 8)
+del addr_data
+addr = data.GetAddress(error, 0)
+self.assertEqual(addr, 0x1122334455667788);
+
 def test_with_run_command(self):
 """Test the SBData APIs."""
 self.build()
Index: lldb/source/API/SBData.cpp
===
--- lldb/source/API/SBData.cpp
+++ lldb/source/API/SBData.cpp
@

[Lldb-commits] [PATCH] D115126: [LLDB] Add unit tests for Editline keyboard shortcuts

2021-12-13 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/include/lldb/Host/Editline.h:392-393
+
+  friend class EditlineKeyboardBindingTest_MultiLineEditlineKeybindings_Test;
+  friend class EditlineKeyboardBindingTest_SingleLineEditlineKeybindings_Test;
 };

This also isn't something we normally do. I'd recommend just making a function 
like `DumpKeyBindings()` or something. It's true that it would only be used in 
tests right now, but I can imagine some day adding an lldb command to dump 
current bindings, so it does not seem completely out of place. If you wanted 
to, you could even add it right now and do your test that way.



Comment at: lldb/unittests/Editline/EditlineTest.cpp:86
 
+  const std::string GetEditlineOutput();
+

const on a return value is useless



Comment at: lldb/unittests/Editline/EditlineTest.cpp:133-139
+  // We have to set the output stream we pass to Editline as not using
+  // buffered I/O.  Otherwise we are missing editline's output when we
+  // close the stream in the keybinding test (i.e. the EOF comes
+  // before data previously written to the stream by editline).  This
+  // behavior isn't as I understand the spec becuse fclose should
+  // flush the stream, but my best guess is that it's some unexpected
+  // interaction with stream I/O and ptys.

nealsid wrote:
> labath wrote:
> > I find this hard to believe. I think it's more likely that this is working 
> > around some problem in the test itself. I can't say what is the precise 
> > problem without more investigation, but for example the synchronization 
> > around testOutputBuffer seems inadequate. `GetEditlineOutput` could 
> > deadlock if the read thread reads the newline before it reaches the `wait` 
> > call. It also does not handle spurious wakeups. And the accesses to 
> > testOutputBuffer are completely thread-unsafe.
> I spent a few hours on this before sending the initial patch; it may be some 
> interaction with the file APIs and the Psuedoterminal class we have in LLVM.  
> I could not debug anything it was doing that was leading to this behavior, 
> but reliably saw EOF being sent before data that had been written to the 
> stream.  I also tried various things like flushing it manually, which did not 
> work, but sleeping before closing the secondary FD enabled all data to be 
> read on the test side.  If you have some time, I'd be happy to have a gchat 
> or screen sharing session and see if we can brainstorm something.
> 
> Regarding the synchronization, good call; I built on top of the existing 
> threading, which did not require synchronizing reading the output of 
> editline, because the actual output was never used.  Now, I just call provide 
> a method to call thread::join for tests that need to read the output to 
> ensure it's all been written.  
Well.. I tried running this locally, and the test passed just fine even with 
this code deleted. I don't think we should commit code like this without 
understanding the problem in more detail. (Like, if it's a problem with llvm 
code, then lets fix that; if it's a problem with libc code (I doubt that), then 
let's file a bug before working around it.)If you want to discuss this in a 
more interactive fashion, you can find me on the `#lldb` channel @ irc.oftc.net.



Comment at: lldb/unittests/Editline/EditlineTest.cpp:345
+  // mapped back to a specific input.
+  const std::string testNumber;
+  // Whether this keyboard shortcut is only bound in multi-line mode.

nealsid wrote:
> labath wrote:
> > You already have a const on the variable declaration. You don't need to put 
> > one on every member as well.
> I like const on the struct fields since it expresses the intent (a 
> compile-time data structure) better, and, without it, if the array variable 
> decl type was changed to remove the const, modifying the fields would be 
> permitted.
Well, we definitely have have different views on redundancy. I could write a 
PhD thesis on why I think this is wrong, but right now, let me just say this: 
it isn't consistent with how we define const structs anywhere else in llvm or 
lldb. Here's some examples: 
,
 
,
 
.
 (Full disclosure: I wrote the last two; while searching for examples, I also 
found a lot patterns like this which did not have any const annotation 
whatsoever.)



Comment at: lldb/unittests/Editline/EditlineTest.cpp:352-359
+  // This is initialized to the keySequence by default, but gtest has
+  /

[Lldb-commits] [PATCH] D115654: [lldb/plugin] Fix heap-use-after-free in ScriptedProcess::ReadMemory

2021-12-13 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: JDevlieghere, aprantl.
mib added a project: LLDB.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This commit should fix a heap-use-after-free bug that was caught by the
sanitizer bot.

The issue is that we were reading memory from a second target into a
`SBData` object in Python, that was passed to lldb's internal
`ScriptedProcess::DoReadMemory` C++ method.

The ScriptedPythonInterface then extracts the underlying `DataExtractor`
from the `SBData` object, and is used to read the memory with the
appropriate address size and byte order.

Unfortunately, it seems that even though the DataExtractor object was
still valid, it pointed to invalid, possibly garbage-collected memory
from Python.

To mitigate this, the patch uses `SBData::SetDataWithOwnership` to copy
the pointed buffer to lldb's heap memory which prevents the
use-after-free error.

rdar://84511405

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115654

Files:
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py


Index: 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -43,8 +43,9 @@
 if error.Fail():
 return data
 
-data.SetData(error, bytes_read, self.corefile_target.GetByteOrder(),
-self.corefile_target.GetAddressByteSize())
+data.SetDataWithOwnership(error, bytes_read,
+  self.corefile_target.GetByteOrder(),
+  self.corefile_target.GetAddressByteSize())
 
 return data
 
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -139,7 +139,6 @@
 
 @skipUnlessDarwin
 @skipIfOutOfTreeDebugserver
-@skipIfAsan # rdar://85954489
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""


Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -43,8 +43,9 @@
 if error.Fail():
 return data
 
-data.SetData(error, bytes_read, self.corefile_target.GetByteOrder(),
-self.corefile_target.GetAddressByteSize())
+data.SetDataWithOwnership(error, bytes_read,
+  self.corefile_target.GetByteOrder(),
+  self.corefile_target.GetAddressByteSize())
 
 return data
 
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -139,7 +139,6 @@
 
 @skipUnlessDarwin
 @skipIfOutOfTreeDebugserver
-@skipIfAsan # rdar://85954489
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115652: [lldb/API] Add SetDataWithOwnership method to SBData

2021-12-13 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/D115652/new/

https://reviews.llvm.org/D115652

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


[Lldb-commits] [PATCH] D115654: [lldb/plugin] Fix heap-use-after-free in ScriptedProcess::ReadMemory

2021-12-13 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/D115654/new/

https://reviews.llvm.org/D115654

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


[Lldb-commits] [lldb] 72e2597 - [lldb/API] Add SetDataWithOwnership method to SBData

2021-12-13 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2021-12-13T11:05:06-08:00
New Revision: 72e25978f93f0bf7577593aba9591c727526423c

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

LOG: [lldb/API] Add SetDataWithOwnership method to SBData

This patch introduces a new method to SBData: SetDataWithOwnership.

Instead of referencing the pointer to the data, this method copies the
data buffer into lldb's heap memory.

This can prevent having the underlying DataExtractor object point to
freed/garbage-collected memory.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/bindings/interface/SBData.i
lldb/include/lldb/API/SBData.h
lldb/source/API/SBData.cpp
lldb/test/API/python_api/sbdata/TestSBData.py

Removed: 




diff  --git a/lldb/bindings/interface/SBData.i 
b/lldb/bindings/interface/SBData.i
index a1fb4472cd234..1f2f9fbf05e2d 100644
--- a/lldb/bindings/interface/SBData.i
+++ b/lldb/bindings/interface/SBData.i
@@ -96,6 +96,10 @@ public:
 void
 SetData (lldb::SBError& error, const void *buf, size_t size, 
lldb::ByteOrder endian, uint8_t addr_size);
 
+void
+SetDataWithOwnership (lldb::SBError& error, const void *buf, size_t size,
+  lldb::ByteOrder endian, uint8_t addr_size);
+
 bool
 Append (const SBData& rhs);
 

diff  --git a/lldb/include/lldb/API/SBData.h b/lldb/include/lldb/API/SBData.h
index 85c8110e181c2..89a699f2f713a 100644
--- a/lldb/include/lldb/API/SBData.h
+++ b/lldb/include/lldb/API/SBData.h
@@ -83,6 +83,9 @@ class LLDB_API SBData {
   void SetData(lldb::SBError &error, const void *buf, size_t size,
lldb::ByteOrder endian, uint8_t addr_size);
 
+  void SetDataWithOwnership(lldb::SBError &error, const void *buf, size_t size,
+lldb::ByteOrder endian, uint8_t addr_size);
+
   // see SetData() for why we don't have Append(const void* buf, size_t size)
   bool Append(const SBData &rhs);
 

diff  --git a/lldb/source/API/SBData.cpp b/lldb/source/API/SBData.cpp
index daf313ad55c99..9fc590578bceb 100644
--- a/lldb/source/API/SBData.cpp
+++ b/lldb/source/API/SBData.cpp
@@ -374,6 +374,25 @@ void SBData::SetData(lldb::SBError &error, const void 
*buf, size_t size,
   }
 }
 
+void SBData::SetDataWithOwnership(lldb::SBError &error, const void *buf,
+  size_t size, lldb::ByteOrder endian,
+  uint8_t addr_size) {
+  LLDB_RECORD_DUMMY(
+  void, SBData, SetData,
+  (lldb::SBError &, const void *, size_t, lldb::ByteOrder, uint8_t, bool),
+  error, buf, size, endian, addr_size, copy);
+
+  lldb::DataBufferSP buffer_sp = std::make_shared(buf, size);
+
+  if (!m_opaque_sp.get())
+m_opaque_sp = std::make_shared(buf, size, endian, 
addr_size);
+  else {
+m_opaque_sp->SetData(buffer_sp);
+m_opaque_sp->SetByteOrder(endian);
+m_opaque_sp->SetAddressByteSize(addr_size);
+  }
+}
+
 bool SBData::Append(const SBData &rhs) {
   LLDB_RECORD_METHOD(bool, SBData, Append, (const lldb::SBData &), rhs);
 

diff  --git a/lldb/test/API/python_api/sbdata/TestSBData.py 
b/lldb/test/API/python_api/sbdata/TestSBData.py
index b845c0abd734d..1b20cf205e63d 100644
--- a/lldb/test/API/python_api/sbdata/TestSBData.py
+++ b/lldb/test/API/python_api/sbdata/TestSBData.py
@@ -39,6 +39,17 @@ def test_byte_order_and_address_byte_size(self):
 addr = data.GetAddress(error, 0)
 self.assertEqual(addr, 0x8877665544332211);
 
+def test_byte_order_and_address_byte_size_with_ownership(self):
+"""Test the SBData::SetDataWithOwnership() to ensure the byte order
+and address byte size are obeyed even when source date is released"""
+addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetDataWithOwnership(error, addr_data, lldb.eByteOrderBig, 8)
+del addr_data
+addr = data.GetAddress(error, 0)
+self.assertEqual(addr, 0x1122334455667788);
+
 def test_with_run_command(self):
 """Test the SBData APIs."""
 self.build()



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


[Lldb-commits] [lldb] ef74c80 - [lldb/plugin] Fix heap-use-after-free in ScriptedProcess::ReadMemory

2021-12-13 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2021-12-13T11:05:07-08:00
New Revision: ef74c8002ae86d95fd9d1927233102aac52d769c

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

LOG: [lldb/plugin] Fix heap-use-after-free in ScriptedProcess::ReadMemory

This commit should fix a heap-use-after-free bug that was caught by the
sanitizer bot.

The issue is that we were reading memory from a second target into a
`SBData` object in Python, that was passed to lldb's internal
`ScriptedProcess::DoReadMemory` C++ method.

The ScriptedPythonInterface then extracts the underlying `DataExtractor`
from the `SBData` object, and is used to read the memory with the
appropriate address size and byte order.

Unfortunately, it seems that even though the DataExtractor object was
still valid, it pointed to invalid, possibly garbage-collected memory
from Python.

To mitigate this, the patch uses `SBData::SetDataWithOwnership` to copy
the pointed buffer to lldb's heap memory which prevents the
use-after-free error.

rdar://84511405

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py 
b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index 603dc7fa6c128..2a5eff3122145 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -139,7 +139,6 @@ def create_stack_skinny_corefile(self, file):
 
 @skipUnlessDarwin
 @skipIfOutOfTreeDebugserver
-@skipIfAsan # rdar://85954489
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""

diff  --git 
a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py 
b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
index 7c3e069d22505..da7c69ee7b993 100644
--- 
a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ 
b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -43,8 +43,9 @@ def read_memory_at_address(self, addr: int, size: int) -> 
lldb.SBData:
 if error.Fail():
 return data
 
-data.SetData(error, bytes_read, self.corefile_target.GetByteOrder(),
-self.corefile_target.GetAddressByteSize())
+data.SetDataWithOwnership(error, bytes_read,
+  self.corefile_target.GetByteOrder(),
+  self.corefile_target.GetAddressByteSize())
 
 return data
 



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


[Lldb-commits] [PATCH] D115652: [lldb/API] Add SetDataWithOwnership method to SBData

2021-12-13 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72e25978f93f: [lldb/API] Add SetDataWithOwnership method to 
SBData (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115652

Files:
  lldb/bindings/interface/SBData.i
  lldb/include/lldb/API/SBData.h
  lldb/source/API/SBData.cpp
  lldb/test/API/python_api/sbdata/TestSBData.py


Index: lldb/test/API/python_api/sbdata/TestSBData.py
===
--- lldb/test/API/python_api/sbdata/TestSBData.py
+++ lldb/test/API/python_api/sbdata/TestSBData.py
@@ -39,6 +39,17 @@
 addr = data.GetAddress(error, 0)
 self.assertEqual(addr, 0x8877665544332211);
 
+def test_byte_order_and_address_byte_size_with_ownership(self):
+"""Test the SBData::SetDataWithOwnership() to ensure the byte order
+and address byte size are obeyed even when source date is released"""
+addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetDataWithOwnership(error, addr_data, lldb.eByteOrderBig, 8)
+del addr_data
+addr = data.GetAddress(error, 0)
+self.assertEqual(addr, 0x1122334455667788);
+
 def test_with_run_command(self):
 """Test the SBData APIs."""
 self.build()
Index: lldb/source/API/SBData.cpp
===
--- lldb/source/API/SBData.cpp
+++ lldb/source/API/SBData.cpp
@@ -374,6 +374,25 @@
   }
 }
 
+void SBData::SetDataWithOwnership(lldb::SBError &error, const void *buf,
+  size_t size, lldb::ByteOrder endian,
+  uint8_t addr_size) {
+  LLDB_RECORD_DUMMY(
+  void, SBData, SetData,
+  (lldb::SBError &, const void *, size_t, lldb::ByteOrder, uint8_t, bool),
+  error, buf, size, endian, addr_size, copy);
+
+  lldb::DataBufferSP buffer_sp = std::make_shared(buf, size);
+
+  if (!m_opaque_sp.get())
+m_opaque_sp = std::make_shared(buf, size, endian, 
addr_size);
+  else {
+m_opaque_sp->SetData(buffer_sp);
+m_opaque_sp->SetByteOrder(endian);
+m_opaque_sp->SetAddressByteSize(addr_size);
+  }
+}
+
 bool SBData::Append(const SBData &rhs) {
   LLDB_RECORD_METHOD(bool, SBData, Append, (const lldb::SBData &), rhs);
 
Index: lldb/include/lldb/API/SBData.h
===
--- lldb/include/lldb/API/SBData.h
+++ lldb/include/lldb/API/SBData.h
@@ -83,6 +83,9 @@
   void SetData(lldb::SBError &error, const void *buf, size_t size,
lldb::ByteOrder endian, uint8_t addr_size);
 
+  void SetDataWithOwnership(lldb::SBError &error, const void *buf, size_t size,
+lldb::ByteOrder endian, uint8_t addr_size);
+
   // see SetData() for why we don't have Append(const void* buf, size_t size)
   bool Append(const SBData &rhs);
 
Index: lldb/bindings/interface/SBData.i
===
--- lldb/bindings/interface/SBData.i
+++ lldb/bindings/interface/SBData.i
@@ -96,6 +96,10 @@
 void
 SetData (lldb::SBError& error, const void *buf, size_t size, 
lldb::ByteOrder endian, uint8_t addr_size);
 
+void
+SetDataWithOwnership (lldb::SBError& error, const void *buf, size_t size,
+  lldb::ByteOrder endian, uint8_t addr_size);
+
 bool
 Append (const SBData& rhs);
 


Index: lldb/test/API/python_api/sbdata/TestSBData.py
===
--- lldb/test/API/python_api/sbdata/TestSBData.py
+++ lldb/test/API/python_api/sbdata/TestSBData.py
@@ -39,6 +39,17 @@
 addr = data.GetAddress(error, 0)
 self.assertEqual(addr, 0x8877665544332211);
 
+def test_byte_order_and_address_byte_size_with_ownership(self):
+"""Test the SBData::SetDataWithOwnership() to ensure the byte order
+and address byte size are obeyed even when source date is released"""
+addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetDataWithOwnership(error, addr_data, lldb.eByteOrderBig, 8)
+del addr_data
+addr = data.GetAddress(error, 0)
+self.assertEqual(addr, 0x1122334455667788);
+
 def test_with_run_command(self):
 """Test the SBData APIs."""
 self.build()
Index: lldb/source/API/SBData.cpp
===
--- lldb/source/API/SBData.cpp
+++ lldb/source/API/SBData.cpp
@@ -374,6 +374,25 @@
   }
 }
 
+void SBData::SetDataWithOwnership(lldb::SBError &error, const void *buf,
+  size_t size, lldb::ByteOrder endian,
+  uint8_t addr_size) {
+  LLDB_RECORD_DUMMY(
+  void, SBData, 

[Lldb-commits] [PATCH] D115654: [lldb/plugin] Fix heap-use-after-free in ScriptedProcess::ReadMemory

2021-12-13 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef74c8002ae8: [lldb/plugin] Fix heap-use-after-free in 
ScriptedProcess::ReadMemory (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115654

Files:
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py


Index: 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -43,8 +43,9 @@
 if error.Fail():
 return data
 
-data.SetData(error, bytes_read, self.corefile_target.GetByteOrder(),
-self.corefile_target.GetAddressByteSize())
+data.SetDataWithOwnership(error, bytes_read,
+  self.corefile_target.GetByteOrder(),
+  self.corefile_target.GetAddressByteSize())
 
 return data
 
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -139,7 +139,6 @@
 
 @skipUnlessDarwin
 @skipIfOutOfTreeDebugserver
-@skipIfAsan # rdar://85954489
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""


Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -43,8 +43,9 @@
 if error.Fail():
 return data
 
-data.SetData(error, bytes_read, self.corefile_target.GetByteOrder(),
-self.corefile_target.GetAddressByteSize())
+data.SetDataWithOwnership(error, bytes_read,
+  self.corefile_target.GetByteOrder(),
+  self.corefile_target.GetAddressByteSize())
 
 return data
 
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -139,7 +139,6 @@
 
 @skipUnlessDarwin
 @skipIfOutOfTreeDebugserver
-@skipIfAsan # rdar://85954489
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 82d6a96 - disable test on older compilers

2021-12-13 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2021-12-13T11:59:05-08:00
New Revision: 82d6a96e129e959f78173a4ad5d165380f98d3f5

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

LOG: disable test on older compilers

Added: 


Modified: 

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/multimap/TestDataFormatterGenericMultiMap.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/multimap/TestDataFormatterGenericMultiMap.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/multimap/TestDataFormatterGenericMultiMap.py
index 62cd06b421fe4..6a6ad26c9cfdd 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/multimap/TestDataFormatterGenericMultiMap.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/multimap/TestDataFormatterGenericMultiMap.py
@@ -328,9 +328,11 @@ def cleanup():
 self.check("ss", 0)
 
 @add_test_categories(["libstdcxx"])
+@skipIf(compiler="clang", compiler_version=['<', '9.0'])
 def test_with_run_command_libstdcpp(self):
 self.do_test_with_run_command(USE_LIBSTDCPP)
 
+@skipIf(compiler="clang", compiler_version=['<', '9.0'])
 @add_test_categories(["libc++"])
 def test_with_run_command_libcpp(self):
 self.do_test_with_run_command(USE_LIBCPP)



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


[Lldb-commits] [PATCH] D114791: [lldb] Clarify StructuredDataImpl ownership

2021-12-13 Thread Pavel Labath via Phabricator via lldb-commits
labath marked an inline comment as done.
labath added inline comments.



Comment at: lldb/bindings/lua/lua-wrapper.swig:31
lldb::BreakpointLocationSP bp_loc_sp,
StructuredDataImpl *extra_args_impl
 )

mib wrote:
> May be we should keep consistency with the `python-wrapper.swig` definition ?
Good point. This actually uncovered that I was now leaking this 
StructuredDataImpl object.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114791

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


[Lldb-commits] [lldb] 82de8df - [lldb] Clarify StructuredDataImpl ownership

2021-12-13 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2021-12-13T21:04:51+01:00
New Revision: 82de8df26f15778793dc6b1526e14779f435f2e1

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

LOG: [lldb] Clarify StructuredDataImpl ownership

StructuredDataImpl ownership semantics is unclear at best. Various
structures were holding a non-owning pointer to it, with a comment that
the object is owned somewhere else. From what I was able to gather that
"somewhere else" was the SBStructuredData object, but I am not sure that
all created object eventually made its way there. (It wouldn't matter
even if they did, as we are leaking most of our SBStructuredData
objects.)

Since StructuredDataImpl is just a collection of two (shared) pointers,
there's really no point in elaborate lifetime management, so this patch
replaces all StructuredDataImpl pointers with actual objects or
unique_ptrs to it. This makes it much easier to resolve SBStructuredData
leaks in a follow-up patch.

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

Added: 


Modified: 
lldb/bindings/lua/lua-wrapper.swig
lldb/bindings/python/python-wrapper.swig
lldb/include/lldb/API/SBStructuredData.h
lldb/include/lldb/Breakpoint/BreakpointResolverScripted.h
lldb/include/lldb/Core/StructuredDataImpl.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/include/lldb/Target/Target.h
lldb/include/lldb/Target/ThreadPlanPython.h
lldb/source/API/SBStructuredData.cpp
lldb/source/API/SBThreadPlan.cpp
lldb/source/Breakpoint/BreakpointResolverScripted.cpp
lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
lldb/source/Target/Target.cpp
lldb/source/Target/Thread.cpp
lldb/source/Target/ThreadPlanPython.cpp
lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Removed: 




diff  --git a/lldb/bindings/lua/lua-wrapper.swig 
b/lldb/bindings/lua/lua-wrapper.swig
index 4ca406137d6cf..9e4b8d1224bd2 100644
--- a/lldb/bindings/lua/lua-wrapper.swig
+++ b/lldb/bindings/lua/lua-wrapper.swig
@@ -11,23 +11,21 @@ lldb_private::LLDBSwigLuaBreakpointCallbackFunction
lua_State *L,
lldb::StackFrameSP stop_frame_sp,
lldb::BreakpointLocationSP bp_loc_sp,
-   StructuredDataImpl *extra_args_impl
+   const StructuredDataImpl &extra_args_impl
 )
 {
lldb::SBFrame sb_frame(stop_frame_sp);
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
int nargs = 2;
 
-   llvm::Optional extra_args;
-   if (extra_args_impl)
-  extra_args = lldb::SBStructuredData(extra_args_impl);
+   lldb::SBStructuredData extra_args(extra_args_impl);
 
// Push the Lua wrappers
PushSBClass(L, &sb_frame);
PushSBClass(L, &sb_bp_loc);
 
-   if (extra_args.hasValue()) {
-  PushSBClass(L, extra_args.getPointer());
+   if (extra_args.IsValid()) {
+  PushSBClass(L, &extra_args);
   nargs++;
}
 

diff  --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 079f8d12dafab..da943f73c4351 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -29,7 +29,7 @@ lldb_private::LLDBSwigPythonBreakpointCallbackFunction
 const char *session_dictionary_name,
 const lldb::StackFrameSP& frame_sp,
 const lldb::BreakpointLocationSP& bp_loc_sp,
-lldb_private::StructuredDataImpl *args_impl
+const lldb_private::StructuredDataImpl &args_impl
 )
 {
 using namespace llvm;
@@ -254,7 +254,7 @@ lldb_private::LLDBSwigPythonCreateScriptedProcess
 const char *python_class_name,
 const char *session_dictionary_name,
 const lldb::TargetSP& target_sp,
-lldb_private::StructuredDataImpl *args_impl,
+const lldb_private::StructuredDataImpl &args_impl,
 std::string &error_string
 )
 {
@@ -290,7 +290,9 @@ lldb_private::LLDBSwigPythonCreateScriptedProcess
 PythonObject result = {};
 if (arg_info.get().max_positional_args == 2) {
 // FIXME: SBStructuredData leaked here
-PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*new 
lldb::SBStructuredData(args_impl)));
+PythonObject args_arg(
+PyRefType::Owned,
+SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
 

[Lldb-commits] [PATCH] D114791: [lldb] Clarify StructuredDataImpl ownership

2021-12-13 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.
Closed by commit rG82de8df26f15: [lldb] Clarify StructuredDataImpl ownership 
(authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D114791?vs=390672&id=393996#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114791

Files:
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBStructuredData.h
  lldb/include/lldb/Breakpoint/BreakpointResolverScripted.h
  lldb/include/lldb/Core/StructuredDataImpl.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Target/Target.h
  lldb/include/lldb/Target/ThreadPlanPython.h
  lldb/source/API/SBStructuredData.cpp
  lldb/source/API/SBThreadPlan.cpp
  lldb/source/Breakpoint/BreakpointResolverScripted.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/Thread.cpp
  lldb/source/Target/ThreadPlanPython.cpp
  lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -63,7 +63,7 @@
 const char *python_function_name, const char *session_dictionary_name,
 const lldb::StackFrameSP &sb_frame,
 const lldb::BreakpointLocationSP &sb_bp_loc,
-StructuredDataImpl *args_impl) {
+const StructuredDataImpl &args_impl) {
   return false;
 }
 
@@ -94,7 +94,7 @@
 
 void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
 const char *python_class_name, const char *session_dictionary_name,
-StructuredDataImpl *args_data, std::string &error_string,
+const StructuredDataImpl &args_data, std::string &error_string,
 const lldb::ThreadPlanSP &thread_plan_sp) {
   return nullptr;
 }
@@ -108,7 +108,7 @@
 
 void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
 const char *python_class_name, const char *session_dictionary_name,
-lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp) {
+const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
   return nullptr;
 }
 
@@ -200,14 +200,14 @@
 
 void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
 const char *python_class_name, const char *session_dictionary_name,
-const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl,
+const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
 std::string &error_string) {
   return nullptr;
 }
 
 void *lldb_private::LLDBSwigPythonCreateScriptedThread(
 const char *python_class_name, const char *session_dictionary_name,
-const lldb::ProcessSP &process_sp, StructuredDataImpl *args_impl,
+const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
 std::string &error_string) {
   return nullptr;
 }
@@ -259,8 +259,8 @@
 
 void *lldb_private::LLDBSwigPythonCreateScriptedStopHook(
 lldb::TargetSP target_sp, const char *python_class_name,
-const char *session_dictionary_name,
-lldb_private::StructuredDataImpl *args_impl, Status &error) {
+const char *session_dictionary_name, const StructuredDataImpl &args_impl,
+Status &error) {
   return nullptr;
 }
 
Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
===
--- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
+++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
@@ -16,7 +16,8 @@
 
 llvm::Expected lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
 lua_State *L, lldb::StackFrameSP stop_frame_sp,
-lldb::BreakpointLocationSP bp_loc_sp, StructuredDataImpl *extra_args_impl) {
+lldb::BreakpointLocationSP bp_loc_sp,
+const StructuredDataImpl &extra_args_impl) {
   return false;
 }
 
Index: lldb/source/Target/ThreadPlanPython.cpp
===
--- lldb/source/Target/ThreadPlanPython.cpp
+++ lldb/source/Target/ThreadPlanPython.cpp
@@ -26,7 +26,7 @@
 // ThreadPlanPython
 
 ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
-   StructuredDataImpl *a

[Lldb-commits] [PATCH] D113604: [lldb][NFC] Format lldb/include/lldb/Symbol/Type.h

2021-12-13 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 updated this revision to Diff 394001.

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

https://reviews.llvm.org/D113604

Files:
  lldb/include/lldb/Symbol/Type.h
  lldb/source/Symbol/Type.cpp


Index: lldb/source/Symbol/Type.cpp
===
--- lldb/source/Symbol/Type.cpp
+++ lldb/source/Symbol/Type.cpp
@@ -662,7 +662,7 @@
   return GetForwardCompilerType().GetTypeName();
 }
 
-bool Type::GetTypeScopeAndBasename(const llvm::StringRef& name,
+bool Type::GetTypeScopeAndBasename(llvm::StringRef name,
llvm::StringRef &scope,
llvm::StringRef &basename,
TypeClass &type_class) {
Index: lldb/include/lldb/Symbol/Type.h
===
--- lldb/include/lldb/Symbol/Type.h
+++ lldb/include/lldb/Symbol/Type.h
@@ -67,23 +67,27 @@
 public:
   enum EncodingDataType {
 eEncodingInvalid,
-eEncodingIsUID,  ///< This type is the type whose UID is m_encoding_uid
-eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid
- /// with the const qualifier added
-eEncodingIsRestrictUID, ///< This type is the type whose UID is
-/// m_encoding_uid with the restrict qualifier 
added
-eEncodingIsVolatileUID, ///< This type is the type whose UID is
-/// m_encoding_uid with the volatile qualifier 
added
-eEncodingIsTypedefUID,  ///< This type is pointer to a type whose UID is
-/// m_encoding_uid
-eEncodingIsPointerUID,  ///< This type is pointer to a type whose UID is
-/// m_encoding_uid
-eEncodingIsLValueReferenceUID, ///< This type is L value reference to a 
type
-   /// whose UID is m_encoding_uid
-eEncodingIsRValueReferenceUID, ///< This type is R value reference to a 
type
-   /// whose UID is m_encoding_uid,
-eEncodingIsAtomicUID,  ///< This type is the type whose UID is
-   /// m_encoding_uid as an atomic type.
+/// This type is the type whose UID is m_encoding_uid.
+eEncodingIsUID,
+/// This type is the type whose UID is m_encoding_uid with the const
+/// qualifier added.
+eEncodingIsConstUID,
+/// This type is the type whose UID is m_encoding_uid with the restrict
+/// qualifier added.
+eEncodingIsRestrictUID,
+/// This type is the type whose UID is m_encoding_uid with the volatile
+/// qualifier added.
+eEncodingIsVolatileUID,
+/// This type is pointer to a type whose UID is m_encoding_uid.
+eEncodingIsTypedefUID,
+/// This type is pointer to a type whose UID is m_encoding_uid.
+eEncodingIsPointerUID,
+/// This type is L value reference to a type whose UID is m_encoding_uid.
+eEncodingIsLValueReferenceUID,
+/// This type is R value reference to a type whose UID is m_encoding_uid.
+eEncodingIsRValueReferenceUID,
+/// This type is the type whose UID is m_encoding_uid as an atomic type.
+eEncodingIsAtomicUID,
 eEncodingIsSyntheticUID
   };
 
@@ -197,7 +201,7 @@
 
   // From a fully qualified typename, split the type into the type basename and
   // the remaining type scope (namespaces/classes).
-  static bool GetTypeScopeAndBasename(const llvm::StringRef& name,
+  static bool GetTypeScopeAndBasename(llvm::StringRef name,
   llvm::StringRef &scope,
   llvm::StringRef &basename,
   lldb::TypeClass &type_class);
@@ -473,8 +477,8 @@
 public:
   TypeEnumMemberImpl() : m_integer_type_sp(), m_name(""), m_value() {}
 
-  TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp,
- ConstString name, const llvm::APSInt &value);
+  TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp, ConstString name,
+ const llvm::APSInt &value);
 
   TypeEnumMemberImpl(const TypeEnumMemberImpl &rhs) = default;
 


Index: lldb/source/Symbol/Type.cpp
===
--- lldb/source/Symbol/Type.cpp
+++ lldb/source/Symbol/Type.cpp
@@ -662,7 +662,7 @@
   return GetForwardCompilerType().GetTypeName();
 }
 
-bool Type::GetTypeScopeAndBasename(const llvm::StringRef& name,
+bool Type::GetTypeScopeAndBasename(llvm::StringRef name,
llvm::StringRef &scope,
llvm::StringRef &basename,
TypeClass &type_class) {
Index: lldb/include/lldb/Symbol/Type.h
===
--- lldb/include/lldb/Symbol/Type.h
+++ lldb/include/lldb/Symbol/Type.h
@@ -67,23 +67,27 @@
 public:
   enum EncodingDataType {
 

[Lldb-commits] [PATCH] D113604: [lldb][NFC] Format lldb/include/lldb/Symbol/Type.h

2021-12-13 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 added a comment.

Sorry for the delay. Can you re-review this @dblaikie ?


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

https://reviews.llvm.org/D113604

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


[Lldb-commits] [PATCH] D115662: [lldb][DWARF] Remove duplicate DIE type assignment

2021-12-13 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 created this revision.
Herald added a reviewer: shafik.
ljmf00 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

  This assignment is already being done via UpdateSymbolContextScopeForType
  routine at the end of the type parsing function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115662

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -764,7 +764,6 @@
   dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl,
   clang_type, resolve_state, TypePayloadClang(GetOwningClangModule(die)));
 
-  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
   return type_sp;
 }
 


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -764,7 +764,6 @@
   dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl,
   clang_type, resolve_state, TypePayloadClang(GetOwningClangModule(die)));
 
-  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
   return type_sp;
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115126: [LLDB] Add unit tests for Editline keyboard shortcuts

2021-12-13 Thread Neal via Phabricator via lldb-commits
nealsid added a comment.

Thanks, Pavel.  Some comments responded to, will take another look at the 
buffered/unbuffered I/O issue and address the remaining comments.




Comment at: lldb/include/lldb/Host/Editline.h:392-393
+
+  friend class EditlineKeyboardBindingTest_MultiLineEditlineKeybindings_Test;
+  friend class EditlineKeyboardBindingTest_SingleLineEditlineKeybindings_Test;
 };

labath wrote:
> This also isn't something we normally do. I'd recommend just making a 
> function like `DumpKeyBindings()` or something. It's true that it would only 
> be used in tests right now, but I can imagine some day adding an lldb command 
> to dump current bindings, so it does not seem completely out of place. If you 
> wanted to, you could even add it right now and do your test that way.
Can you clarify this? I see a lot of friend class declarations in the LLDB 
codebase, both prod and test.

A command to dump key bindings could be useful in the future, but the 
requirement of parsing editline's stdout and manipulating it into some sort of 
structure for an API sounds like a maintenance tax until that command is 
implemented.



Comment at: lldb/unittests/Editline/EditlineTest.cpp:133-139
+  // We have to set the output stream we pass to Editline as not using
+  // buffered I/O.  Otherwise we are missing editline's output when we
+  // close the stream in the keybinding test (i.e. the EOF comes
+  // before data previously written to the stream by editline).  This
+  // behavior isn't as I understand the spec becuse fclose should
+  // flush the stream, but my best guess is that it's some unexpected
+  // interaction with stream I/O and ptys.

labath wrote:
> nealsid wrote:
> > labath wrote:
> > > I find this hard to believe. I think it's more likely that this is 
> > > working around some problem in the test itself. I can't say what is the 
> > > precise problem without more investigation, but for example the 
> > > synchronization around testOutputBuffer seems inadequate. 
> > > `GetEditlineOutput` could deadlock if the read thread reads the newline 
> > > before it reaches the `wait` call. It also does not handle spurious 
> > > wakeups. And the accesses to testOutputBuffer are completely 
> > > thread-unsafe.
> > I spent a few hours on this before sending the initial patch; it may be 
> > some interaction with the file APIs and the Psuedoterminal class we have in 
> > LLVM.  I could not debug anything it was doing that was leading to this 
> > behavior, but reliably saw EOF being sent before data that had been written 
> > to the stream.  I also tried various things like flushing it manually, 
> > which did not work, but sleeping before closing the secondary FD enabled 
> > all data to be read on the test side.  If you have some time, I'd be happy 
> > to have a gchat or screen sharing session and see if we can brainstorm 
> > something.
> > 
> > Regarding the synchronization, good call; I built on top of the existing 
> > threading, which did not require synchronizing reading the output of 
> > editline, because the actual output was never used.  Now, I just call 
> > provide a method to call thread::join for tests that need to read the 
> > output to ensure it's all been written.  
> Well.. I tried running this locally, and the test passed just fine even with 
> this code deleted. I don't think we should commit code like this without 
> understanding the problem in more detail. (Like, if it's a problem with llvm 
> code, then lets fix that; if it's a problem with libc code (I doubt that), 
> then let's file a bug before working around it.)If you want to discuss this 
> in a more interactive fashion, you can find me on the `#lldb` channel @ 
> irc.oftc.net.
Cool, I'll take another look..what platform were you running on? 



Comment at: lldb/unittests/Editline/EditlineTest.cpp:345
+  // mapped back to a specific input.
+  const std::string testNumber;
+  // Whether this keyboard shortcut is only bound in multi-line mode.

labath wrote:
> nealsid wrote:
> > labath wrote:
> > > You already have a const on the variable declaration. You don't need to 
> > > put one on every member as well.
> > I like const on the struct fields since it expresses the intent (a 
> > compile-time data structure) better, and, without it, if the array variable 
> > decl type was changed to remove the const, modifying the fields would be 
> > permitted.
> Well, we definitely have have different views on redundancy. I could write a 
> PhD thesis on why I think this is wrong, but right now, let me just say this: 
> it isn't consistent with how we define const structs anywhere else in llvm or 
> lldb. Here's some examples: 
> ,
>  
> 

[Lldb-commits] [lldb] f212032 - Add support for a "load binary" LC_NOTE in mach-o corefiles

2021-12-13 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2021-12-13T13:21:56-08:00
New Revision: f2120328e81879bf14d2a5c381749a11577fa304

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

LOG: Add support for a "load binary" LC_NOTE in mach-o corefiles

Add lldb support for a Mach-O "load binary" LC_NOTE which provides
a UUID, load address/slide, and possibly a name of a binary that
should be loaded when examining the core.

struct load_binary
{
uint32_t version;// currently 1
uuid_t   uuid;   // all zeroes if uuid not specified
uint64_t load_address;   // virtual address where the macho is loaded, 
UINT64_MAX if unavail
uint64_t slide;  // slide to be applied to file address to get load 
address, 0 if unavail
char name_cstring[]; // must be nul-byte terminated c-string, '\0' 
alone if name unavail
} __attribute__((packed));

Differential Revision: https://reviews.llvm.org/D115494
rdar://85069250

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 29cc399f7c2f1..e0087dbd4941e 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6973,6 +6973,23 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
   }
   image_infos.all_image_infos.push_back(image_entry);
 }
+  } else if (strcmp("load binary", data_owner) == 0) {
+uint32_t version = m_data.GetU32(&fileoff);
+if (version == 1) {
+  uuid_t uuid;
+  memcpy(&uuid, m_data.GetData(&fileoff, sizeof(uuid_t)),
+ sizeof(uuid_t));
+  uint64_t load_address = m_data.GetU64(&fileoff);
+  uint64_t slide = m_data.GetU64(&fileoff);
+  std::string filename = m_data.GetCStr(&fileoff);
+
+  MachOCorefileImageEntry image_entry;
+  image_entry.filename = filename;
+  image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t));
+  image_entry.load_address = load_address;
+  image_entry.slide = slide;
+  image_infos.all_image_infos.push_back(image_entry);
+}
   }
 }
 offset = cmd_offset + lc.cmdsize;
@@ -6983,29 +7000,42 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
 
 bool ObjectFileMachO::LoadCoreFileImages(lldb_private::Process &process) {
   MachOCorefileAllImageInfos image_infos = GetCorefileAllImageInfos();
-  bool added_images = false;
-  if (image_infos.IsValid()) {
-for (const MachOCorefileImageEntry &image : image_infos.all_image_infos) {
-  ModuleSpec module_spec;
-  module_spec.GetUUID() = image.uuid;
-  module_spec.GetFileSpec() = FileSpec(image.filename.c_str());
-  if (image.currently_executing) {
-Symbols::DownloadObjectAndSymbolFile(module_spec, true);
-if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
-  process.GetTarget().GetOrCreateModule(module_spec, false);
-}
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+
+  ModuleList added_modules;
+  for (const MachOCorefileImageEntry &image : image_infos.all_image_infos) {
+ModuleSpec module_spec;
+module_spec.GetUUID() = image.uuid;
+module_spec.GetFileSpec() = FileSpec(image.filename.c_str());
+if (image.currently_executing) {
+  Symbols::DownloadObjectAndSymbolFile(module_spec, true);
+  if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
+process.GetTarget().GetOrCreateModule(module_spec, false);
   }
-  Status error;
-  ModuleSP module_sp =
-  process.GetTarget().GetOrCreateModule(module_spec, false, &error);
-  if (!module_sp.get() || !module_sp->GetObjectFile()) {
-if (image.load_address != LLDB_INVALID_ADDRESS) {
-  module_sp = process.ReadModuleFromMemory(module_spec.GetFileSpec(),
-   image.load_address);
-}
+}
+Status error;
+ModuleSP module_sp =
+process.GetTarget().GetOrCreateModule(module_spec, false, &error);
+if (!module_sp.get() || !module_sp->GetObjectFile()) {
+  if (image.load_address != LLDB_INVALID_ADDRESS) {
+module_sp = process.ReadModuleFromMemory(module_spec.GetFileSpec(),
+ image.load_address);
   }
-  if (module_sp.get()) {
-added_images = true;
+}
+if (module_sp.get()) {
+  

[Lldb-commits] [PATCH] D115494: Add support to lldb for reading a "load binary" LC_NOTE with Mach-O corefiles

2021-12-13 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2120328e818: Add support for a "load binary" 
LC_NOTE in mach-o corefiles (authored by jasonmolenda).

Changed prior to commit:
  https://reviews.llvm.org/D115494?vs=393668&id=394031#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115494

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
  lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c

Index: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
===
--- lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
+++ lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 
 // Given an executable binary with 
 //   "fmain" (a function pointer to main)
@@ -55,6 +56,28 @@
   }
   pclose (nm);
 
+  sprintf (buf, "dwarfdump -u '%s'", argv[1]);
+  FILE *dwarfdump = popen(buf, "r");
+  if (!dwarfdump) {
+fprintf (stderr, "Unable to run dwarfdump -u on '%s'\n", argv[1]);
+exit (1);
+  }
+  uuid_t uuid;
+  uuid_clear (uuid);
+  while (fgets (buf, sizeof(buf), dwarfdump)) {
+if (strncmp (buf, "UUID: ", 6) == 0) {
+  buf[6 + 36] = '\0';
+  if (uuid_parse (buf + 6, uuid) != 0) {
+fprintf (stderr, "Unable to parse UUID in '%s'\n", buf);
+exit (1);
+  }
+}
+  }
+  if (uuid_is_null(uuid)) {
+fprintf (stderr, "Got a null uuid for the binary\n");
+exit (1);
+  }
+
   if (main_addr == 0 || fmain_addr == 0) {
 fprintf(stderr, "Unable to find address of main or fmain in %s.\n",
 argv[1]);
@@ -65,7 +88,9 @@
   //1. mach header
   //2. LC_THREAD load command
   //3. LC_SEGMENT_64 load command
-  //4. memory segment contents
+  //4. LC_NOTE load command
+  //5. memory segment contents
+  //6. "load binary" note contents
 
   // struct thread_command {
   //   uint32_tcmd;
@@ -80,13 +105,14 @@
   mh.cputype = CPU_TYPE_ARM64;
   mh.cpusubtype = CPU_SUBTYPE_ARM64E;
   mh.filetype = MH_CORE;
-  mh.ncmds = 2; // LC_THREAD, LC_SEGMENT_64
-  mh.sizeofcmds = size_of_thread_cmd + sizeof(struct segment_command_64);
+  mh.ncmds = 3; // LC_THREAD, LC_SEGMENT_64, LC_NOTE
+  mh.sizeofcmds = size_of_thread_cmd + sizeof(struct segment_command_64) + sizeof(struct note_command);
   mh.flags = 0;
   mh.reserved = 0;
 
   fwrite(&mh, sizeof (mh), 1, out);
 
+  struct note_command lcnote;
   struct segment_command_64 seg;
   seg.cmd = LC_SEGMENT_64;
   seg.cmdsize = sizeof(seg);
@@ -94,7 +120,7 @@
   seg.vmaddr = fmain_addr;
   seg.vmsize = 8;
   // Offset to segment contents
-  seg.fileoff = sizeof (mh) + size_of_thread_cmd + sizeof(seg);
+  seg.fileoff = sizeof (mh) + size_of_thread_cmd + sizeof(seg) + sizeof(lcnote);
   seg.filesize = 8;
   seg.maxprot = 3;
   seg.initprot = 3;
@@ -116,15 +142,47 @@
   memset (®state, 0, sizeof (regstate));
   fwrite (®state, sizeof (regstate), 1, out);
 
+  lcnote.cmd = LC_NOTE;
+  lcnote.cmdsize = sizeof (lcnote);
+  strcpy (lcnote.data_owner, "load binary");
+
+  // 8 is the size of the LC_SEGMENT contents
+  lcnote.offset = sizeof (mh) + size_of_thread_cmd + sizeof(seg) + sizeof(lcnote) + 8;
+
+  // struct load_binary
+  // {
+  // uint32_t version;// currently 1
+  // uuid_t   uuid;   // all zeroes if uuid not specified
+  // uint64_t load_address;   // virtual address where the macho is loaded, UINT64_MAX if unavail
+  // uint64_t slide;  // slide to be applied to file address to get load address, 0 if unavail
+  // char name_cstring[]; // must be nul-byte terminated c-string, '\0' alone if name unavail
+  // } __attribute__((packed));
+  lcnote.size = 4 + 16 + 8 + 8 + sizeof("a.out");
+
+  fwrite (&lcnote, sizeof(lcnote), 1, out);
+
+  // Write the contents of the memory segment
 
   // Or together a random PAC value from a system using 39 bits 
   // of addressing with the address of main().  lldb will need
   // to correctly strip off the high bits to find the address of
   // main.
   uint64_t segment_contents = 0xe46bff00 | main_addr;
-
   fwrite (&segment_contents, sizeof (segment_contents), 1, out);
 
+  // Now write the contents of the "load binary" LC_NOTE.
+  {
+uint32_t version = 1;
+fwrite (&version, sizeof (version), 1, out);
+fwrite (&uuid, sizeof (uuid), 1, out);
+uint64_t load_address = UINT64_MAX;
+fwrite (&load_address, sizeof (load_address), 1, out);
+uint64_t slide = 0;
+fwrite (&slide, sizeof (slide), 1, out);
+strcpy (buf, "a.out");
+fwrite (buf, 6, 1, out);
+  }
+
   fclose (out);
 
   exit (0);
Index: lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefault

[Lldb-commits] [PATCH] D115324: Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.

2021-12-13 Thread Greg Clayton via Phabricator via lldb-commits
clayborg updated this revision to Diff 394041.
clayborg added a comment.

Added string tables to the cache files.

This allowed me to add the symbol table name indexes to the same symbol table 
cache file and share any strings from the normal symbol table.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115324

Files:
  lldb/include/lldb/Core/Mangled.h
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Symbol/Symbol.h
  lldb/include/lldb/Symbol/Symtab.h
  lldb/include/lldb/Utility/DataEncoder.h
  lldb/include/lldb/Utility/DataFileCache.h
  lldb/include/lldb/lldb-forward.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Mangled.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/DataEncoder.cpp
  lldb/source/Utility/DataFileCache.cpp
  lldb/test/API/functionalities/module_cache/bsd/Makefile
  lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
  lldb/test/API/functionalities/module_cache/bsd/a.c
  lldb/test/API/functionalities/module_cache/bsd/b.c
  lldb/test/API/functionalities/module_cache/bsd/c.c
  lldb/test/API/functionalities/module_cache/bsd/main.c
  lldb/test/API/functionalities/module_cache/simple_exe/Makefile
  lldb/test/API/functionalities/module_cache/simple_exe/TestModuleCacheSimple.py
  lldb/test/API/functionalities/module_cache/simple_exe/main.c
  lldb/test/API/functionalities/module_cache/universal/Makefile
  
lldb/test/API/functionalities/module_cache/universal/TestModuleCacheUniversal.py
  lldb/test/API/functionalities/module_cache/universal/main.c
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/SymbolTest.cpp

Index: lldb/unittests/Symbol/SymbolTest.cpp
===
--- /dev/null
+++ lldb/unittests/Symbol/SymbolTest.cpp
@@ -0,0 +1,276 @@
+//===-- SymbolTest.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 "gtest/gtest.h"
+
+#include "lldb/Core/Section.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Utility/DataEncoder.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/DataFileCache.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list,
+ ByteOrder byte_order) {
+  const uint8_t addr_size = 8;
+  DataEncoder file(byte_order, addr_size);
+  DataEncoder strtab_encoder(byte_order, addr_size);
+  StringTableCreator strtab_creator;
+  object.Encode(file, strtab_creator);
+  llvm::ArrayRef bytes = file.GetData();
+  DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
+
+  strtab_creator.Encode(strtab_encoder);
+  llvm::ArrayRef strtab_bytes = strtab_encoder.GetData();
+  DataExtractor strtab_data(strtab_bytes.data(), strtab_bytes.size(),
+byte_order, addr_size);
+  StringTableReader strtab_reader;
+  offset_t strtab_data_offset = 0;
+  ASSERT_EQ(strtab_reader.Decode(strtab_data, &strtab_data_offset), true);
+
+  Symbol decoded_object;
+  offset_t data_offset = 0;
+  decoded_object.Decode(data, &data_offset, sect_list, strtab_reader);
+  EXPECT_EQ(object, decoded_object);
+}
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list) {
+  EncodeDecode(object, sect_list, eByteOrderLittle);
+  EncodeDecode(object, sect_list, eByteOrderBig);
+}
+
+TEST(SymbolTest, EncodeDecodeSymbol) {
+
+  SectionSP sect_sp(new Section(
+  /*module_sp=*/ModuleSP(),
+  /*obj_file=*/nullptr,
+  /*sect_id=*/1,
+  /*name=*/ConstString(".text"),
+  /*sect_type=*/eSectionTypeCode,
+  /*file_vm_addr=*/0x1000,
+  /*vm_size=*/0x1000,
+  /*file_offset=*/0,
+  /*file_size=*/0,
+  /*log2align=*/5,
+  /*flags=*/0x10203040));
+
+  SectionList sect_list;
+  sect_list.AddSection(sect_sp);
+
+  Symbol symbol(
+  /*symID=*/0x10203040,
+  /*name=*/"main",
+  /*type=*/eSymbolTypeCode,
+  /*bool external=*/false,
+  /*bool is_debug=*/false,
+  /*bool is_trampoline=*/false,
+  /*bool is_artificial=*/false,
+  /*section_sp=*/sect_sp,
+  /*offset=*/0x0,
+  /

[Lldb-commits] [PATCH] D113604: [lldb][NFC] Format lldb/include/lldb/Symbol/Type.h

2021-12-13 Thread David Blaikie via Phabricator via lldb-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks alright


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

https://reviews.llvm.org/D113604

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


[Lldb-commits] [PATCH] D77287: Windows: support `DoLoadImage`

2021-12-13 Thread Saleem Abdulrasool via Phabricator via lldb-commits
compnerd added a comment.

Thanks @thakis - 906e60b9f923464cba0f71a9205846550752162f 
 should 
have addressed that from a few days ago (sorry about not mentioning that here)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77287

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


[Lldb-commits] [PATCH] D94997: [lldb][lldb-vscode] Updated implementation of 'launch' and 'attach' requests to not create auxiliary target in case "launchCommands" and "attachCommands" are provided.

2021-12-13 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Revert the whitespace only changes to the .py file and good to go as long as 
all vscode tests are passing.




Comment at: 
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py:3


revert whitespace only change


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

https://reviews.llvm.org/D94997

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


[Lldb-commits] [PATCH] D115324: Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.

2021-12-13 Thread walter erquinigo via Phabricator via lldb-commits
wallace requested changes to this revision.
wallace added a comment.
This revision now requires changes to proceed.

much nicer than the first version. I'm just asking a few minor things.




Comment at: lldb/include/lldb/Host/FileSystem.h:147
+  ///
+  /// The path must specify a file an not a directory.
+  /// \{





Comment at: lldb/include/lldb/Symbol/Symbol.h:256
+  ///   and cache file size reduction. Strings are stored as uint32_t string
+  ///   table offsets in the cache data.
+  bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,

better mention that the return value means



Comment at: lldb/include/lldb/Symbol/Symtab.h:148
+  ///   otherwise.
+  bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,
+  bool &uuid_mismatch);

ditto



Comment at: lldb/include/lldb/Utility/DataFileCache.h:59
+  ///   A valid unique pointer to a memory buffer if the data is available, or
+  ///   an shared pointer that contains NULL if the data is not available.
+  std::unique_ptr GetCachedData(llvm::StringRef key);





Comment at: lldb/include/lldb/Utility/DataFileCache.h:175
+/// class helps create string tables.
+class StringTableCreator {
+public:

I'd just call this ConstStringTable for callers to know that this is using 
ConstString as its storage pool and that the data doesn't just go away when the 
object is disposed. 



Comment at: lldb/source/Utility/DataFileCache.cpp:58
+  else
+consumeError(cache_or_err.takeError());
+}

could you create a new lldb log channel where this information is logged? it'll 
help investigating issues with the cache (if they ever happen). Same for 
everywhere llvm::Error's or lldb::Status messages are lost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115324

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


[Lldb-commits] [lldb] 58473d8 - [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING

2021-12-13 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2021-12-13T16:58:39-08:00
New Revision: 58473d84e0c7796de5dcfd3153e5d5cc8ad034b3

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

LOG: [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING

Added: 


Modified: 
lldb/source/Version/Version.cpp

Removed: 




diff  --git a/lldb/source/Version/Version.cpp b/lldb/source/Version/Version.cpp
index ae2d83bd3e5f8..b391fe1eacd80 100644
--- a/lldb/source/Version/Version.cpp
+++ b/lldb/source/Version/Version.cpp
@@ -15,7 +15,7 @@ static const char *GetLLDBVersion() {
 #ifdef LLDB_FULL_VERSION_STRING
   return LLDB_FULL_VERSION_STRING;
 #else
-  return "lldb version " CLANG_VERSION_STRING;
+  return "lldb version " LLDB_VERSION_STRING;
 #endif
 }
 



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


Re: [Lldb-commits] [lldb] 58473d8 - [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING

2021-12-13 Thread David Blaikie via lldb-commits
Any chance of test coverage?

On Mon, Dec 13, 2021 at 4:58 PM Jonas Devlieghere via lldb-commits <
lldb-commits@lists.llvm.org> wrote:

>
> Author: Jonas Devlieghere
> Date: 2021-12-13T16:58:39-08:00
> New Revision: 58473d84e0c7796de5dcfd3153e5d5cc8ad034b3
>
> URL:
> https://github.com/llvm/llvm-project/commit/58473d84e0c7796de5dcfd3153e5d5cc8ad034b3
> DIFF:
> https://github.com/llvm/llvm-project/commit/58473d84e0c7796de5dcfd3153e5d5cc8ad034b3.diff
>
> LOG: [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING
>
> Added:
>
>
> Modified:
> lldb/source/Version/Version.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/lldb/source/Version/Version.cpp
> b/lldb/source/Version/Version.cpp
> index ae2d83bd3e5f8..b391fe1eacd80 100644
> --- a/lldb/source/Version/Version.cpp
> +++ b/lldb/source/Version/Version.cpp
> @@ -15,7 +15,7 @@ static const char *GetLLDBVersion() {
>  #ifdef LLDB_FULL_VERSION_STRING
>return LLDB_FULL_VERSION_STRING;
>  #else
> -  return "lldb version " CLANG_VERSION_STRING;
> +  return "lldb version " LLDB_VERSION_STRING;
>  #endif
>  }
>
>
>
>
> ___
> lldb-commits mailing list
> lldb-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


Re: [Lldb-commits] [lldb] 58473d8 - [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING

2021-12-13 Thread Jonas Devlieghere via lldb-commits
This is NFC

On Mon, Dec 13, 2021 at 5:00 PM David Blaikie  wrote:

> Any chance of test coverage?
>
> On Mon, Dec 13, 2021 at 4:58 PM Jonas Devlieghere via lldb-commits <
> lldb-commits@lists.llvm.org> wrote:
>
>>
>> Author: Jonas Devlieghere
>> Date: 2021-12-13T16:58:39-08:00
>> New Revision: 58473d84e0c7796de5dcfd3153e5d5cc8ad034b3
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/58473d84e0c7796de5dcfd3153e5d5cc8ad034b3
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/58473d84e0c7796de5dcfd3153e5d5cc8ad034b3.diff
>>
>> LOG: [lldb] Use LLDB_VERSION_STRING instead of CLANG_VERSION_STRING
>>
>> Added:
>>
>>
>> Modified:
>> lldb/source/Version/Version.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/lldb/source/Version/Version.cpp
>> b/lldb/source/Version/Version.cpp
>> index ae2d83bd3e5f8..b391fe1eacd80 100644
>> --- a/lldb/source/Version/Version.cpp
>> +++ b/lldb/source/Version/Version.cpp
>> @@ -15,7 +15,7 @@ static const char *GetLLDBVersion() {
>>  #ifdef LLDB_FULL_VERSION_STRING
>>return LLDB_FULL_VERSION_STRING;
>>  #else
>> -  return "lldb version " CLANG_VERSION_STRING;
>> +  return "lldb version " LLDB_VERSION_STRING;
>>  #endif
>>  }
>>
>>
>>
>>
>> ___
>> lldb-commits mailing list
>> lldb-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>>
>
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115662: [lldb][DWARF] Remove duplicate DIE type assignment

2021-12-13 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik 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/D115662/new/

https://reviews.llvm.org/D115662

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


[Lldb-commits] [PATCH] D115570: [lldb] Use `GNUInstallDirs` to support custom installation dirs.

2021-12-13 Thread John Ericson via Phabricator via lldb-commits
Ericson2314 updated this revision to Diff 394117.
Ericson2314 added a comment.

simplify


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115570

Files:
  lldb/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBConfig.cmake


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -226,7 +226,7 @@
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   install(DIRECTORY include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
@@ -234,7 +234,7 @@
 
   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -1,3 +1,5 @@
+include(GNUInstallDirs)
+
 function(lldb_tablegen)
   # Syntax:
   # lldb_tablegen output-file [tablegen-arg ...] SOURCE source-file
@@ -113,7 +115,7 @@
 endif()
 # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS
 install(TARGETS ${name} COMPONENT ${name}
-  RUNTIME DESTINATION bin
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   LIBRARY DESTINATION ${install_dest}
   ARCHIVE DESTINATION ${install_dest}
   FRAMEWORK DESTINATION ${install_dest})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -1,5 +1,7 @@
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 # Add path for custom modules.
 set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
@@ -11,6 +13,7 @@
 # using LLVM as an external library.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(lldb)
+
   include(LLDBStandalone)
 
   set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -226,7 +226,7 @@
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   install(DIRECTORY include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
@@ -234,7 +234,7 @@
 
   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -1,3 +1,5 @@
+include(GNUInstallDirs)
+
 function(lldb_tablegen)
   # Syntax:
   # lldb_tablegen output-file [tablegen-arg ...] SOURCE source-file
@@ -113,7 +115,7 @@
 endif()
 # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS
 install(TARGETS ${name} COMPONENT ${name}
-  RUNTIME DESTINATION bin
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   LIBRARY DESTINATION ${install_dest}
   ARCHIVE DESTINATION ${install_dest}
   FRAMEWORK DESTINATION ${install_dest})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -1,5 +1,7 @@
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 # Add path for custom modules.
 set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
@@ -11,6 +13,7 @@
 # using LLVM as an external library.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(lldb)
+
   include(LLDBStandalone)
 
   set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115570: [lldb] Use `GNUInstallDirs` to support custom installation dirs.

2021-12-13 Thread John Ericson via Phabricator via lldb-commits
Ericson2314 updated this revision to Diff 394118.
Ericson2314 added a comment.



1. Updating D115570 : [lldb] Use 
`GNUInstallDirs` to support custom installation dirs. #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

remove blank line we don't need to add


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115570

Files:
  lldb/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBConfig.cmake


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -226,7 +226,7 @@
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   install(DIRECTORY include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
@@ -234,7 +234,7 @@
 
   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -1,3 +1,5 @@
+include(GNUInstallDirs)
+
 function(lldb_tablegen)
   # Syntax:
   # lldb_tablegen output-file [tablegen-arg ...] SOURCE source-file
@@ -113,7 +115,7 @@
 endif()
 # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS
 install(TARGETS ${name} COMPONENT ${name}
-  RUNTIME DESTINATION bin
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   LIBRARY DESTINATION ${install_dest}
   ARCHIVE DESTINATION ${install_dest}
   FRAMEWORK DESTINATION ${install_dest})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -1,5 +1,7 @@
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 # Add path for custom modules.
 set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -226,7 +226,7 @@
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
   install(DIRECTORY include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
@@ -234,7 +234,7 @@
 
   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
 COMPONENT lldb-headers
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 FILES_MATCHING
 PATTERN "*.h"
 PATTERN ".cmake" EXCLUDE
Index: lldb/cmake/modules/AddLLDB.cmake
===
--- lldb/cmake/modules/AddLLDB.cmake
+++ lldb/cmake/modules/AddLLDB.cmake
@@ -1,3 +1,5 @@
+include(GNUInstallDirs)
+
 function(lldb_tablegen)
   # Syntax:
   # lldb_tablegen output-file [tablegen-arg ...] SOURCE source-file
@@ -113,7 +115,7 @@
 endif()
 # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS
 install(TARGETS ${name} COMPONENT ${name}
-  RUNTIME DESTINATION bin
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   LIBRARY DESTINATION ${install_dest}
   ARCHIVE DESTINATION ${install_dest}
   FRAMEWORK DESTINATION ${install_dest})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -1,5 +1,7 @@
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 # Add path for custom modules.
 set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115698: [lldb] Check if language is supported before creating a REPL instance

2021-12-13 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, teemperor.
JDevlieghere requested review of this revision.

Currently, we'll try to instantiate a ClangREPL for every known language. The 
plugin manager already knows what languages are supported, so rely on that to 
only instantiate a REPL when we know the requested language in supported.

rdar://86439474


https://reviews.llvm.org/D115698

Files:
  lldb/include/lldb/Core/PluginManager.h
  lldb/source/Core/PluginManager.cpp
  lldb/source/Expression/REPL.cpp
  lldb/test/Shell/REPL/Basic.test


Index: lldb/test/Shell/REPL/Basic.test
===
--- /dev/null
+++ lldb/test/Shell/REPL/Basic.test
@@ -0,0 +1,10 @@
+// Basic sanity checking of the REPL.
+
+// RUN: %lldb --repl --repl-language c++ 2>&1 | FileCheck %s --check-prefix=CPP
+// CPP: error: must have a target to create a REPL
+
+// RUN: %lldb --repl --repl-language python 2>&1 | FileCheck %s 
--check-prefix=PYTHON
+// PYTHON: error: couldn't find a REPL for python
+
+// RUN: not %lldb --repl --repl-language bogus 2>&1 | FileCheck %s 
--check-prefix=BOGUS
+// BOGUS: error: Unrecognized language name: "bogus"
Index: lldb/source/Expression/REPL.cpp
===
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -39,7 +39,11 @@
   lldb::REPLSP ret;
 
   while (REPLCreateInstance create_instance =
- PluginManager::GetREPLCreateCallbackAtIndex(idx++)) {
+ PluginManager::GetREPLCreateCallbackAtIndex(idx)) {
+LanguageSet supported_languages =
+PluginManager::GetREPLSupportedLanguagesAtIndex(idx++);
+if (!supported_languages[language])
+  continue;
 ret = (*create_instance)(err, language, debugger, target, repl_options);
 if (ret) {
   break;
Index: lldb/source/Core/PluginManager.cpp
===
--- lldb/source/Core/PluginManager.cpp
+++ lldb/source/Core/PluginManager.cpp
@@ -1345,6 +1345,12 @@
   return GetREPLInstances().GetCallbackAtIndex(idx);
 }
 
+LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
+  const auto &instances = GetREPLInstances().GetInstances();
+  return idx < instances.size() ? instances[idx].supported_languages
+: LanguageSet();
+}
+
 LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
   const auto &instances = GetREPLInstances().GetInstances();
   LanguageSet all;
Index: lldb/include/lldb/Core/PluginManager.h
===
--- lldb/include/lldb/Core/PluginManager.h
+++ lldb/include/lldb/Core/PluginManager.h
@@ -449,6 +449,8 @@
 
   static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx);
 
+  static LanguageSet GetREPLSupportedLanguagesAtIndex(uint32_t idx);
+
   static LanguageSet GetREPLAllTypeSystemSupportedLanguages();
 
   // Some plug-ins might register a DebuggerInitializeCallback callback when


Index: lldb/test/Shell/REPL/Basic.test
===
--- /dev/null
+++ lldb/test/Shell/REPL/Basic.test
@@ -0,0 +1,10 @@
+// Basic sanity checking of the REPL.
+
+// RUN: %lldb --repl --repl-language c++ 2>&1 | FileCheck %s --check-prefix=CPP
+// CPP: error: must have a target to create a REPL
+
+// RUN: %lldb --repl --repl-language python 2>&1 | FileCheck %s --check-prefix=PYTHON
+// PYTHON: error: couldn't find a REPL for python
+
+// RUN: not %lldb --repl --repl-language bogus 2>&1 | FileCheck %s --check-prefix=BOGUS
+// BOGUS: error: Unrecognized language name: "bogus"
Index: lldb/source/Expression/REPL.cpp
===
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -39,7 +39,11 @@
   lldb::REPLSP ret;
 
   while (REPLCreateInstance create_instance =
- PluginManager::GetREPLCreateCallbackAtIndex(idx++)) {
+ PluginManager::GetREPLCreateCallbackAtIndex(idx)) {
+LanguageSet supported_languages =
+PluginManager::GetREPLSupportedLanguagesAtIndex(idx++);
+if (!supported_languages[language])
+  continue;
 ret = (*create_instance)(err, language, debugger, target, repl_options);
 if (ret) {
   break;
Index: lldb/source/Core/PluginManager.cpp
===
--- lldb/source/Core/PluginManager.cpp
+++ lldb/source/Core/PluginManager.cpp
@@ -1345,6 +1345,12 @@
   return GetREPLInstances().GetCallbackAtIndex(idx);
 }
 
+LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
+  const auto &instances = GetREPLInstances().GetInstances();
+  return idx < instances.size() ? instances[idx].supported_languages
+: LanguageSet();
+}
+
 LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
   co

[Lldb-commits] [PATCH] D115324: Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.

2021-12-13 Thread Greg Clayton via Phabricator via lldb-commits
clayborg updated this revision to Diff 394141.
clayborg added a comment.

Address all review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115324

Files:
  lldb/include/lldb/Core/Mangled.h
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Symbol/Symbol.h
  lldb/include/lldb/Symbol/Symtab.h
  lldb/include/lldb/Utility/DataEncoder.h
  lldb/include/lldb/Utility/DataFileCache.h
  lldb/include/lldb/lldb-forward.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Mangled.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/DataEncoder.cpp
  lldb/source/Utility/DataFileCache.cpp
  lldb/test/API/functionalities/module_cache/bsd/Makefile
  lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
  lldb/test/API/functionalities/module_cache/bsd/a.c
  lldb/test/API/functionalities/module_cache/bsd/b.c
  lldb/test/API/functionalities/module_cache/bsd/c.c
  lldb/test/API/functionalities/module_cache/bsd/main.c
  lldb/test/API/functionalities/module_cache/simple_exe/Makefile
  lldb/test/API/functionalities/module_cache/simple_exe/TestModuleCacheSimple.py
  lldb/test/API/functionalities/module_cache/simple_exe/main.c
  lldb/test/API/functionalities/module_cache/universal/Makefile
  
lldb/test/API/functionalities/module_cache/universal/TestModuleCacheUniversal.py
  lldb/test/API/functionalities/module_cache/universal/main.c
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/SymbolTest.cpp

Index: lldb/unittests/Symbol/SymbolTest.cpp
===
--- /dev/null
+++ lldb/unittests/Symbol/SymbolTest.cpp
@@ -0,0 +1,276 @@
+//===-- SymbolTest.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 "gtest/gtest.h"
+
+#include "lldb/Core/Section.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Utility/DataEncoder.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/DataFileCache.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list,
+ ByteOrder byte_order) {
+  const uint8_t addr_size = 8;
+  DataEncoder file(byte_order, addr_size);
+  DataEncoder strtab_encoder(byte_order, addr_size);
+  ConstStringTable const_strtab;
+  object.Encode(file, const_strtab);
+  llvm::ArrayRef bytes = file.GetData();
+  DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
+
+  const_strtab.Encode(strtab_encoder);
+  llvm::ArrayRef strtab_bytes = strtab_encoder.GetData();
+  DataExtractor strtab_data(strtab_bytes.data(), strtab_bytes.size(),
+byte_order, addr_size);
+  StringTableReader strtab_reader;
+  offset_t strtab_data_offset = 0;
+  ASSERT_EQ(strtab_reader.Decode(strtab_data, &strtab_data_offset), true);
+
+  Symbol decoded_object;
+  offset_t data_offset = 0;
+  decoded_object.Decode(data, &data_offset, sect_list, strtab_reader);
+  EXPECT_EQ(object, decoded_object);
+}
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list) {
+  EncodeDecode(object, sect_list, eByteOrderLittle);
+  EncodeDecode(object, sect_list, eByteOrderBig);
+}
+
+TEST(SymbolTest, EncodeDecodeSymbol) {
+
+  SectionSP sect_sp(new Section(
+  /*module_sp=*/ModuleSP(),
+  /*obj_file=*/nullptr,
+  /*sect_id=*/1,
+  /*name=*/ConstString(".text"),
+  /*sect_type=*/eSectionTypeCode,
+  /*file_vm_addr=*/0x1000,
+  /*vm_size=*/0x1000,
+  /*file_offset=*/0,
+  /*file_size=*/0,
+  /*log2align=*/5,
+  /*flags=*/0x10203040));
+
+  SectionList sect_list;
+  sect_list.AddSection(sect_sp);
+
+  Symbol symbol(
+  /*symID=*/0x10203040,
+  /*name=*/"main",
+  /*type=*/eSymbolTypeCode,
+  /*bool external=*/false,
+  /*bool is_debug=*/false,
+  /*bool is_trampoline=*/false,
+  /*bool is_artificial=*/false,
+  /*section_sp=*/sect_sp,
+  /*offset=*/0x0,
+  /*size=*/0x100,
+  /*size_is_valid=*/true,
+  /*contains_linker_annotations=*/false,
+  /*flags=*/0x11223344);
+
+  // Test encoding a symbol with an a

[Lldb-commits] [PATCH] D115324: Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.

2021-12-13 Thread Greg Clayton via Phabricator via lldb-commits
clayborg marked 6 inline comments as done.
clayborg added inline comments.



Comment at: lldb/source/Utility/DataFileCache.cpp:58
+  else
+consumeError(cache_or_err.takeError());
+}

wallace wrote:
> could you create a new lldb log channel where this information is logged? 
> it'll help investigating issues with the cache (if they ever happen). Same 
> for everywhere llvm::Error's or lldb::Status messages are lost.
I didn't create a new channel because we are out of log bits. I can expand the 
log bits to 64 in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115324

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