[Lldb-commits] [PATCH] D122193: Reland "[lldb/test] Add events listener helper class to lldbtest"

2022-03-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 417136.
mib added a comment.

Reflow docstring


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

https://reviews.llvm.org/D122193

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,28 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopProgressThread = (1 << 0)
+class TestProgressReporting(EventListenerTestBase):
+
+mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
-
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+EventListenerTestBase.setUp(self, lldb.SBDebugger.eBroadcastBitProgress)
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
 
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
+def event_checker(self, event):
+ret_args = lldb.SBDebugger.GetProgressFromEvent(event)
+self.assertTrue(ret_args)
 
-self.assertGreater(len(self.progress_events), 0)
+self.assertEvent(event_checker)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,23 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListenerTestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
 def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopDiagnosticThread:
-done = True
-elif event.BroadcasterMatchesRef(self.diagnostic_broadcaster):
-self.diagnostic_events.append(
-

[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added a comment.

Came up with a new approach in D122193 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D122193: Reland "[lldb/test] Add events listener helper class to lldbtest"

2022-03-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: labath, JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This reverts commit 8bf893466632cc2597188b431160effcd8cedeef 
 and 
updates
it to - hopefully - fix the racing issue, when accessing the event list.

To do so, instead of listening for event on a separate thread and
appending the matching ones to an event list, this provides a new
`assertEvent` helper method with a "event checker" callback, that will
fetch only one event and run the callback if it matches the event mask
provided at `setUp`.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122193

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,28 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopProgressThread = (1 << 0)
+class TestProgressReporting(EventListenerTestBase):
+
+mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
-
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+EventListenerTestBase.setUp(self, lldb.SBDebugger.eBroadcastBitProgress)
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
 
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
+def event_checker(self, event):
+ret_args = lldb.SBDebugger.GetProgressFromEvent(event)
+self.assertTrue(ret_args)
 
-self.assertGreater(len(self.progress_events), 0)
+self.assertEvent(event_checker)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,23 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListenerTestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
 def setUp(self):
-

[Lldb-commits] [PATCH] D122176: [trace] clear any existing tracing sessions before relaunching the binary

2022-03-21 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa80c6c7d36d2: [trace] clear any existing tracing sessions 
before relaunching the binary (authored by Walter Erquinigo 
wall...@fb.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122176

Files:
  lldb/source/Target/Target.cpp
  lldb/test/API/commands/trace/TestTraceStartStop.py


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+# For this, we'll trace starting at a different point in the new
+# process.
+self.expect("breakpoint disable")
+self.expect("b main.cpp:4")
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("si")
+self.expect("thread trace dump instructions -c 1",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 11 at main.cpp:4'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+# For this, we'll trace starting at a different point in the new
+# process.
+self.expect("breakpoint disable")
+self.expect("b main.cpp:4")
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("si")
+self.expect("thread trace dump instructions -c 1",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 11 at main.cpp:4'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122192: [trace] Use vector instead of ArrayRef when reading data

2022-03-21 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31e44c01e3b5: [trace] Use vector instead of ArrayRef when 
reading data (authored by Walter Erquinigo wall...@fb.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122192

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


Index: lldb/source/Target/Trace.cpp
===
--- lldb/source/Target/Trace.cpp
+++ lldb/source/Target/Trace.cpp
@@ -142,7 +142,7 @@
   return data_it->second;
 }
 
-Expected>
+Expected>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected>
+Expected>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
Index: lldb/include/lldb/Target/Trace.h
===
--- lldb/include/lldb/Target/Trace.h
+++ lldb/include/lldb/Target/Trace.h
@@ -253,7 +253,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData


Index: lldb/source/Target/Trace.cpp
===
--- lldb/source/Target/Trace.cpp
+++ lldb/source/Target/Trace.cpp
@@ -142,7 +142,7 @@
   return data_it->second;
 }
 
-Expected>
+Expected>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected>
+Expected>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
Index: lldb/include/lldb/Target/Trace.h
===
--- lldb/include/lldb/Target/Trace.h
+++ lldb/include/lldb/Target/Trace.h
@@ -253,7 +253,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 31e44c0 - [trace] Use vector instead of ArrayRef when reading data

2022-03-21 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-03-21T16:03:37-07:00
New Revision: 31e44c01e3b5cc2cc7a9f1dc49806b3f050efb82

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

LOG: [trace] Use vector instead of ArrayRef when reading data

I incorrectly returned an ArrayRef when the underlying object didn't own
the data. Instead, returning a vector is what we should do.

This fixes an issue when trying to access an intel-pt trace buffer
larger than 16 MB.

repro
```
go to a breakpoint
thread trace start -s 16777216
n
thread trace dump instructions # this doesn't fail anymore
```

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

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Target/Trace.h 
b/lldb/include/lldb/Target/Trace.h
index 643b761cdb897..c4ca192a1c263 100644
--- a/lldb/include/lldb/Target/Trace.h
+++ b/lldb/include/lldb/Target/Trace.h
@@ -253,7 +253,7 @@ class Trace : public PluginInterface,
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@ class Trace : public PluginInterface,
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData

diff  --git a/lldb/source/Target/Trace.cpp b/lldb/source/Target/Trace.cpp
index 38b3a7cb006df..7f9ae54455cb1 100644
--- a/lldb/source/Target/Trace.cpp
+++ b/lldb/source/Target/Trace.cpp
@@ -142,7 +142,7 @@ Optional 
Trace::GetLiveProcessBinaryDataSize(llvm::StringRef kind) {
   return data_it->second;
 }
 
-Expected>
+Expected>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@ Trace::GetLiveThreadBinaryData(lldb::tid_t tid, 
llvm::StringRef kind) {
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected>
+Expected>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),



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


[Lldb-commits] [lldb] a80c6c7 - [trace] clear any existing tracing sessions before relaunching the binary

2022-03-21 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-03-21T16:03:37-07:00
New Revision: a80c6c7d36d25999a28cfad32e1f461db95ba4dc

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

LOG: [trace] clear any existing tracing sessions before relaunching the binary

There's a bug caused when a process is relaunched: the target, which
doesn't change, keeps the Trace object from the previous process, which
is already defunct, and causes segmentation faults when it's attempted
to be used.
A fix is to clean up the Trace object when the target is disposing of
the previous process during relaunches.

A way to reproduce this:
```
lldb a.out
b main
r
process trace start
c
r
process trace start
```

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

Added: 


Modified: 
lldb/source/Target/Target.cpp
lldb/test/API/commands/trace/TestTraceStartStop.py

Removed: 




diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 00e9fd1eda571..71991085145ab 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@ void Target::CleanupProcess() {
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);

diff  --git a/lldb/test/API/commands/trace/TestTraceStartStop.py 
b/lldb/test/API/commands/trace/TestTraceStartStop.py
index 841ca437b29f6..d0d65fdd9cf9c 100644
--- a/lldb/test/API/commands/trace/TestTraceStartStop.py
+++ b/lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@ def testStartStopLiveThreads(self):
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+# For this, we'll trace starting at a 
diff erent point in the new
+# process.
+self.expect("breakpoint disable")
+self.expect("b main.cpp:4")
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("si")
+self.expect("thread trace dump instructions -c 1",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 11 at main.cpp:4'''])



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


[Lldb-commits] [PATCH] D122176: [trace] clear any existing tracing sessions before relaunching the binary

2022-03-21 Thread Jakob Johnson via Phabricator via lldb-commits
jj10306 accepted this revision.
jj10306 added a comment.
This revision is now accepted and ready to land.

nice catch, lgtm!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122176

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


[Lldb-commits] [lldb] 15c2d9c - [simple] fix formatting in the intel-pt doc

2022-03-21 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-03-21T15:56:55-07:00
New Revision: 15c2d9cd790cac143fdd2a206304d245d65fb4e1

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

LOG: [simple] fix formatting in the intel-pt doc

A list needs to be properly formatted.

Added: 


Modified: 
lldb/docs/use/intel_pt.rst

Removed: 




diff  --git a/lldb/docs/use/intel_pt.rst b/lldb/docs/use/intel_pt.rst
index 95a13618b213f..3f88ae1cda27f 100644
--- a/lldb/docs/use/intel_pt.rst
+++ b/lldb/docs/use/intel_pt.rst
@@ -4,21 +4,21 @@ Tracing with Intel Processor Trace
 .. contents::
   :local:
 
-Intel PT is a technology available in modern Intel CPUs that allows efficient 
-tracing of all the instructions executed by a process. 
-LLDB can collect traces and dump them using its symbolication stack. 
-You can read more here 
+Intel PT is a technology available in modern Intel CPUs that allows efficient
+tracing of all the instructions executed by a process.
+LLDB can collect traces and dump them using its symbolication stack.
+You can read more here
 https://easyperf.net/blog/2019/08/23/Intel-Processor-Trace.
 
 Prerequisites
 -
 
-Confirm that your CPU supports Intel PT 
-(see 
https://www.intel.com/content/www/us/en/support/articles/56730/processors.html)
 
+Confirm that your CPU supports Intel PT
+(see 
https://www.intel.com/content/www/us/en/support/articles/56730/processors.html)
 and that your operating system is Linux.
 
 Check for the existence of this particular file on your Linux system
-:: 
+::
 
   $ cat /sys/bus/event_source/devices/intel_pt/type
 
@@ -28,9 +28,9 @@ The output should be a number. Otherwise, try upgrading your 
kernel.
 Build Instructions
 --
 
-Clone and build the low level Intel PT 
+Clone and build the low level Intel PT
 decoder library [LibIPT library](https://github.com/intel/libipt).
-:: 
+::
 
   $ git clone g...@github.com:intel/libipt.git
   $ mkdir libipt-build
@@ -38,19 +38,19 @@ decoder library [LibIPT 
library](https://github.com/intel/libipt).
   $ cd libipt-build
   $ make
 
-This will generate a few files in the `/lib` 
+This will generate a few files in the `/lib`
 and `/libipt/include` directories.
 
 Configure and build LLDB with Intel PT support
-:: 
+::
 
-  $ cmake \
+  $ cmake \
   -DLLDB_BUILD_INTEL_PT=ON \
   -DLIBIPT_INCLUDE_PATH="/libipt/include" \
   -DLIBIPT_LIBRARY_PATH="/lib" \
-  ... other common configuration parameters 
+  ... other common configuration parameters
 
-:: 
+::
 
   $ cd  && ninja lldb lldb-server # if using Ninja
 
@@ -58,11 +58,11 @@ Configure and build LLDB with Intel PT support
 How to Use
 --
 
-When you are debugging a process, you can turn on intel-pt tracing, 
-which will “record” all the instructions that the process will execute. 
-After turning it on, you can continue debugging, and at any breakpoint, 
+When you are debugging a process, you can turn on intel-pt tracing,
+which will “record” all the instructions that the process will execute.
+After turning it on, you can continue debugging, and at any breakpoint,
 you can inspect the instruction list.
- 
+
 For example:
 ::
   lldb 
@@ -70,7 +70,7 @@ For example:
   > run
   > process trace start # start tracing on all threads, including future ones
   # keep debugging until you hit a breakpoint
-  
+
   > thread trace dump instructions
   # this should output something like
 
@@ -86,53 +86,53 @@ For example:
   [4962259] 0x7fffeb66b648movl   %eax, %r11d
 
   # you can keep pressing ENTER to see more and more instructions
- 
-The number between brackets is the instruction index, 
+
+The number between brackets is the instruction index,
 and by default the current thread will be picked.
- 
+
 Configuring the trace size
 --
- 
-The CPU stores the instruction list in a compressed format in a ring buffer, 
-which keeps the latest information. 
-By default, LLDB uses a buffer of 4KB per thread, 
-but you can change it by running. 
+
+The CPU stores the instruction list in a compressed format in a ring buffer,
+which keeps the latest information.
+By default, LLDB uses a buffer of 4KB per thread,
+but you can change it by running.
 The size must be a power of 2 and at least 4KB.
 ::
   thread trace start all -s 
- 
+
 For reference, a 1MB trace buffer can easily store around 5M instructions.
- 
+
 Printing more instructions
 --
- 
+
 If you want to dump more instructions at a time, you can run
 ::
   thread trace dump instructions -c 
- 
+
 Printing the instructions of another thread
 ---
 
-By default the current thread will be picked when dumping instructions, 
+By default the current thread will 

[Lldb-commits] [PATCH] D122025: [lldb] Remove lldbassert from CommandInterpreter::PrintCommandOutput

2022-03-21 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I think it makes sense to require that the CommandResultObject's command output 
is UTF-8 string with no embedded '\0'-s.  We wouldn't do smart things with 
rendering command output with nulls in it, and I don't see any reason to 
support such a thing.

OTOH, this seems like the wrong place to check that, since it's pretty far 
removed from whoever would have added the null's.  If we wanted to do this 
right, we would sanitize when you write to the CommandResultObject.


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

https://reviews.llvm.org/D122025

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


[Lldb-commits] [PATCH] D122192: [trace] Use vector instead of ArrayRef when reading data

2022-03-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: jj10306, zrthxn.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

I incorrectly returned an ArrayRef when the underlying object didn't own
the data. Instead, returning a vector is what we should do.

This fixes an issue when trying to access an intel-pt trace buffer
larger than 16 MB.

repro

  go to a breakpoint
  thread trace start -s 16777216
  n
  thread trace dump instructions # this doesn't fail anymore


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122192

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


Index: lldb/source/Target/Trace.cpp
===
--- lldb/source/Target/Trace.cpp
+++ lldb/source/Target/Trace.cpp
@@ -142,7 +142,7 @@
   return data_it->second;
 }
 
-Expected>
+Expected>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected>
+Expected>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
Index: lldb/include/lldb/Target/Trace.h
===
--- lldb/include/lldb/Target/Trace.h
+++ lldb/include/lldb/Target/Trace.h
@@ -253,7 +253,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData


Index: lldb/source/Target/Trace.cpp
===
--- lldb/source/Target/Trace.cpp
+++ lldb/source/Target/Trace.cpp
@@ -142,7 +142,7 @@
   return data_it->second;
 }
 
-Expected>
+Expected>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected>
+Expected>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
 return createStringError(inconvertibleErrorCode(),
Index: lldb/include/lldb/Target/Trace.h
===
--- lldb/include/lldb/Target/Trace.h
+++ lldb/include/lldb/Target/Trace.h
@@ -253,7 +253,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@
   /// \return
   /// A vector of bytes with the requested data, or an \a llvm::Error in
   /// case of failures.
-  llvm::Expected>
+  llvm::Expected>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122177: [lldb] Fix log & progress report for in-memory binaries

2022-03-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3323321f4ef0: [lldb] Fix log  progress report for 
in-memory binaries (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D122177?vs=417077=417117#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122177

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2201,14 +2201,14 @@
 enum { DebugSymbols = true, NonDebugSymbols = false };
 
 void ObjectFileMachO::ParseSymtab(Symtab ) {
-  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
- m_file.GetFilename().AsCString(""));
   ModuleSP module_sp(GetModule());
   if (!module_sp)
 return;
 
-  Progress progress(llvm::formatv("Parsing symbol table for {0}",
-  
m_file.GetFilename().AsCString("")));
+  const FileSpec  = m_file ? m_file : module_sp->GetFileSpec();
+  const char *file_name = file.GetFilename().AsCString("");
+  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s", file_name);
+  Progress progress(llvm::formatv("Parsing symbol table for {0}", file_name));
 
   llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 
0};


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2201,14 +2201,14 @@
 enum { DebugSymbols = true, NonDebugSymbols = false };
 
 void ObjectFileMachO::ParseSymtab(Symtab ) {
-  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
- m_file.GetFilename().AsCString(""));
   ModuleSP module_sp(GetModule());
   if (!module_sp)
 return;
 
-  Progress progress(llvm::formatv("Parsing symbol table for {0}",
-  m_file.GetFilename().AsCString("")));
+  const FileSpec  = m_file ? m_file : module_sp->GetFileSpec();
+  const char *file_name = file.GetFilename().AsCString("");
+  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s", file_name);
+  Progress progress(llvm::formatv("Parsing symbol table for {0}", file_name));
 
   llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0};
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 3323321 - [lldb] Fix log & progress report for in-memory binaries

2022-03-21 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-03-21T15:35:21-07:00
New Revision: 3323321f4ef04308c50a3dc4ad17dfa1e13d8477

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

LOG: [lldb] Fix log & progress report for in-memory binaries

Fix the log and progress report message for in-memory binaries. If
there's no object file, use the name from the Module. With this patch we
correctly show the library name when attaching to a remote process
without an expanded shared cache.

Differential revision: https://reviews.llvm.org/D122177

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index ff4d0a1cc41cf..d728978c3e3aa 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2201,14 +2201,14 @@ ParseNList(DataExtractor _data, lldb::offset_t 
_data_offset,
 enum { DebugSymbols = true, NonDebugSymbols = false };
 
 void ObjectFileMachO::ParseSymtab(Symtab ) {
-  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
- m_file.GetFilename().AsCString(""));
   ModuleSP module_sp(GetModule());
   if (!module_sp)
 return;
 
-  Progress progress(llvm::formatv("Parsing symbol table for {0}",
-  
m_file.GetFilename().AsCString("")));
+  const FileSpec  = m_file ? m_file : module_sp->GetFileSpec();
+  const char *file_name = file.GetFilename().AsCString("");
+  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s", file_name);
+  Progress progress(llvm::formatv("Parsing symbol table for {0}", file_name));
 
   llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 
0};



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


[Lldb-commits] [lldb] 45d9aab - Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

2022-03-21 Thread Jakob Johnson via lldb-commits

Author: Jakob Johnson
Date: 2022-03-21T15:02:02-07:00
New Revision: 45d9aab7a5a76b7317ec5571bc557158045a34df

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

LOG: Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

Failed buildbot: https://lab.llvm.org/buildbot/#/builders/17/builds/19490

Only run perf event tsc conversion test on x86_64.

Added: 


Modified: 
lldb/unittests/Process/Linux/PerfTests.cpp

Removed: 




diff  --git a/lldb/unittests/Process/Linux/PerfTests.cpp 
b/lldb/unittests/Process/Linux/PerfTests.cpp
index 3a1c08c11cdfb..934d680e8c38b 100644
--- a/lldb/unittests/Process/Linux/PerfTests.cpp
+++ b/lldb/unittests/Process/Linux/PerfTests.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#ifdef __x86_64__
+
 #include "Perf.h"
 
 #include "llvm/Support/Error.h"
@@ -83,3 +85,5 @@ TEST(Perf, TscConversion) {
   ASSERT_LT(converted_tsc_
diff .count(),
 (SLEEP_NANOS + acceptable_overhead).count());
 }
+
+#endif // __x86_64__



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


[Lldb-commits] [lldb] d137528 - Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

2022-03-21 Thread Jakob Johnson via lldb-commits

Author: Jakob Johnson
Date: 2022-03-21T14:35:14-07:00
New Revision: d13752851a4e134708f365a5b238e8ff375accaa

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

LOG: Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

Failed buildbot: https://lab.llvm.org/buildbot/#/builders/68/builds/29250

Use toString() to consume the Error

Added: 


Modified: 
lldb/unittests/Process/Linux/PerfTests.cpp

Removed: 




diff  --git a/lldb/unittests/Process/Linux/PerfTests.cpp 
b/lldb/unittests/Process/Linux/PerfTests.cpp
index f8467d7042ef7..3a1c08c11cdfb 100644
--- a/lldb/unittests/Process/Linux/PerfTests.cpp
+++ b/lldb/unittests/Process/Linux/PerfTests.cpp
@@ -61,7 +61,7 @@ TEST(Perf, TscConversion) {
 
   // Skip the test if the conversion parameters aren't available.
   if (!params)
-GTEST_SKIP() << params.takeError();
+GTEST_SKIP() << toString(params.takeError());
 
   Expected tsc_before_sleep = readTsc();
   sleep(SLEEP_SECS);
@@ -69,9 +69,9 @@ TEST(Perf, TscConversion) {
 
   // Skip the test if we are unable to read the TSC value.
   if (!tsc_before_sleep)
-GTEST_SKIP() << tsc_before_sleep.takeError();
+GTEST_SKIP() << toString(tsc_before_sleep.takeError());
   if (!tsc_after_sleep)
-GTEST_SKIP() << tsc_after_sleep.takeError();
+GTEST_SKIP() << toString(tsc_after_sleep.takeError());
 
   std::chrono::nanoseconds converted_tsc_
diff  =
   params->ToWallTime(*tsc_after_sleep) -



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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:38-41
+# Broadcast a eBroadcastBitStopListenerThread` event so the background
+# thread stops listening to events, then join the background thread.
+
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
+self.listener_thread.join()

labath wrote:
> This cannot be done in the tearDown method (without extra synchronisation) as 
> this is what guarantees that the events have been processed and can be read 
> from the event array. This is what caused [[ 
> https://lab.llvm.org/buildbot/#/builders/68/builds/29171 | 
> TestDiagnosticReporting.py ]] to flake. If you want to do the shutdown in the 
> tearDown method, then you'll need to introduce some other means of 
> synchronising and ensuring that the event array can be accessed safely and 
> contains all the things it is supposed to contain (e.g. through a new kind of 
> a message).
I knew this was going to bite us eventually :/ Should we get back to the 
`start/stop` approach ?



Comment at: 
lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py:15
+event_mask = lldb.SBDebugger.eBroadcastBitWarning | 
lldb.SBDebugger.eBroadcastBitError
+event_data_extractor = lldb.SBDebugger.GetDiagnosticFromEvent
 

labath wrote:
> Why not just queue the events themselves and let the user do whatever it 
> wants with them later?
We still need to setup the `event_mask` to filter out unwanted events from the 
source broadcaster.

We would have to set that up in the derived class `setUp` override.

@JDevlieghere do you have any other suggestion ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [lldb] e412529 - Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

2022-03-21 Thread Jakob Johnson via lldb-commits

Author: Jakob Johnson
Date: 2022-03-21T14:00:39-07:00
New Revision: e412529c93ae86d580b8212e07a0a2a0a8ab5cda

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

LOG: Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

Failed buildbot: https://lab.llvm.org/buildbot/#/builders/17/builds/19480

The fix seems to be simply be adding some type casts to make the compiler happy

Added: 


Modified: 
lldb/source/Plugins/Process/Linux/Perf.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/Linux/Perf.cpp 
b/lldb/source/Plugins/Process/Linux/Perf.cpp
index 944076784b36d..455a81fbcbaff 100644
--- a/lldb/source/Plugins/Process/Linux/Perf.cpp
+++ b/lldb/source/Plugins/Process/Linux/Perf.cpp
@@ -171,11 +171,11 @@ ArrayRef PerfEvent::GetDataBuffer() const {
   perf_event_mmap_page _metadata = GetMetadataPage();
   return {reinterpret_cast(m_metadata_data_base.get()) +
   mmap_metadata.data_offset,
-  mmap_metadata.data_size};
+   static_cast(mmap_metadata.data_size)};
 }
 
 ArrayRef PerfEvent::GetAuxBuffer() const {
   perf_event_mmap_page _metadata = GetMetadataPage();
   return {reinterpret_cast(m_aux_base.get()),
-  mmap_metadata.aux_size};
+   static_cast(mmap_metadata.aux_size)};
 }



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


[Lldb-commits] [lldb] e6c84f8 - Add thin wrapper for perf_event_open API

2022-03-21 Thread Jakob Johnson via lldb-commits

Author: Jakob Johnson
Date: 2022-03-21T13:38:52-07:00
New Revision: e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1

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

LOG: Add thin wrapper for perf_event_open API
  - Add PerfEvent class to handle creating ring buffers and handle the 
resources associated with a perf_event
  - Refactor IntelPT collection code to use this new API
  - Add TSC to timestamp conversion logic with unittest

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

Added: 
lldb/source/Plugins/Process/Linux/Perf.cpp
lldb/source/Plugins/Process/Linux/Perf.h
lldb/unittests/Process/Linux/PerfTests.cpp

Modified: 
lldb/source/Plugins/Process/Linux/CMakeLists.txt
lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
lldb/source/Plugins/Process/Linux/IntelPTCollector.h
lldb/unittests/Process/Linux/CMakeLists.txt
lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/Linux/CMakeLists.txt 
b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
index 60958bb913960..cc70edba3483e 100644
--- a/lldb/source/Plugins/Process/Linux/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
@@ -8,6 +8,7 @@ add_lldb_library(lldbPluginProcessLinux
   NativeRegisterContextLinux_s390x.cpp
   NativeRegisterContextLinux_x86_64.cpp
   NativeThreadLinux.cpp
+  Perf.cpp
   SingleStepCheck.cpp
 
   LINK_LIBS

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp 
b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index 0e65c88a1f765..5f31c10f8b88b 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
@@ -6,19 +6,23 @@
 //
 
//===--===//
 
-#include 
-#include 
-#include 
+#include "IntelPTCollector.h"
 
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/MathExtras.h"
+#include "Perf.h"
 
-#include "IntelPTCollector.h"
 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
 #include "lldb/Host/linux/Support.h"
 #include "lldb/Utility/StreamString.h"
 
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MathExtras.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 
@@ -53,6 +57,21 @@ enum IntelPTConfigFileType {
   BitOffset
 };
 
+/// Get the content of /proc/cpuinfo that can be later used to decode traces.
+static Expected> GetCPUInfo() {
+  static llvm::Optional> cpu_info;
+  if (!cpu_info) {
+auto buffer_or_error = errorOrToExpected(getProcFile("cpuinfo"));
+if (!buffer_or_error)
+  return buffer_or_error.takeError();
+MemoryBuffer  = **buffer_or_error;
+cpu_info = std::vector(
+reinterpret_cast(buffer.getBufferStart()),
+reinterpret_cast(buffer.getBufferEnd()));
+  }
+  return *cpu_info;
+}
+
 static Expected ReadIntelPTConfigFile(const char *file,
 IntelPTConfigFileType type) {
   ErrorOr> stream =
@@ -106,6 +125,7 @@ static Expected ReadIntelPTConfigFile(const char 
*file,
   }
   return value;
 }
+
 /// Return the Linux perf event type for Intel PT.
 static Expected GetOSEventType() {
   return ReadIntelPTConfigFile(kOSEventIntelPTTypeFile,
@@ -148,7 +168,7 @@ size_t IntelPTThreadTrace::GetTraceBufferSize() const {
 #ifndef PERF_ATTR_SIZE_VER5
   llvm_unreachable("Intel PT Linux perf event not supported");
 #else
-  return m_mmap_meta->aux_size;
+  return m_perf_event.GetAuxBuffer().size();
 #endif
 }
 
@@ -176,30 +196,9 @@ GeneratePerfEventConfigValue(bool enable_tsc, 
Optional psb_period) {
   return config;
 }
 
-Error IntelPTThreadTrace::StartTrace(lldb::pid_t pid, lldb::tid_t tid,
- uint64_t buffer_size, bool enable_tsc,
- Optional psb_period) {
-#ifndef PERF_ATTR_SIZE_VER5
-  llvm_unreachable("Intel PT Linux perf event not supported");
-#else
-  Log *log = GetLog(POSIXLog::Ptrace);
-
-  m_tid = tid;
-  LLDB_LOG(log, "called thread id {0}", tid);
-  uint64_t page_size = getpagesize();
-
-  if (__builtin_popcount(buffer_size) != 1 || buffer_size < 4096) {
-return createStringError(
-inconvertibleErrorCode(),
-"The trace buffer size must be a power of 2 greater than or equal to "
-"4096 (2^12) bytes. It was %" PRIu64 ".",
-buffer_size);
-  }
-  uint64_t numpages = static_cast(
-  llvm::PowerOf2Floor((buffer_size + page_size - 1) / page_size));
-  numpages = std::max(1, numpages);
-  buffer_size = page_size * numpages;
-
+llvm::Expected
+IntelPTThreadTrace::CreateIntelPTPerfEventConfiguration(
+bool enable_tsc, Optional psb_period) 

[Lldb-commits] [PATCH] D121734: [trace][intelpt] Add thin wrapper for perf_event_open API

2022-03-21 Thread Jakob Johnson via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6c84f82b875: Add thin wrapper for perf_event_open API 
(authored by jj10306).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121734

Files:
  lldb/source/Plugins/Process/Linux/CMakeLists.txt
  lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
  lldb/source/Plugins/Process/Linux/IntelPTCollector.h
  lldb/source/Plugins/Process/Linux/Perf.cpp
  lldb/source/Plugins/Process/Linux/Perf.h
  lldb/unittests/Process/Linux/CMakeLists.txt
  lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
  lldb/unittests/Process/Linux/PerfTests.cpp

Index: lldb/unittests/Process/Linux/PerfTests.cpp
===
--- /dev/null
+++ lldb/unittests/Process/Linux/PerfTests.cpp
@@ -0,0 +1,85 @@
+//===-- PerfTests.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 "Perf.h"
+
+#include "llvm/Support/Error.h"
+
+#include "gtest/gtest.h"
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace process_linux;
+using namespace llvm;
+
+/// Helper function to read current TSC value.
+///
+/// This code is based on llvm/xray.
+static Expected readTsc() {
+
+  unsigned int eax, ebx, ecx, edx;
+
+  // We check whether rdtscp support is enabled. According to the x86_64 manual,
+  // level should be set at 0x8001, and we should have a look at bit 27 in
+  // EDX. That's 0x800 (or 1u << 27).
+  __asm__ __volatile__("cpuid"
+   : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
+   : "0"(0x8001));
+  if (!(edx & (1u << 27))) {
+return createStringError(inconvertibleErrorCode(),
+ "Missing rdtscp support.");
+  }
+
+  unsigned cpu;
+  unsigned long rax, rdx;
+
+  __asm__ __volatile__("rdtscp\n" : "=a"(rax), "=d"(rdx), "=c"(cpu)::);
+
+  return (rdx << 32) + rax;
+}
+
+// Test TSC to walltime conversion based on perf conversion values.
+TEST(Perf, TscConversion) {
+  // This test works by first reading the TSC value directly before
+  // and after sleeping, then converting these values to nanoseconds, and
+  // finally ensuring the difference is approximately equal to the sleep time.
+  //
+  // There will be slight overhead associated with the sleep call, so it isn't
+  // reasonable to expect the difference to be exactly equal to the sleep time.
+
+  const int SLEEP_SECS = 1;
+  std::chrono::nanoseconds SLEEP_NANOS{std::chrono::seconds(SLEEP_SECS)};
+
+  Expected params =
+  FetchPerfTscConversionParameters();
+
+  // Skip the test if the conversion parameters aren't available.
+  if (!params)
+GTEST_SKIP() << params.takeError();
+
+  Expected tsc_before_sleep = readTsc();
+  sleep(SLEEP_SECS);
+  Expected tsc_after_sleep = readTsc();
+
+  // Skip the test if we are unable to read the TSC value.
+  if (!tsc_before_sleep)
+GTEST_SKIP() << tsc_before_sleep.takeError();
+  if (!tsc_after_sleep)
+GTEST_SKIP() << tsc_after_sleep.takeError();
+
+  std::chrono::nanoseconds converted_tsc_diff =
+  params->ToWallTime(*tsc_after_sleep) -
+  params->ToWallTime(*tsc_before_sleep);
+
+  std::chrono::microseconds acceptable_overhead(500);
+
+  ASSERT_GE(converted_tsc_diff.count(), SLEEP_NANOS.count());
+  ASSERT_LT(converted_tsc_diff.count(),
+(SLEEP_NANOS + acceptable_overhead).count());
+}
Index: lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
===
--- lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
+++ lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
@@ -20,8 +20,8 @@
   size_t offset) {
   llvm::MutableArrayRef dst(reinterpret_cast(buf),
  buf_size);
-  llvm::MutableArrayRef src(reinterpret_cast(cyc_buf),
- cyc_buf_size);
+  llvm::ArrayRef src(reinterpret_cast(cyc_buf),
+  cyc_buf_size);
   IntelPTThreadTrace::ReadCyclicBuffer(dst, src, cyc_start, offset);
   return dst.size();
 }
Index: lldb/unittests/Process/Linux/CMakeLists.txt
===
--- lldb/unittests/Process/Linux/CMakeLists.txt
+++ lldb/unittests/Process/Linux/CMakeLists.txt
@@ -1,9 +1,10 @@
-add_lldb_unittest(TraceIntelPTTests
+add_lldb_unittest(ProcessLinuxTests
   IntelPTCollectorTests.cpp
+  PerfTests.cpp
 
   LINK_LIBS
 lldbPluginProcessLinux
   )
 

[Lldb-commits] [PATCH] D122176: [trace] clear any existing tracing sessions before relaunching the binary

2022-03-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 417082.
wallace added a comment.

improve test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122176

Files:
  lldb/source/Target/Target.cpp
  lldb/test/API/commands/trace/TestTraceStartStop.py


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+# For this, we'll trace starting at a different point in the new
+# process.
+self.expect("breakpoint disable")
+self.expect("b main.cpp:4")
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("si")
+self.expect("thread trace dump instructions -c 1",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 11 at main.cpp:4'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+# For this, we'll trace starting at a different point in the new
+# process.
+self.expect("breakpoint disable")
+self.expect("b main.cpp:4")
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("si")
+self.expect("thread trace dump instructions -c 1",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 11 at main.cpp:4'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122177: [lldb] Fix log & progress report for in-memory binaries

2022-03-21 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D122177

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


[Lldb-commits] [PATCH] D122177: [lldb] Fix log & progress report for in-memory binaries

2022-03-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: jasonmolenda, clayborg.
Herald added a project: All.
JDevlieghere requested review of this revision.

Fix the log and progress report message for in-memory binaries. If there's no 
object file, use the name from the Module. With this patch we correctly show 
the library name when attaching to a remote process without an expanded shared 
cache.


https://reviews.llvm.org/D122177

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2201,14 +2201,16 @@
 enum { DebugSymbols = true, NonDebugSymbols = false };
 
 void ObjectFileMachO::ParseSymtab(Symtab ) {
-  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
- m_file.GetFilename().AsCString(""));
   ModuleSP module_sp(GetModule());
   if (!module_sp)
 return;
 
+  const FileSpec  = m_file ? m_file : module_sp->GetFileSpec();
+  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
+ file.GetFilename().AsCString(""));
+
   Progress progress(llvm::formatv("Parsing symbol table for {0}",
-  
m_file.GetFilename().AsCString("")));
+  file.GetFilename().AsCString("")));
 
   llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 
0};


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2201,14 +2201,16 @@
 enum { DebugSymbols = true, NonDebugSymbols = false };
 
 void ObjectFileMachO::ParseSymtab(Symtab ) {
-  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
- m_file.GetFilename().AsCString(""));
   ModuleSP module_sp(GetModule());
   if (!module_sp)
 return;
 
+  const FileSpec  = m_file ? m_file : module_sp->GetFileSpec();
+  LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s",
+ file.GetFilename().AsCString(""));
+
   Progress progress(llvm::formatv("Parsing symbol table for {0}",
-  m_file.GetFilename().AsCString("")));
+  file.GetFilename().AsCString("")));
 
   llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0};
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122176: [trace] clear any existing tracing sessions before relaunching the binary

2022-03-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: jj10306, zrthxn.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

There's a bug caused when a process is relaunched: the target, which
doesn't change, keeps the Trace object from the previous process, which
is already defunct, and causes segmentation faults when it's attempted
to be used.
A fix is to clean up the Trace object when the target is disposing of
the previous process during relaunches.

A way to reproduce this:

  lldb a.out
  b main
  r
  process trace start
  c
  r
  process trace start


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122176

Files:
  lldb/source/Target/Target.cpp
  lldb/test/API/commands/trace/TestTraceStartStop.py


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,13 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("n")
+self.expect("thread trace dump instructions -f",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 4 at main.cpp:2
+\[ 0\] {ADDRESS_REGEX}movl'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,13 @@
 
 self.expect("thread trace stop", error=True,
 substrs=["error: Process must be launched"])
+
+# We should be able to trace the program if we relaunch it
+self.expect("r")
+self.expect("thread trace start")
+# We can reconstruct the single instruction executed in the first line
+self.expect("n")
+self.expect("thread trace dump instructions -f",
+patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 4 at main.cpp:2
+\[ 0\] {ADDRESS_REGEX}movl'''])
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+// We dispose any active tracing sessions on the current process
+m_trace_sp.reset();
 m_section_load_history.Clear();
 if (m_process_sp->IsAlive())
   m_process_sp->Destroy(false);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122041: [llvm][utils] Fix llvm::Optional summary provider

2022-03-21 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added a comment.

Do we have any tests for these?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122041

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


[Lldb-commits] [PATCH] D121631: Introduce new symbol on-demand for debug info

2022-03-21 Thread jeffrey tan via Phabricator via lldb-commits
yinghuitan updated this revision to Diff 417049.
yinghuitan added a comment.

Remove last ondemand test flavor testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121631

Files:
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Symbol/SymbolFileOnDemand.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/LLDBLog.h
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/CompileUnit.cpp
  lldb/source/Symbol/SymbolFile.cpp
  lldb/source/Symbol/SymbolFileOnDemand.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/LLDBLog.cpp
  lldb/test/API/symbol_ondemand/breakpoint_language/Makefile
  lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguage.py
  lldb/test/API/symbol_ondemand/breakpoint_language/c_lang.c
  lldb/test/API/symbol_ondemand/breakpoint_language/cpp_lang.cpp
  lldb/test/API/symbol_ondemand/breakpoint_language/main.cpp
  lldb/test/API/symbol_ondemand/breakpoint_source_regex/Makefile
  
lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py
  lldb/test/API/symbol_ondemand/breakpoint_source_regex/main.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/basic.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/lib.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/lib.h
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/shared.cpp
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib-globals-hydration.test
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib-globals.test
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
  lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
  lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test

Index: lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test
@@ -0,0 +1,24 @@
+
+# Test shows that symbolic function breakpoint works with LLDB on demand symbol loading.
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %build %p/Inputs/basic.cpp -o basic.out
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s basic.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+b bar
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+breakpoint list
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+run
+# CHECK: stop reason = breakpoint
+
+bt
+# CHECK: {{.*}}`bar(x=33, y=78) at basic.cpp:1
+# CHECK: {{.*}}`foo(x=33, y=78) at basic.cpp:3
+# CHECK: {{.*}}`main(argc=1, argv={{.*}}) at basic.cpp:5
Index: lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
@@ -0,0 +1,23 @@
+# Test shows that source line breakpoint works with LLDB on demand symbol loading.
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %build %p/Inputs/basic.cpp -o basic.out
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s basic.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+breakpoint set -f basic.cpp -l 1
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+breakpoint list
+# CHECK: file = 'basic.cpp'
+
+run
+# CHECK: stop reason = breakpoint
+
+bt
+# CHECK: {{.*}}`bar(x=33, y=78) at basic.cpp:1
+# CHECK: {{.*}}`foo(x=33, y=78) at basic.cpp:3
+# CHECK: {{.*}}`main(argc=1, argv={{.*}}) at basic.cpp:5
Index: lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
@@ -0,0 +1,37 @@
+# Test shows that source line breakpoint works in multiple shared libraries with LLDB on demand symbol loading.
+
+# REQUIRES: system-linux
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %clang_host -shared -g -fpic %p/Inputs/lib.cpp -o libFoo.so
+# RUN: %clang_host -L%t -g -o shared.out %p/Inputs/shared.cpp -lFoo -Wl,-rpath=%t
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s shared.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+breakpoint set -f lib.cpp -l 4
+# CHECK: where = {{.*}}`foo() + {{.*}} at lib.cpp:4
+
+breakpoint list
+# CHECK: file = 'lib.cpp', line = 4
+
+run
+# CHECK: stop reason = breakpoint
+# CHECK: foo() at lib.cpp:4
+
+bt
+# CHECK: {{.*}}`foo() at lib.cpp:4
+# CHECK: at shared.cpp:7
+
+breakpoint set -f shared.cpp -l 8
+# CHECK: at shared.cpp:8
+
+breakpoint list
+# CHECK: file = 'lib.cpp', line = 4
+# CHECK: file = 'shared.cpp', line = 8
+
+continue
+# CHECK: stop reason = breakpoint
+# CHECK: at 

[Lldb-commits] [PATCH] D121631: Introduce new symbol on-demand for debug info

2022-03-21 Thread jeffrey tan via Phabricator via lldb-commits
yinghuitan updated this revision to Diff 417048.
yinghuitan added a comment.

Remove ondemand test category/flavor
Add new testcases:

- source text regex breakpoint
- regex breakpoint filter by language
- global variable symbol table match hydration


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121631

Files:
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Symbol/SymbolFileOnDemand.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/LLDBLog.h
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/CompileUnit.cpp
  lldb/source/Symbol/SymbolFile.cpp
  lldb/source/Symbol/SymbolFileOnDemand.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/LLDBLog.cpp
  lldb/test/API/lang/cpp/enum_types/TestCPP11EnumTypes.py
  lldb/test/API/symbol_ondemand/breakpoint_language/Makefile
  lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguage.py
  lldb/test/API/symbol_ondemand/breakpoint_language/c_lang.c
  lldb/test/API/symbol_ondemand/breakpoint_language/cpp_lang.cpp
  lldb/test/API/symbol_ondemand/breakpoint_language/main.cpp
  lldb/test/API/symbol_ondemand/breakpoint_source_regex/Makefile
  
lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py
  lldb/test/API/symbol_ondemand/breakpoint_source_regex/main.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/basic.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/lib.cpp
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/lib.h
  lldb/test/Shell/SymbolFile/OnDemand/Inputs/shared.cpp
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib-globals-hydration.test
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib-globals.test
  lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
  lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
  lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test

Index: lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test
@@ -0,0 +1,24 @@
+
+# Test shows that symbolic function breakpoint works with LLDB on demand symbol loading.
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %build %p/Inputs/basic.cpp -o basic.out
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s basic.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+b bar
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+breakpoint list
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+run
+# CHECK: stop reason = breakpoint
+
+bt
+# CHECK: {{.*}}`bar(x=33, y=78) at basic.cpp:1
+# CHECK: {{.*}}`foo(x=33, y=78) at basic.cpp:3
+# CHECK: {{.*}}`main(argc=1, argv={{.*}}) at basic.cpp:5
Index: lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test
@@ -0,0 +1,23 @@
+# Test shows that source line breakpoint works with LLDB on demand symbol loading.
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %build %p/Inputs/basic.cpp -o basic.out
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s basic.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+breakpoint set -f basic.cpp -l 1
+# CHECK: where = {{.*}}`bar(int, int) + {{.*}} at basic.cpp:1
+
+breakpoint list
+# CHECK: file = 'basic.cpp'
+
+run
+# CHECK: stop reason = breakpoint
+
+bt
+# CHECK: {{.*}}`bar(x=33, y=78) at basic.cpp:1
+# CHECK: {{.*}}`foo(x=33, y=78) at basic.cpp:3
+# CHECK: {{.*}}`main(argc=1, argv={{.*}}) at basic.cpp:5
Index: lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/OnDemand/shared-lib.test
@@ -0,0 +1,37 @@
+# Test shows that source line breakpoint works in multiple shared libraries with LLDB on demand symbol loading.
+
+# REQUIRES: system-linux
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: %clang_host -shared -g -fpic %p/Inputs/lib.cpp -o libFoo.so
+# RUN: %clang_host -L%t -g -o shared.out %p/Inputs/shared.cpp -lFoo -Wl,-rpath=%t
+# RUN: %lldb -b -O "settings set symbols.load-on-demand true" -s %s shared.out | FileCheck %s
+
+breakpoint list
+# CHECK: No breakpoints currently set
+
+breakpoint set -f lib.cpp -l 4
+# CHECK: where = {{.*}}`foo() + {{.*}} at lib.cpp:4
+
+breakpoint list
+# CHECK: file = 'lib.cpp', line = 4
+
+run
+# CHECK: stop reason = breakpoint
+# CHECK: foo() at lib.cpp:4
+
+bt
+# CHECK: {{.*}}`foo() at lib.cpp:4
+# CHECK: at shared.cpp:7
+
+breakpoint set -f 

[Lldb-commits] [PATCH] D122041: [llvm][utils] Fix llvm::Optional summary provider

2022-03-21 Thread Dave Lee via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG826bdf51ff31: [lldb] Fix llvm::Optional summary provider 
(authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122041

Files:
  llvm/utils/lldbDataFormatters.py


Index: llvm/utils/lldbDataFormatters.py
===
--- llvm/utils/lldbDataFormatters.py
+++ llvm/utils/lldbDataFormatters.py
@@ -138,7 +138,11 @@
 
 def OptionalSummaryProvider(valobj, internal_dict):
 val = GetOptionalValue(valobj)
-return val.summary if val else 'None'
+if val is None:
+return 'None'
+if val.summary:
+return val.summary
+return ''
 
 class OptionalSynthProvider:
 """Provides deref support to llvm::Optional"""


Index: llvm/utils/lldbDataFormatters.py
===
--- llvm/utils/lldbDataFormatters.py
+++ llvm/utils/lldbDataFormatters.py
@@ -138,7 +138,11 @@
 
 def OptionalSummaryProvider(valobj, internal_dict):
 val = GetOptionalValue(valobj)
-return val.summary if val else 'None'
+if val is None:
+return 'None'
+if val.summary:
+return val.summary
+return ''
 
 class OptionalSynthProvider:
 """Provides deref support to llvm::Optional"""
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D122114: [tests][intelpt] Fix outdated trace load test

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca47011e73e6: [tests][intelpt] Fix outdated trace load test 
(authored by zrthxn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122114

Files:
  lldb/test/API/commands/trace/TestTraceLoad.py


Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -36,7 +36,9 @@
 self.expect("thread trace dump info", substrs=['''Trace technology: 
intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()


Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -36,7 +36,9 @@
 self.expect("thread trace dump info", substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] ca47011 - [tests][intelpt] Fix outdated trace load test

2022-03-21 Thread Alisamar Husain via lldb-commits

Author: Alisamar Husain
Date: 2022-03-21T13:21:45+05:30
New Revision: ca47011e73e6ff0451b6a9c8de3d3f3044acec72

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

LOG: [tests][intelpt] Fix outdated trace load test

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

Added: 


Modified: 
lldb/test/API/commands/trace/TestTraceLoad.py

Removed: 




diff  --git a/lldb/test/API/commands/trace/TestTraceLoad.py 
b/lldb/test/API/commands/trace/TestTraceLoad.py
index 896f0eade663f..f901e2b2d9eb6 100644
--- a/lldb/test/API/commands/trace/TestTraceLoad.py
+++ b/lldb/test/API/commands/trace/TestTraceLoad.py
@@ -36,7 +36,9 @@ def testLoadTrace(self):
 self.expect("thread trace dump info", substrs=['''Trace technology: 
intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()



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


[Lldb-commits] [PATCH] D122114: [tests][intelpt] Fix outdated trace load test

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn created this revision.
zrthxn added reviewers: wallace, jj10306.
Herald added a project: All.
zrthxn requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122114

Files:
  lldb/test/API/commands/trace/TestTraceLoad.py


Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -36,7 +36,9 @@
 self.expect("thread trace dump info", substrs=['''Trace technology: 
intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()


Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -36,7 +36,9 @@
 self.expect("thread trace dump info", substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-21 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I've reverted this patch because it introduces races in the event processing. 
See inline comment for details.




Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:38-41
+# Broadcast a eBroadcastBitStopListenerThread` event so the background
+# thread stops listening to events, then join the background thread.
+
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
+self.listener_thread.join()

This cannot be done in the tearDown method (without extra synchronisation) as 
this is what guarantees that the events have been processed and can be read 
from the event array. This is what caused [[ 
https://lab.llvm.org/buildbot/#/builders/68/builds/29171 | 
TestDiagnosticReporting.py ]] to flake. If you want to do the shutdown in the 
tearDown method, then you'll need to introduce some other means of 
synchronising and ensuring that the event array can be accessed safely and 
contains all the things it is supposed to contain (e.g. through a new kind of a 
message).



Comment at: 
lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py:15
+event_mask = lldb.SBDebugger.eBroadcastBitWarning | 
lldb.SBDebugger.eBroadcastBitError
+event_data_extractor = lldb.SBDebugger.GetDiagnosticFromEvent
 

Why not just queue the events themselves and let the user do whatever it wants 
with them later?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [lldb] 8bf8934 - Revert "[lldb/test] Add events listener helper class to lldbtest"

2022-03-21 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-21T08:32:16+01:00
New Revision: 8bf893466632cc2597188b431160effcd8cedeef

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

LOG: Revert "[lldb/test] Add events listener helper class to lldbtest"

It removes the "wait-until-event-thread-stops" logic, which makes
TestDiagnosticReporting.py flaky.

This reverts commits 09ff41a087760ea7e80b8e5390a05101c5a5b929 and
acdd41b4590935e39208a941fbac7889d778e8e5.

Added: 


Modified: 

lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Removed: 
lldb/packages/Python/lldbsuite/test/eventlistener.py



diff  --git a/lldb/packages/Python/lldbsuite/test/eventlistener.py 
b/lldb/packages/Python/lldbsuite/test/eventlistener.py
deleted file mode 100644
index 2bf53fe2d75b5..0
--- a/lldb/packages/Python/lldbsuite/test/eventlistener.py
+++ /dev/null
@@ -1,72 +0,0 @@
-import threading
-
-import lldb
-from lldbsuite.test.lldbtest import *
-
-class EventListenerTestBase(TestBase):
-
-"""
-Base class for lldb event listener tests.
-
-This class will setup and start an event listener for the test to use.
-
-If the event received matches the source broadcaster, the event is
-queued up in a list that the user can access later on.
-"""
-NO_DEBUG_INFO_TESTCASE = True
-
-eBroadcastBitStopListenerThread = (1 << 0)
-events = []
-event_mask = None
-event_data_extractor = None
-
-def setUp(self):
-TestBase.setUp(self)
-
-self.src_broadcaster = self.dbg.GetBroadcaster()
-self.broadcaster = lldb.SBBroadcaster('lldb.test.broadcaster')
-self.listener = lldb.SBListener("lldb.test.listener")
-self.listener.StartListeningForEvents(self.broadcaster,
-  
self.eBroadcastBitStopListenerThread)
-
-self.src_broadcaster.AddListener(self.listener, self.event_mask)
-
-self.listener_thread = threading.Thread(target=self._fetch_events)
-self.listener_thread.start()
-
-def tearDown(self):
-# Broadcast a `eBroadcastBitStopListenerThread` event so the background
-# thread stops listening to events, then join the background thread.
-
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
-self.listener_thread.join()
-TestBase.tearDown(self)
-
-def _fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.GetNextEvent(event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.broadcaster):
-if event_mask & self.eBroadcastBitStopListenerThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.src_broadcaster):
-# NOTE: https://wiki.python.org/moin/FromFunctionToMethod
-#
-# When assigning the `event_data_extractor` function 
pointer
-# to the `EventListenerTestBase` instance, it turns the
-# function object into an instance method which 
subsequently
-# passes `self` as an extra argument.
-
-# However, because most of the event data extractor
-# functions are static, passing the `self` argument makes
-# the number of passed arguments exceeds the function 
definition
-
-# This is why we unwrap the function from the instance
-# method object calling `__func__` instead.
-ret_args = self.event_data_extractor.__func__(event)
-if not ret_args:
-continue
-
-self.events.append(ret_args)

diff  --git 
a/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py 
b/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
index e78c34b599e11..1bfc313e8381f 100644
--- 
a/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ 
b/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,20 +2,51 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
 import lldbsuite.test.lldbutil as lldbutil
+import threading
 
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(EventListenerTestBase):
+class TestDiagnosticReporting(TestBase):
 
 mydir = 

[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37a466dd72b0: [trace][intelpt] Added total memory usage by 
decoded trace (authored by zrthxn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@
 return;
   }
   s.Printf("\n");
-  s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
-  s.Printf("  Total number of instructions: %zu\n", 
-Decode(thread)->GetInstructions().size());
+
+  size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage();
+  s.Printf("  Raw trace size: %zu KiB\n", *raw_size / 1024);
+  s.Printf("  Total number of instructions: %zu\n",
+   Decode(thread)->GetInstructions().size());
+  s.Printf("  Total approximate memory usage: %0.2lf KiB\n",
+   (double)mem_used / 1024);
   return;
 }
 
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -81,6 +81,9 @@
   /// The instruction pointer address, or \a LLDB_INVALID_ADDRESS if it is
   /// an error.
   lldb::addr_t GetLoadAddress() const;
+  
+  /// Get the size in bytes of a non-error instance of this class
+  static size_t GetNonErrorMemoryUsage();
 
   /// \return
   /// An \a llvm::Error object if this class corresponds to an Error, or an
@@ -112,6 +115,8 @@
   IntelPTInstruction(const IntelPTInstruction ) = delete;
   const IntelPTInstruction =(const IntelPTInstruction ) = 
delete;
 
+  // When adding new members to this class, make sure to update 
+  // IntelPTInstruction::GetNonErrorMemoryUsage() if needed.
   pt_insn m_pt_insn;
   llvm::Optional m_timestamp;
   std::unique_ptr m_error;
@@ -150,7 +155,13 @@
   ///   The size of the trace.
   size_t GetRawTraceSize() const;
 
+  /// The approximate size in bytes used by this instance, 
+  /// including all the already decoded instructions.
+  size_t CalculateApproximateMemoryUsage() const;
+
 private:
+  /// When adding new members to this class, make sure 
+  /// to update \a CalculateApproximateMemoryUsage() accordingly.
   lldb::ThreadSP m_thread_sp;
   std::vector m_instructions;
   size_t m_raw_trace_size;
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -48,6 +48,8 @@
 
 lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; 
}
 
+size_t IntelPTInstruction::GetNonErrorMemoryUsage() { return 
sizeof(IntelPTInstruction); }
+
 Optional IntelPTInstruction::GetTimestampCounter() const {
   return m_timestamp;
 }
@@ -116,3 +118,9 @@
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::CalculateApproximateMemoryUsage() const {
+  return m_raw_trace_size
++ IntelPTInstruction::GetNonErrorMemoryUsage() * m_instructions.size()
++ sizeof(DecodedThread);
+}


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@
 return;
   }
   

[Lldb-commits] [lldb] 37a466d - [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread Alisamar Husain via lldb-commits

Author: Alisamar Husain
Date: 2022-03-21T12:36:08+05:30
New Revision: 37a466dd72b0c46090198c9f1779c384809c0662

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

LOG: [trace][intelpt] Added total memory usage by decoded trace

This fails currently but the basics are there

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

Added: 


Modified: 
lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
lldb/test/API/commands/trace/TestTraceDumpInfo.py

Removed: 




diff  --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
index 4822a786c68c1..a81a779302605 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -48,6 +48,8 @@ bool IntelPTInstruction::IsError() const { return 
(bool)m_error; }
 
 lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; 
}
 
+size_t IntelPTInstruction::GetNonErrorMemoryUsage() { return 
sizeof(IntelPTInstruction); }
+
 Optional IntelPTInstruction::GetTimestampCounter() const {
   return m_timestamp;
 }
@@ -116,3 +118,9 @@ DecodedThread::DecodedThread(ThreadSP thread_sp,
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::CalculateApproximateMemoryUsage() const {
+  return m_raw_trace_size
++ IntelPTInstruction::GetNonErrorMemoryUsage() * m_instructions.size()
++ sizeof(DecodedThread);
+}

diff  --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
index 592c402cd0e50..4063012997045 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -81,6 +81,9 @@ class IntelPTInstruction {
   /// The instruction pointer address, or \a LLDB_INVALID_ADDRESS if it is
   /// an error.
   lldb::addr_t GetLoadAddress() const;
+  
+  /// Get the size in bytes of a non-error instance of this class
+  static size_t GetNonErrorMemoryUsage();
 
   /// \return
   /// An \a llvm::Error object if this class corresponds to an Error, or an
@@ -112,6 +115,8 @@ class IntelPTInstruction {
   IntelPTInstruction(const IntelPTInstruction ) = delete;
   const IntelPTInstruction =(const IntelPTInstruction ) = 
delete;
 
+  // When adding new members to this class, make sure to update 
+  // IntelPTInstruction::GetNonErrorMemoryUsage() if needed.
   pt_insn m_pt_insn;
   llvm::Optional m_timestamp;
   std::unique_ptr m_error;
@@ -150,7 +155,13 @@ class DecodedThread : public 
std::enable_shared_from_this {
   ///   The size of the trace.
   size_t GetRawTraceSize() const;
 
+  /// The approximate size in bytes used by this instance, 
+  /// including all the already decoded instructions.
+  size_t CalculateApproximateMemoryUsage() const;
+
 private:
+  /// When adding new members to this class, make sure 
+  /// to update \a CalculateApproximateMemoryUsage() accordingly.
   lldb::ThreadSP m_thread_sp;
   std::vector m_instructions;
   size_t m_raw_trace_size;

diff  --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
index 831cd3764672c..63318031f8893 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@ void TraceIntelPT::DumpTraceInfo(Thread , Stream 
, bool verbose) {
 return;
   }
   s.Printf("\n");
-  s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
-  s.Printf("  Total number of instructions: %zu\n", 
-Decode(thread)->GetInstructions().size());
+
+  size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage();
+  s.Printf("  Raw trace size: %zu KiB\n", *raw_size / 1024);
+  s.Printf("  Total number of instructions: %zu\n",
+   Decode(thread)->GetInstructions().size());
+  s.Printf("  Total approximate memory usage: %0.2lf KiB\n",
+   (double)mem_used / 1024);
   return;
 }
 

diff  --git a/lldb/test/API/commands/trace/TestTraceDumpInfo.py 
b/lldb/test/API/commands/trace/TestTraceDumpInfo.py
index 18088e07b8df3..bc50b5274195a 100644
--- a/lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ b/lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@ def testDumpRawTraceSize(self):
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])




[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

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


[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 416826.
zrthxn added a comment.

Ingore errored instructions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@
 return;
   }
   s.Printf("\n");
-  s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
-  s.Printf("  Total number of instructions: %zu\n", 
-Decode(thread)->GetInstructions().size());
+
+  size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage();
+  s.Printf("  Raw trace size: %zu KiB\n", *raw_size / 1024);
+  s.Printf("  Total number of instructions: %zu\n",
+   Decode(thread)->GetInstructions().size());
+  s.Printf("  Total approximate memory usage: %0.2lf KiB\n",
+   (double)mem_used / 1024);
   return;
 }
 
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -81,6 +81,9 @@
   /// The instruction pointer address, or \a LLDB_INVALID_ADDRESS if it is
   /// an error.
   lldb::addr_t GetLoadAddress() const;
+  
+  /// Get the size in bytes of a non-error instance of this class
+  static size_t GetNonErrorMemoryUsage();
 
   /// \return
   /// An \a llvm::Error object if this class corresponds to an Error, or an
@@ -112,6 +115,8 @@
   IntelPTInstruction(const IntelPTInstruction ) = delete;
   const IntelPTInstruction =(const IntelPTInstruction ) = 
delete;
 
+  // When adding new members to this class, make sure to update 
+  // IntelPTInstruction::GetNonErrorMemoryUsage() if needed.
   pt_insn m_pt_insn;
   llvm::Optional m_timestamp;
   std::unique_ptr m_error;
@@ -150,7 +155,13 @@
   ///   The size of the trace.
   size_t GetRawTraceSize() const;
 
+  /// The approximate size in bytes used by this instance, 
+  /// including all the already decoded instructions.
+  size_t CalculateApproximateMemoryUsage() const;
+
 private:
+  /// When adding new members to this class, make sure 
+  /// to update \a CalculateApproximateMemoryUsage() accordingly.
   lldb::ThreadSP m_thread_sp;
   std::vector m_instructions;
   size_t m_raw_trace_size;
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -48,6 +48,8 @@
 
 lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; 
}
 
+size_t IntelPTInstruction::GetNonErrorMemoryUsage() { return 
sizeof(IntelPTInstruction); }
+
 Optional IntelPTInstruction::GetTimestampCounter() const {
   return m_timestamp;
 }
@@ -116,3 +118,9 @@
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::CalculateApproximateMemoryUsage() const {
+  return m_raw_trace_size
++ IntelPTInstruction::GetNonErrorMemoryUsage() * m_instructions.size()
++ sizeof(DecodedThread);
+}


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@
 return;
   }
   s.Printf("\n");
-  s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
-  s.Printf("  Total 

[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace requested changes to this revision.
wallace added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:123-130
+  size_t non_err_instruction_count = 0;
+  for (const IntelPTInstruction  : m_instructions)
+if (!insn.IsError())
+  non_err_instruction_count++;
+
+  return m_raw_trace_size
++ IntelPTInstruction::GetNonErrorMemoryUsage() * non_err_instruction_count

as discussed offline, this should just be


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

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


[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 416825.
zrthxn marked an inline comment as done.
zrthxn added a comment.

Cosmetic and minor changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -111,9 +111,13 @@
 return;
   }
   s.Printf("\n");
-  s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
-  s.Printf("  Total number of instructions: %zu\n", 
-Decode(thread)->GetInstructions().size());
+
+  size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage();
+  s.Printf("  Raw trace size: %zu KiB\n", *raw_size / 1024);
+  s.Printf("  Total number of instructions: %zu\n",
+   Decode(thread)->GetInstructions().size());
+  s.Printf("  Total approximate memory usage: %0.2lf KiB\n",
+   (double)mem_used / 1024);
   return;
 }
 
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -81,6 +81,9 @@
   /// The instruction pointer address, or \a LLDB_INVALID_ADDRESS if it is
   /// an error.
   lldb::addr_t GetLoadAddress() const;
+  
+  /// Get the size in bytes of a non-error instance of this class
+  size_t GetNonErrorMemoryUsage() const;
 
   /// \return
   /// An \a llvm::Error object if this class corresponds to an Error, or an
@@ -112,6 +115,8 @@
   IntelPTInstruction(const IntelPTInstruction ) = delete;
   const IntelPTInstruction =(const IntelPTInstruction ) = 
delete;
 
+  // When adding new members to this class, make sure to update 
+  // IntelPTInstruction::GetNonErrorMemoryUsage() if needed.
   pt_insn m_pt_insn;
   llvm::Optional m_timestamp;
   std::unique_ptr m_error;
@@ -150,7 +155,13 @@
   ///   The size of the trace.
   size_t GetRawTraceSize() const;
 
+  /// The approximate size in bytes used by this instance, 
+  /// including all the already decoded instructions.
+  size_t CalculateApproximateMemoryUsage() const;
+
 private:
+  /// When adding new members to this class, make sure 
+  /// to update \a CalculateApproximateMemoryUsage() accordingly.
   lldb::ThreadSP m_thread_sp;
   std::vector m_instructions;
   size_t m_raw_trace_size;
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -48,6 +48,8 @@
 
 lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; 
}
 
+size_t IntelPTInstruction::GetNonErrorMemoryUsage() const { return 
sizeof(IntelPTInstruction); }
+
 Optional IntelPTInstruction::GetTimestampCounter() const {
   return m_timestamp;
 }
@@ -116,3 +118,14 @@
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::CalculateApproximateMemoryUsage() const {
+  size_t non_err_instruction_count = 0;
+  for (const IntelPTInstruction  : m_instructions)
+if (!insn.IsError())
+  non_err_instruction_count++;
+
+  return m_raw_trace_size
++ IntelPTInstruction::GetNonErrorMemoryUsage() * non_err_instruction_count
++ sizeof(DecodedThread);
+}


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -38,5 +38,6 @@
 substrs=['''Trace technology: intel-pt
 
 thread #1: tid = 3842849
-  Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Raw trace size: 4 KiB
+  Total number of instructions: 21
+  Total approximate memory usage: 5.38 KiB'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- 

[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

2022-03-21 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn marked 4 inline comments as done.
zrthxn added inline comments.



Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:119
+  s.Printf("  Total approximate memory usage: %0.2lf KiB\n",
+   (float)mem_used / 1024);
   return;

wallace wrote:
> use double instead of float. double has more precision
But since we're showing only two decimal places, which gets rounded up, the 
precision eventually gets thrown away... doesn't it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093

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