[Lldb-commits] [lldb] c30c37c - Revert "[lldb] fix test expectation broken by clang fix at D110216"

2021-11-12 Thread Adrian Kuegel via lldb-commits

Author: Adrian Kuegel
Date: 2021-11-12T13:21:30+01:00
New Revision: c30c37c00a501e21f36f13109795dd5f95e1d937

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

LOG: Revert "[lldb] fix test expectation broken by clang fix at D110216"

This reverts commit 55085952175ed3b029097a0594acc4e34a5df218.
The patch it depends on is reverted.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp 
b/lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp
index 69d8d17179fe9..75f9a029d448c 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp
+++ b/lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp
@@ -118,7 +118,7 @@ auto aab = &unary;
 auto aac = &unary;
 // CHECK: (void (*)(int (&&)[5])) aac = {{.*}}
 auto aad = &unary;
-// CHECK: (void (*)(int (*const)[5])) aad = {{.*}}
+// CHECK: (void (*)(int (*)[5])) aad = {{.*}}
 
 
 // same test cases with return values, note we can't overload on return type



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


[Lldb-commits] [PATCH] D113760: next

2021-11-12 Thread Danil Stefaniuc via Phabricator via lldb-commits
danilashtefan created this revision.
danilashtefan 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/D113760

Files:
  lldb/examples/synthetic/gnu_libstdcpp.py
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -918,6 +918,11 @@
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
   stl_deref_flags,
   "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+  RegularExpression("^std::unordered_(multi)?(map|set)<.+> >$"),
+  SyntheticChildrenSP(new ScriptedSyntheticChildren(
+  stl_deref_flags,
+  "lldb.formatters.cpp.gnu_libstdcpp.StdUnorderedMapSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
   RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
@@ -949,6 +954,10 @@
   RegularExpression("^std::multiset<.+> >(( )?&)?$"),
   TypeSummaryImplSP(
   new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
+  cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
+  RegularExpression("^std::unordered_(multi)?(map|set)<.+> >$"),
+  TypeSummaryImplSP(
+  new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
   cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
   RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
   TypeSummaryImplSP(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -7,6 +7,94 @@
 # as it ships with Mac OS X 10.6.8 thru 10.8.0
 # You are encouraged to look at the STL implementation for your platform
 # before relying on these formatters to do the right thing for your setup
+class StdUnorderedMapSynthProvider:
+def __init__(self, valobj, dict):
+self.valobj = valobj
+self.count = None
+
+def extract_type(self):
+logger = lldb.formatters.Logger.Logger()
+list_type = self.valobj.GetType().GetUnqualifiedType()
+if list_type.IsReferenceType():
+list_type = list_type.GetDereferencedType()
+if list_type.GetNumberOfTemplateArguments() > 0:
+data_type = list_type.GetTemplateArgumentType(0)
+else:
+data_type = None
+return data_type
+
+def update(self): 
+logger = lldb.formatters.Logger.Logger()
+# preemptively setting this to None - we might end up changing our mind
+# later
+self.count = None
+try:
+self.head = self.valobj.GetChildMemberWithName('_M_h')
+self.before_begin = self.head.GetChildMemberWithName('_M_before_begin')
+self.next = self.before_begin.GetChildMemberWithName('_M_nxt')
+self.data_type = self.extract_type()
+self.skip_size = self.head.GetType().GetByteSize()
+logger >> "Data type is this: " + str(self.data_type)
+self.data_size = self.data_type.GetByteSize()
+except:
+pass
+return False
+
+def get_child_index(self, name):
+logger = lldb.formatters.Logger.Logger()
+try:
+return int(name.lstrip('[').rstrip(']'))
+except:
+return -1
+
+def get_child_key(self, index):
+try:
+logger = lldb.formatters.Logger.Logger()
+offset = self.count - index - 1
+current = self.next 
+while offset > 0:
+current = current.GetChildMemberWithName('_M_nxt')
+offset = offset - 1
+return current.CreateChildAtOffset('[' + str(index) + ']', self.next.GetType().GetByteSize(), self.data_type)
+except:
+logger >> "Error in get_child_key"
+return None
+
+def get_child_at_index(self, index):
+logger = lldb.formatters.Logger.Logger()
+logger >> "Being asked to fetch child[" + str(index) + "]"
+if index < 0:
+return None
+if index >= self.num_children():
+return None
+try:
+offset = self.count - index - 1
+current = self.next 
+while offset > 0:
+current = current.GetChildMemberWithName('_M_nxt')
+offset = offset - 1
+key = self.get_child_key(index)
+return current.CreateChildAtOffset('[' + str(key.GetValue()) + ']', self.next.GetType().GetByteSize() + 9, self.data_type)
+

[Lldb-commits] [lldb] cef1e07 - [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT

2021-11-12 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2021-11-12T14:19:15+01:00
New Revision: cef1e07cc6d00b5b429d77133201e1f404a8023c

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

LOG: [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT

When LLDB receives a SIGINT while running the embedded Python REPL it currently
just crashes in `ScriptInterpreterPythonImpl::Interrupt` with an error such as
the one below:

```

Fatal Python error: PyThreadState_Get: the function must be called with the GIL
held, but the GIL is released (the current Python thread state is NULL)

```

The faulty code that causes this error is this part of 
`ScriptInterpreterPythonImpl::Interrupt`:
```
PyThreadState *state = PyThreadState_GET();
if (!state)
  state = GetThreadState();
if (state) {
  long tid = state->thread_id;
  PyThreadState_Swap(state);
  int num_threads = PyThreadState_SetAsyncExc(tid, PyExc_KeyboardInterrupt);
```

The obvious fix I tried is to just acquire the GIL before this code is running
which fixes the crash but the `KeyboardInterrupt` we want to raise immediately
is actually just queued and would only be raised once the next line of input has
been parsed (which e.g. won't interrupt Python code that is currently waiting on
a timer or IO from what I can see). Also none of the functions we call here is
marked as safe to be called from a signal handler from what I can see, so we
might still end up crashing here with some bad timing.

Python 3.2 introduced `PyErr_SetInterrupt` to solve this and the function takes
care of all the details and avoids doing anything that isn't safe to do inside a
signal handler. The only thing we need to do is to manually setup our own fake
SIGINT handler that behaves the same way as the standalone Python REPL signal
handler (which raises a KeyboardInterrupt).

>From what I understand the old code used to work with Python 2 so I kept the 
>old
code around until we officially drop support for Python 2.

There is a small gap here with Python 3.0->3.1 where we might still be crashing,
but those versions have reached their EOL more than a decade ago so I think we
don't need to bother about them.

Reviewed By: JDevlieghere

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

Added: 
lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py

Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 418e2239a771e..8655338941b5a 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1067,6 +1067,23 @@ void 
ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
 }
 
 bool ScriptInterpreterPythonImpl::Interrupt() {
+  // PyErr_SetInterrupt was introduced in 3.2.
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
+  // If the interpreter isn't evaluating any Python at the moment then return
+  // false to signal that this function didn't handle the interrupt and the
+  // next component should try handling it.
+  if (!IsExecutingPython())
+return false;
+
+  // Tell Python that it should pretend to have received a SIGINT.
+  PyErr_SetInterrupt();
+  // PyErr_SetInterrupt has no way to return an error so we can only pretend 
the
+  // signal got successfully handled and return true.
+  // Python 3.10 introduces PyErr_SetInterruptEx that could return an error, 
but
+  // the error handling is limited to checking the arguments which would be
+  // just our (hardcoded) input signal code SIGINT, so that's not useful at 
all.
+  return true;
+#else
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
 
   if (IsExecutingPython()) {
@@ -1088,6 +1105,7 @@ bool ScriptInterpreterPythonImpl::Interrupt() {
 "ScriptInterpreterPythonImpl::Interrupt() python code not running, 
"
 "can't interrupt");
   return false;
+#endif
 }
 
 bool ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn(
@@ -3293,6 +3311,28 @@ ScriptInterpreterPythonImpl::AcquireInterpreterLock() {
   return py_lock;
 }
 
+namespace {
+/// Saves the current signal handler for the specified signal and restores
+/// it at the end of the current scope.
+struct RestoreSignalHandlerScope {
+  /// The signal handler.
+  struct sigaction m_prev_handler;
+  int m_signal_code;
+  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
+// Initialize sigaction to their default state.
+std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
+// Don't install a n

[Lldb-commits] [PATCH] D104886: [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT

2021-11-12 Thread Raphael Isemann 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 rGcef1e07cc6d0: [lldb] Fix that the embedded Python REPL 
crashes if it receives SIGINT (authored by teemperor).
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104886

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py

Index: lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py
===
--- /dev/null
+++ lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py
@@ -0,0 +1,73 @@
+"""
+Test sending SIGINT to the embedded Python REPL.
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+class TestCase(PExpectTest):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def start_python_repl(self):
+""" Starts up the embedded Python REPL."""
+self.launch()
+# Start the embedded Python REPL via the 'script' command.
+self.child.send("script -l python --\n")
+# Wait for the Python REPL prompt.
+self.child.expect(">>>")
+
+# PExpect uses many timeouts internally and doesn't play well
+# under ASAN on a loaded machine..
+@skipIfAsan
+def test_while_evaluating_code(self):
+""" Tests SIGINT handling while Python code is being evaluated."""
+self.start_python_repl()
+
+# Start a long-running command that we try to abort with SIGINT.
+# Note that we dont actually wait 1s in this code as pexpect or
+# lit will kill the test way before that.
+self.child.send("import time; print('running' + 'now'); time.sleep(1);\n")
+
+# Make sure the command is actually being evaluated at the moment by
+# looking at the string that the command is printing.
+# Don't check for a needle that also occurs in the program itself to
+# prevent that echoing will make this check pass unintentionally.
+self.child.expect("runningnow")
+
+# Send SIGINT to the LLDB process.
+self.child.sendintr()
+
+# This should get transformed to a KeyboardInterrupt which is the same
+# behaviour as the standalone Python REPL. It should also interrupt
+# the evaluation of our sleep statement.
+self.child.expect("KeyboardInterrupt")
+# Send EOF to quit the Python REPL.
+self.child.sendeof()
+
+self.quit()
+
+# PExpect uses many timeouts internally and doesn't play well
+# under ASAN on a loaded machine..
+@skipIfAsan
+# FIXME: On Linux the Python code that reads from stdin seems to block until
+# it has finished reading a line before handling any queued signals.
+@skipIfLinux
+def test_while_waiting_on_input(self):
+""" Tests SIGINT handling while the REPL is waiting on input from
+stdin."""
+self.start_python_repl()
+
+# Send SIGINT to the LLDB process.
+self.child.sendintr()
+# This should get transformed to a KeyboardInterrupt which is the same
+# behaviour as the standalone Python REPL.
+self.child.expect("KeyboardInterrupt")
+# Send EOF to quit the Python REPL.
+self.child.sendeof()
+
+self.quit()
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1067,6 +1067,23 @@
 }
 
 bool ScriptInterpreterPythonImpl::Interrupt() {
+  // PyErr_SetInterrupt was introduced in 3.2.
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
+  // If the interpreter isn't evaluating any Python at the moment then return
+  // false to signal that this function didn't handle the interrupt and the
+  // next component should try handling it.
+  if (!IsExecutingPython())
+return false;
+
+  // Tell Python that it should pretend to have received a SIGINT.
+  PyErr_SetInterrupt();
+  // PyErr_SetInterrupt has no way to return an error so we can only pretend the
+  // signal got successfully handled and return true.
+  // Python 3.10 introduces PyErr_SetInterruptEx that could return an error, but
+  // the error handling is limited to checking the arguments which would be
+  // just our (hardcoded) input signal code SIGINT, so that's not useful at all.
+  return true;
+#else
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
 
   if (IsExecutingPython()) {
@@ -1088,6 +1105,7 @@
 "Scr

[Lldb-commits] [PATCH] D113760: [formatters] Draft diff for unordered_map libstdcpp formatter

2021-11-12 Thread Danil Stefaniuc via Phabricator via lldb-commits
danilashtefan updated this revision to Diff 386824.
danilashtefan added a comment.

Small cosmetic change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113760

Files:
  lldb/examples/synthetic/gnu_libstdcpp.py
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -918,6 +918,11 @@
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
   stl_deref_flags,
   "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+  RegularExpression("^std::unordered_(multi)?(map|set)<.+> >$"),
+  SyntheticChildrenSP(new ScriptedSyntheticChildren(
+  stl_deref_flags,
+  "lldb.formatters.cpp.gnu_libstdcpp.StdUnorderedMapSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
   RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
@@ -949,6 +954,10 @@
   RegularExpression("^std::multiset<.+> >(( )?&)?$"),
   TypeSummaryImplSP(
   new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
+  cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
+  RegularExpression("^std::unordered_(multi)?(map|set)<.+> >$"),
+  TypeSummaryImplSP(
+  new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
   cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
   RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
   TypeSummaryImplSP(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -7,6 +7,94 @@
 # as it ships with Mac OS X 10.6.8 thru 10.8.0
 # You are encouraged to look at the STL implementation for your platform
 # before relying on these formatters to do the right thing for your setup
+class StdUnorderedMapSynthProvider:
+def __init__(self, valobj, dict):
+self.valobj = valobj
+self.count = None
+
+def extract_type(self):
+logger = lldb.formatters.Logger.Logger()
+list_type = self.valobj.GetType().GetUnqualifiedType()
+if list_type.IsReferenceType():
+list_type = list_type.GetDereferencedType()
+if list_type.GetNumberOfTemplateArguments() > 0:
+data_type = list_type.GetTemplateArgumentType(0)
+else:
+data_type = None
+return data_type
+
+def update(self): 
+logger = lldb.formatters.Logger.Logger()
+# preemptively setting this to None - we might end up changing our mind
+# later
+self.count = None
+try:
+self.head = self.valobj.GetChildMemberWithName('_M_h')
+self.before_begin = self.head.GetChildMemberWithName('_M_before_begin')
+self.next = self.before_begin.GetChildMemberWithName('_M_nxt')
+self.data_type = self.extract_type()
+self.skip_size = self.head.GetType().GetByteSize()
+logger >> "Data type is this: " + str(self.data_type)
+self.data_size = self.data_type.GetByteSize()
+except:
+pass
+return False
+
+def get_child_index(self, name):
+logger = lldb.formatters.Logger.Logger()
+try:
+return int(name.lstrip('[').rstrip(']'))
+except:
+return -1
+
+def get_child_key(self, index):
+try:
+logger = lldb.formatters.Logger.Logger()
+offset = self.count - index - 1
+current = self.next 
+while offset > 0:
+current = current.GetChildMemberWithName('_M_nxt')
+offset = offset - 1
+return current.CreateChildAtOffset('[' + str(index) + ']', self.next.GetType().GetByteSize(), self.data_type)
+except:
+logger >> "Error in get_child_key"
+return None
+
+def get_child_at_index(self, index):
+logger = lldb.formatters.Logger.Logger()
+logger >> "Being asked to fetch child[" + str(index) + "]"
+if index < 0:
+return None
+if index >= self.num_children():
+return None
+try:
+offset = self.count - index - 1
+current = self.next 
+while offset > 0:
+current = current.GetChildMemberWithName('_M_nxt')
+offset = offset - 1
+key = self.get_child_key(index)
+return current.CreateChildAtOffset('[' + str(key.GetValue()) + ']', self.next.GetType().GetByteSize() + self.data_si

[Lldb-commits] [PATCH] D113760: [formatters] Draft diff for unordered_map libstdcpp formatter

2021-11-12 Thread Danil Stefaniuc via Phabricator via lldb-commits
danilashtefan added a comment.

Hi Walter :) This is the Draft PR for the unordered_map/set data formatter. 
Currently it works well in case both key and values are of the same primitive 
data types (except string).

Unfortunately, the following problems are encountered:

1. When key and value are of different types value is detected wrong (some 
garbage). I will leave the separate comment with the details

2)Currently I print the unordered_map in the following form [key] = [value]. 
However, the right from would be: [index] = (first = key, second = value). I am 
struggling through finding the way to do so

3)Whether key and/or value are of the string type, formatter cannot read the 
data. Is the string formatter issue.

Many thanks for your help in advance


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113760

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


[Lldb-commits] [PATCH] D113760: [formatters] Draft diff for unordered_map libstdcpp formatter

2021-11-12 Thread Danil Stefaniuc via Phabricator via lldb-commits
danilashtefan added inline comments.



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:77
+key = self.get_child_key(index)
+return current.CreateChildAtOffset('[' + str(key.GetValue()) + 
']', self.next.GetType().GetByteSize() + self.data_size, self.data_type)
+

I assume that the cause of the first issue (different key value type) is 
located here. self.next.GetType().GetByteSize() + self.data_size does not work 
in this case. Key is read, however value - not. It means that we cannot always 
add self.data_size.

I tried to manually figure out on the unordered_map case what can I 
add instead of self.data_size (which is 1 in this case), but got no success


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113760

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


[Lldb-commits] [PATCH] D104886: [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT

2021-11-12 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a subscriber: labath.
teemperor added a comment.

@labath raised some concerns in IRC about the setup code being run in a 
potential multithreaded env (which makes sense). Feel free to revert (not sure 
when/if I'll get around to address the issues)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104886

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


[Lldb-commits] [PATCH] D113687: [lldb][NFC] Inclusive language: replace master/slave names for ptys

2021-11-12 Thread Quinn Pham via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52a3ed5b93ca: [lldb][NFC] Inclusive language: replace 
master/slave names for ptys (authored by quinnp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113687

Files:
  
lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
  lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestPty.py
  lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
  lldb/test/API/tools/lldb-server/TestPtyServer.py
  lldb/third_party/Python/module/ptyprocess-0.6.0/ptyprocess/ptyprocess.py
  lldb/unittests/Editline/EditlineTest.cpp

Index: lldb/unittests/Editline/EditlineTest.cpp
===
--- lldb/unittests/Editline/EditlineTest.cpp
+++ lldb/unittests/Editline/EditlineTest.cpp
@@ -87,24 +87,24 @@
   std::unique_ptr _editline_sp;
 
   PseudoTerminal _pty;
-  int _pty_master_fd;
+  int _pty_primary_fd;
   int _pty_secondary_fd;
 
   std::unique_ptr _el_secondary_file;
 };
 
 EditlineAdapter::EditlineAdapter()
-: _editline_sp(), _pty(), _pty_master_fd(-1), _pty_secondary_fd(-1),
+: _editline_sp(), _pty(), _pty_primary_fd(-1), _pty_secondary_fd(-1),
   _el_secondary_file() {
   lldb_private::Status error;
 
-  // Open the first master pty available.
+  // Open the first primary pty available.
   EXPECT_THAT_ERROR(_pty.OpenFirstAvailablePrimary(O_RDWR), llvm::Succeeded());
 
-  // Grab the master fd.  This is a file descriptor we will:
+  // Grab the primary fd.  This is a file descriptor we will:
   // (1) write to when we want to send input to editline.
   // (2) read from when we want to see what editline sends back.
-  _pty_master_fd = _pty.GetPrimaryFileDescriptor();
+  _pty_primary_fd = _pty.GetPrimaryFileDescriptor();
 
   // Open the corresponding secondary pty.
   EXPECT_THAT_ERROR(_pty.OpenSecondary(O_RDWR), llvm::Succeeded());
@@ -140,13 +140,13 @@
 
   // Write the line out to the pipe connected to editline's input.
   ssize_t input_bytes_written =
-  ::write(_pty_master_fd, line.c_str(),
+  ::write(_pty_primary_fd, line.c_str(),
   line.length() * sizeof(std::string::value_type));
 
   const char *eoln = "\n";
   const size_t eoln_length = strlen(eoln);
   input_bytes_written =
-  ::write(_pty_master_fd, eoln, eoln_length * sizeof(char));
+  ::write(_pty_primary_fd, eoln, eoln_length * sizeof(char));
 
   EXPECT_NE(-1, input_bytes_written) << strerror(errno);
   EXPECT_EQ(eoln_length * sizeof(char), size_t(input_bytes_written));
@@ -205,7 +205,7 @@
 }
 
 void EditlineAdapter::ConsumeAllOutput() {
-  FilePointer output_file(fdopen(_pty_master_fd, "r"));
+  FilePointer output_file(fdopen(_pty_primary_fd, "r"));
 
   int ch;
   while ((ch = fgetc(output_file)) != EOF) {
Index: lldb/third_party/Python/module/ptyprocess-0.6.0/ptyprocess/ptyprocess.py
===
--- lldb/third_party/Python/module/ptyprocess-0.6.0/ptyprocess/ptyprocess.py
+++ lldb/third_party/Python/module/ptyprocess-0.6.0/ptyprocess/ptyprocess.py
@@ -229,7 +229,7 @@
 pid, fd = _fork_pty.fork_pty()
 
 # Some platforms must call setwinsize() and setecho() from the
-# child process, and others from the master process. We do both,
+# child process, and others from the primary process. We do both,
 # allowing IOError for either.
 
 if pid == CHILD:
Index: lldb/test/API/tools/lldb-server/TestPtyServer.py
===
--- lldb/test/API/tools/lldb-server/TestPtyServer.py
+++ lldb/test/API/tools/lldb-server/TestPtyServer.py
@@ -15,10 +15,10 @@
 super().setUp()
 import pty
 import tty
-master, slave = pty.openpty()
-tty.setraw(master)
-self._master = io.FileIO(master, 'r+b')
-self._slave = io.FileIO(slave, 'r+b')
+primary, secondary = pty.openpty()
+tty.setraw(primary)
+self._primary = io.FileIO(primary, 'r+b')
+self._secondary = io.FileIO(secondary, 'r+b')
 
 def get_debug_monitor_command_line_args(self, attach_pid=None):
 commandline_args = self.debug_monitor_extra_args
@@ -28,7 +28,7 @@
 libc = ctypes.CDLL(None)
 libc.ptsname.argtypes = (ctypes.c_int,)
 libc.ptsname.restype = ctypes.c_char_p
-pty_path = libc.ptsname(self._master.fileno()).decode()
+pty_path = libc.ptsname(self._primary.fileno()).decode()
 commandline_args += ["serial://%s" % (pty_path,)]
 return commandline_args
 
@@ -48,7 +48,7 @@
 def recv(self, coun

[Lldb-commits] [lldb] 52a3ed5 - [lldb][NFC] Inclusive language: replace master/slave names for ptys

2021-11-12 Thread Quinn Pham via lldb-commits

Author: Quinn Pham
Date: 2021-11-12T10:54:18-06:00
New Revision: 52a3ed5b93ca9aba042d87e2bb697bf0dda2e43c

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

LOG: [lldb][NFC] Inclusive language: replace master/slave names for ptys

[NFC] This patch replaces master and slave with primary and secondary
respectively when referring to pseudoterminals/file descriptors.

Reviewed By: clayborg, teemperor

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

Added: 


Modified: 

lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Target/Platform.cpp
lldb/source/Target/Process.cpp
lldb/test/API/functionalities/gdb_remote_client/TestPty.py
lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
lldb/test/API/tools/lldb-server/TestPtyServer.py
lldb/third_party/Python/module/ptyprocess-0.6.0/ptyprocess/ptyprocess.py
lldb/unittests/Editline/EditlineTest.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
 
b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
index beb2cbd1507b4..f8c3ed65372f8 100644
--- 
a/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
+++ 
b/lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
@@ -399,8 +399,8 @@ static Status HandleFileAction(ProcessLaunchInfo 
&launch_info,
 case FileAction::eFileActionOpen: {
   FileSpec file_spec = file_action->GetFileSpec();
   if (file_spec) {
-const int master_fd = launch_info.GetPTY().GetPrimaryFileDescriptor();
-if (master_fd != PseudoTerminal::invalid_fd) {
+const int primary_fd = launch_info.GetPTY().GetPrimaryFileDescriptor();
+if (primary_fd != PseudoTerminal::invalid_fd) {
   // Check in case our file action open wants to open the secondary
   FileSpec secondary_spec(launch_info.GetPTY().GetSecondaryName());
   if (file_spec == secondary_spec) {

diff  --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 5ae878024be17..3d2225ff0cb24 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -621,7 +621,7 @@ NativeProcessWindows::Factory::Attach(
 lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
 MainLoop &mainloop) const {
   Error E = Error::success();
-  // Set pty master fd invalid since it is not available.
+  // Set pty primary fd invalid since it is not available.
   auto process_up = std::unique_ptr(
   new NativeProcessWindows(pid, -1, native_delegate, E));
   if (E)

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index da645319fda63..5360db3d84623 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -286,7 +286,7 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
   if (should_forward_stdio) {
 // nullptr means it's not redirected to file or pty (in case of LLGS local)
 // at least one of stdio will be transferred pty<->gdb-remote we need to
-// give the pty master handle to this object to read and/or write
+// give the pty primary handle to this object to read and/or write
 LLDB_LOG(log,
  "pid = {0}: setting up stdout/stderr redirection via $O "
  "gdb-remote commands",

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index be91a90158e8c..0ae56e6ff1615 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1110,7 +1110,7 @@ lldb::ProcessSP Platform::DebugProcess(ProcessLaunchInfo 
&launch_info,
 
 // If we didn't have any file actions, the pseudo terminal might have
 // been used where the secondary side was given as the file to open for
-// stdin/out/err after we have already opened the master so we can
+// stdin/out/err after we have already opened the primary so we can
 // read/write stdin/out/err.
 int pty_fd = launch_info.GetPTY().ReleasePrimaryFileDescriptor();
 if (pty_fd != PseudoTerminal::invalid_fd) {

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
inde

[Lldb-commits] [PATCH] D113760: [formatters] Draft diff for unordered_map libstdcpp formatter

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

When you do your tests, don't care too much about std::string yet, as it has 
its own issues, but instead create a non-standard size type like

  struct Foo {
int a;
int b;
int c;
  };
  
  ...
   std::unordered_map u;




Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:16-24
+logger = lldb.formatters.Logger.Logger()
+list_type = self.valobj.GetType().GetUnqualifiedType()
+if list_type.IsReferenceType():
+list_type = list_type.GetDereferencedType()
+if list_type.GetNumberOfTemplateArguments() > 0:
+data_type = list_type.GetTemplateArgumentType(0)
+else:

you can simplify this



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:18
+list_type = self.valobj.GetType().GetUnqualifiedType()
+if list_type.IsReferenceType():
+list_type = list_type.GetDereferencedType()

you are already passing stl_deref_flags when you declare this formatter in C++, 
so you shouldn't get a Reference type here



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:21
+if list_type.GetNumberOfTemplateArguments() > 0:
+data_type = list_type.GetTemplateArgumentType(0)
+else:

GetTemplateArgumentType(0) will give you the key, and 
GetTemplateArgumentType(1) should give you the value type. The idea is that in 
this place you get both key_type and value_type, so that you don't need to 
figure them out later



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:44
+def get_child_index(self, name):
+logger = lldb.formatters.Logger.Logger()
+try:

remove if not used



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:55
+current = self.next 
+while offset > 0:
+current = current.GetChildMemberWithName('_M_nxt')

this looks weird. you are already doing a while loop in get_child_at_index that 
is taking you to the node you want, but you do again another loop. You have to 
use `current` instead. My suggestion is to remove this function and make 
everything happen in get_child_at_index with one single loop



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:71
+try:
+offset = self.count - index - 1
+current = self.next 

why do you do this? that means that you are traversing backwards. Just move an 
'index' number of times. The unordered map is unordered by definition



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:77
+key = self.get_child_key(index)
+return current.CreateChildAtOffset('[' + str(key.GetValue()) + 
']', self.next.GetType().GetByteSize() + self.data_size, self.data_type)
+

danilashtefan wrote:
> I assume that the cause of the first issue (different key value type) is 
> located here. self.next.GetType().GetByteSize() + self.data_size does not 
> work in this case. Key is read, however value - not. It means that we cannot 
> always add self.data_size.
> 
> I tried to manually figure out on the unordered_map case what can 
> I add instead of self.data_size (which is 1 in this case), but got no success
do what i mentioned above regarding fetching the key and value types. I imagine 
that the internal allocator is using a pair, which means that the 
memory layout will be:
  key
  value [with an offset of key size]



Comment at: lldb/examples/synthetic/gnu_libstdcpp.py:77
+key = self.get_child_key(index)
+return current.CreateChildAtOffset('[' + str(key.GetValue()) + 
']', self.next.GetType().GetByteSize() + self.data_size, self.data_type)
+

wallace wrote:
> danilashtefan wrote:
> > I assume that the cause of the first issue (different key value type) is 
> > located here. self.next.GetType().GetByteSize() + self.data_size does not 
> > work in this case. Key is read, however value - not. It means that we 
> > cannot always add self.data_size.
> > 
> > I tried to manually figure out on the unordered_map case what 
> > can I add instead of self.data_size (which is 1 in this case), but got no 
> > success
> do what i mentioned above regarding fetching the key and value types. I 
> imagine that the internal allocator is using a pair, which means 
> that the memory layout will be:
>   key
>   value [with an offset of key size]
here you are returning a child of type self.data_type, which is the key type. 
And we don't want that. We want to do the same thing that the map formatter 
does for getting the pair and returning it: 
https://github.com/llvm-mirror/lldb/blob/master/examples/synthetic/gnu_libstdcpp.py#L366
Notice how data type in that case is gotten

[Lldb-commits] [PATCH] D113521: Allow lldb to launch a remote executable when there isn't a local copy

2021-11-12 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

In D113521#3125429 , @clayborg wrote:

> I'm good with this to get things started. Pavel?

I think I mostly understand where's Jim's coming from, though I don't fully 
agree with the conclusions. But, it's not my feature, so...

In D113521#3125597 , @jingham wrote:

> In D113521#3124239 , @labath wrote:
>
>> Yes, that is the question I am asking. I didn't want to go off into 
>> designing an exec feature. I only mentioned because it seemed potentially 
>> related. We can put away that for now.
>>
>> While my question may not be "directly germane" to this patch, I wouldn't 
>> say it's orthogonal either. Right now (IIUC) the executable module is always 
>> the source of truth for the launch operation. Now you're adding a second 
>> source, so one has to choose how to handle the situation when both of them 
>> are present. You may not care what happens in that case, but _something_ is 
>> going to happen nonetheless. I guess we basically have three options:
>> a) prefer the executable module (this is what the patch implements, and it's 
>> also the smallest deviation from status quo of completely ignoring launch 
>> info)
>> b) prefer the launch info (that is what I proposed)
>> c) make it an error (I think that's something we could all agree on)
>>
>> The reason I proposed (b) is because of the principle of specific overriding 
>> general. The executable module is embedded into the target, so I would 
>> consider it more general than the launch info, which can be provided 
>> directly to the Launch method. Greg's use case (launching a remote binary 
>> that you already have a copy of) seems like it could benefit from that. 
>> However, maybe I have an even better one. What would happen with reruns? On 
>> the first run, the user would create a executable-less target, and provide a 
>> binary through the launch info. The binary would launch fine and exit. Then 
>> the user would try to launch again using the same target and launch info, 
>> but the code would go down a different path (I'm not sure which one) because 
>> the target would already have an executable. (This is actually kind of 
>> similar to the exec scenario, because the executable module would change 
>> between the two runs.)
>
> This is the same situation as if you had attached to a PID on a remote with 
> no local binary, then reran, right?

I don't have an intuition for what should happen in that case, but I suppose it 
could work that way.

> That should also work w/o the user having to intervene with a LaunchInfo for 
> the second run, and so should re-running in this case.  We shouldn't NEED the 
> extra launch info to make rerun in your case work.

Yes, they don't NEED to provide it, but they CAN do so. If they provide the 
exact same information, then the situation would be as if they didn't provide 
anything. And I think that's your point here -- if the user provides the exact 
same path in the launch info, then he won't be able to tell the difference.
*However*, the user can also specify different launch info on the second 
launch. If he passes say, different environment (e.g., through 
SBTarget::Launch(SBLaunchInfo)), then these will take precedence over the ones 
stored in the target, right? Same for arguments, working dir, etc. But if the 
user specifies a different executable file, then it will be ignored.

I think I now understand how you look at this, but it this discrepancy still 
seems unfortunate...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113521

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


[Lldb-commits] [PATCH] D113720: [lldb][NFC] Inclusive language: rename m_master in ASTImporterDelegate

2021-11-12 Thread Quinn Pham via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84c5702b7649: [lldb][NFC] Inclusive language: rename 
m_master in ASTImporterDelegate (authored by quinnp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113720

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
@@ -259,11 +259,11 @@
   /// CxxModuleHandler to replace any missing or malformed declarations with
   /// their counterpart from a C++ module.
   struct ASTImporterDelegate : public clang::ASTImporter {
-ASTImporterDelegate(ClangASTImporter &master, clang::ASTContext *target_ctx,
+ASTImporterDelegate(ClangASTImporter &main, clang::ASTContext *target_ctx,
 clang::ASTContext *source_ctx)
-: clang::ASTImporter(*target_ctx, master.m_file_manager, *source_ctx,
- master.m_file_manager, true /*minimal*/),
-  m_master(master), m_source_ctx(source_ctx) {
+: clang::ASTImporter(*target_ctx, main.m_file_manager, *source_ctx,
+ main.m_file_manager, true /*minimal*/),
+  m_main(main), m_source_ctx(source_ctx) {
   // Target and source ASTContext shouldn't be identical. Importing AST
   // nodes within the same AST doesn't make any sense as the whole idea
   // is to import them to a different AST.
@@ -329,7 +329,7 @@
 /// were created from the 'std' C++ module to prevent that the Importer
 /// tries to sync them with the broken equivalent in the debug info AST.
 llvm::SmallPtrSet m_decls_to_ignore;
-ClangASTImporter &m_master;
+ClangASTImporter &m_main;
 clang::ASTContext *m_source_ctx;
 CxxModuleHandler *m_std_handler = nullptr;
 /// The currently attached listener.
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -824,7 +824,7 @@
   }
 
   // Check which ASTContext this declaration originally came from.
-  DeclOrigin origin = m_master.GetDeclOrigin(From);
+  DeclOrigin origin = m_main.GetDeclOrigin(From);
 
   // Prevent infinite recursion when the origin tracking contains a cycle.
   assert(origin.decl != From && "Origin points to itself?");
@@ -853,7 +853,7 @@
   // though all these different source ASTContexts just got a copy from
   // one source AST).
   if (origin.Valid()) {
-auto R = m_master.CopyDecl(&getToContext(), origin.decl);
+auto R = m_main.CopyDecl(&getToContext(), origin.decl);
 if (R) {
   RegisterImportedDecl(From, R);
   return R;
@@ -862,7 +862,7 @@
 
   // If we have a forcefully completed type, try to find an actual definition
   // for it in other modules.
-  const ClangASTMetadata *md = m_master.GetDeclMetadata(From);
+  const ClangASTMetadata *md = m_main.GetDeclMetadata(From);
   auto *td = dyn_cast(From);
   if (td && md && md->IsForcefullyCompleted()) {
 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
@@ -1045,7 +1045,7 @@
   }
 
   lldb::user_id_t user_id = LLDB_INVALID_UID;
-  ClangASTMetadata *metadata = m_master.GetDeclMetadata(from);
+  ClangASTMetadata *metadata = m_main.GetDeclMetadata(from);
   if (metadata)
 user_id = metadata->GetUserID();
 
@@ -1069,9 +1069,9 @@
   }
 
   ASTContextMetadataSP to_context_md =
-  m_master.GetContextMetadata(&to->getASTContext());
+  m_main.GetContextMetadata(&to->getASTContext());
   ASTContextMetadataSP from_context_md =
-  m_master.MaybeGetContextMetadata(m_source_ctx);
+  m_main.MaybeGetContextMetadata(m_source_ctx);
 
   if (from_context_md) {
 DeclOrigin origin = from_context_md->getOrigin(from);
@@ -1082,7 +1082,7 @@
   to_context_md->setOrigin(to, origin);
 
 ImporterDelegateSP direct_completer =
-m_master.GetDelegate(&to->getASTContext(), origin.ctx);
+m_main.GetDelegate(&to->getASTContext(), origin.ctx);
 
 if (direct_completer.get() != this)
   direct_completer->ASTImporter::Imported(origin.decl, to);
@@ -1143,7 +1143,7 @@
   }
 
   if (auto *to_namespace_decl = dyn_cast(to)) {
-m_master.BuildNamespaceMap(to_namespace_decl);
+m_main.BuildNamespaceMap(to_namespace_decl);
 to_namespace_decl->setHasExternalVisibleStorage();
   }
 
@@ -1172,10 +1172,10 @@
   }
 
   if (clang::CXXMethodDecl *to_method = dyn_cast(to))
-MaybeCompleteReturnType(m_master, to_method);
+MaybeCompleteReturnTyp

[Lldb-commits] [lldb] 84c5702 - [lldb][NFC] Inclusive language: rename m_master in ASTImporterDelegate

2021-11-12 Thread Quinn Pham via lldb-commits

Author: Quinn Pham
Date: 2021-11-12T12:04:14-06:00
New Revision: 84c5702b76497e6f3e3f2abc15fb59e947663b38

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

LOG: [lldb][NFC] Inclusive language: rename m_master in ASTImporterDelegate

[NFC] As part of using inclusive language within the llvm project, this patch
replaces `m_master` in `ASTImporterDelegate` with `m_main`.

Reviewed By: teemperor, clayborg

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

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

Removed: 




diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 9ff6fbc28bf9c..80469e2925801 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -824,7 +824,7 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl 
*From) {
   }
 
   // Check which ASTContext this declaration originally came from.
-  DeclOrigin origin = m_master.GetDeclOrigin(From);
+  DeclOrigin origin = m_main.GetDeclOrigin(From);
 
   // Prevent infinite recursion when the origin tracking contains a cycle.
   assert(origin.decl != From && "Origin points to itself?");
@@ -853,7 +853,7 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl 
*From) {
   // though all these 
diff erent source ASTContexts just got a copy from
   // one source AST).
   if (origin.Valid()) {
-auto R = m_master.CopyDecl(&getToContext(), origin.decl);
+auto R = m_main.CopyDecl(&getToContext(), origin.decl);
 if (R) {
   RegisterImportedDecl(From, R);
   return R;
@@ -862,7 +862,7 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl 
*From) {
 
   // If we have a forcefully completed type, try to find an actual definition
   // for it in other modules.
-  const ClangASTMetadata *md = m_master.GetDeclMetadata(From);
+  const ClangASTMetadata *md = m_main.GetDeclMetadata(From);
   auto *td = dyn_cast(From);
   if (td && md && md->IsForcefullyCompleted()) {
 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
@@ -1045,7 +1045,7 @@ void 
ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
   }
 
   lldb::user_id_t user_id = LLDB_INVALID_UID;
-  ClangASTMetadata *metadata = m_master.GetDeclMetadata(from);
+  ClangASTMetadata *metadata = m_main.GetDeclMetadata(from);
   if (metadata)
 user_id = metadata->GetUserID();
 
@@ -1069,9 +1069,9 @@ void 
ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
   }
 
   ASTContextMetadataSP to_context_md =
-  m_master.GetContextMetadata(&to->getASTContext());
+  m_main.GetContextMetadata(&to->getASTContext());
   ASTContextMetadataSP from_context_md =
-  m_master.MaybeGetContextMetadata(m_source_ctx);
+  m_main.MaybeGetContextMetadata(m_source_ctx);
 
   if (from_context_md) {
 DeclOrigin origin = from_context_md->getOrigin(from);
@@ -1082,7 +1082,7 @@ void 
ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
   to_context_md->setOrigin(to, origin);
 
 ImporterDelegateSP direct_completer =
-m_master.GetDelegate(&to->getASTContext(), origin.ctx);
+m_main.GetDelegate(&to->getASTContext(), origin.ctx);
 
 if (direct_completer.get() != this)
   direct_completer->ASTImporter::Imported(origin.decl, to);
@@ -1143,7 +1143,7 @@ void 
ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
   }
 
   if (auto *to_namespace_decl = dyn_cast(to)) {
-m_master.BuildNamespaceMap(to_namespace_decl);
+m_main.BuildNamespaceMap(to_namespace_decl);
 to_namespace_decl->setHasExternalVisibleStorage();
   }
 
@@ -1172,10 +1172,10 @@ void 
ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
   }
 
   if (clang::CXXMethodDecl *to_method = dyn_cast(to))
-MaybeCompleteReturnType(m_master, to_method);
+MaybeCompleteReturnType(m_main, to_method);
 }
 
 clang::Decl *
 ClangASTImporter::ASTImporterDelegate::GetOriginalDecl(clang::Decl *To) {
-  return m_master.GetDeclOrigin(To).decl;
+  return m_main.GetDeclOrigin(To).decl;
 }

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
index 4f589d34aa48e..e565a96b217ff 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
@@ -259,11 +259,11 @@ class ClangASTImporter {
   /// CxxModuleHandler to replace any missing or malformed declarations with
   /// their counterpart from a C++ module.
   struct ASTImport

[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386878.
lawrence_danna edited the summary of this revision.
lawrence_danna added a comment.

fix cmake error message condition for cross-compile


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/get-python-config.py
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,31 @@
   return g_spec;
 }
 
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sys
+
+def main(lldb_python_dir, python_exe_relative_path):
+  info = {
+"lldb-pythonpath": lldb_python_dir,
+"language": "python",
+"prefix": sys.prefix,
+"executable": os.path.join(sys.prefix, python_exe_relative_path)
+  }
+  return info
+)";
+
+static const char python_exe_relative_path[] = LLDB_PYTHON_EXE_RELATIVE_PATH;
+
 StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
   GIL gil;
   FileSpec python_dir_spec = GetPythonDir();
   if (!python_dir_spec)
 return nullptr;
-  PythonString python_dir(python_dir_spec.GetPath());
-  PythonDictionary info(PyInitialValue::Empty);
-  llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
-  if (error)
-return nullptr;
-  static const char script[] = R"(
-def main(info):
-  import sys
-  import os
-  name = 'python' + str(sys.version_info.major)
-  info.update({
-"language": "python",
-"prefix": sys.prefix,
-"executable": os.path.join(sys.prefix, "bin", name),
-  })
-  return info
-)";
-  PythonScript get_info(script);
-  auto info_json = unwrapIgnoringErrors(As(get_info(info)));
+  PythonScript get_info(GetInterpreterInfoScript);
+  auto info_json = unwrapIgnoringErrors(
+  As(get_info(PythonString(python_dir_spec.GetPath()),
+PythonString(python_exe_relative_path;
   if (!info_json)
 return nullptr;
   return info_json.CreateStructuredDictionary();
Index: lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -3,6 +3,12 @@
 endif()
 add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${LLDB_PYTHON_RELATIVE_PATH}")
 
+if(NOT LLDB_PYTHON_EXE_RELATIVE_PATH)
+  message(FATAL_ERROR "LLDB_PYTHON_EXE_RELATIVE_PATH is not set.")
+endif()
+add_definitions(-DLLDB_PYTHON_EXE_RELATIVE_PATH="${LLDB_PYTHON_EXE_RELATIVE_PATH}")
+
+
 if (LLDB_ENABLE_LIBEDIT)
   list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES})
 endif()
Index: lldb/bindings/python/get-python-config.py
===
--- /dev/null
+++ lldb/bindings/python/get-python-config.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import argparse
+import sysconfig
+import distutils.sysconfig
+
+
+def relpath_nodots(path, base):
+rel = os.path.normpath(os.path.relpath(path, base))
+assert not os.path.isabs(rel)
+parts = rel.split(os.path.sep)
+if parts and parts[0] == '..':
+raise ValueError(f"{path} is not under {base}")
+return rel
+
+def main():
+parser = argparse.ArgumentParser(description="extract cmake variables from python")
+parser.add_argument("variable_name")
+args = parser.parse_args()
+if args.variable_name == "LLDB_PYTHON_DEFAULT_RELATIVE_PATH":
+print(distutils.sysconfig.get_python_lib(True, False, ''))
+elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
+tried = list()
+exe = sys.executable
+while True:
+try:
+print(relpath_nodots(exe, sys.prefix))
+break
+except ValueError:
+tried.append(exe)
+if os.path.islink(exe):
+exe = os.path.join(os.path.dirname(exe), os.readlink(exe))
+continue
+else:
+print("Could not find a relative path to sys.executable under sys.prefix", file=sys.stderr)
+for e in tried:
+print("tried:", e, file=sys.stderr)
+print("sys.prefix:", sys.prefix, file=sys.stderr)
+sys.exit(1)
+
+else:
+parser.error(f"unknown variable {args.variable_name}")
+
+if __name__ == '__main__':
+main()
\ No newline at end of file
Index: lldb/CMakeLists.txt
===
--- lld

[Lldb-commits] [PATCH] D113789: Add the ability to cache information for a module between debugger instances.

2021-11-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: jingham, labath, JDevlieghere, wallace, aadsm.
Herald added subscribers: mgorny, emaste.
clayborg requested review of this revision.
Herald added subscribers: lldb-commits, MaskRay.
Herald added a project: LLDB.

Added the ability to cache the finalized symbol tables as a proof of concept 
and as a way to discuss caching items for a given module to allow subsequent 
debug sessions to start faster.

Module caching must be enabled by the user before this can be used:

(lldb) settings set symbols.enable-lldb-modules-cache true

There is also a setting that allows the user to specify a module cache 
directory that defaults to a directory that defaults to being next to the 
symbols.clang-modules-cache-path directory in a temp directory:

(lldb) settings show symbols.lldb-modules-cache-path

If this setting is enabled, the finalized symbol tables will be serialized and 
saved to disc so they can be quickly loaded next time you debug.

Each module gets a cache directory in the "symbols.lldb-modules-cache-path" 
directory. A directory is created in the cache directory that uses the module's 
basename as a directory and then a hash is created for the module which 
incorporates the full path to the executable, the architecture, the object name 
offset and modification time (if any). This allows universal mach-o files to 
support caching multuple architectures in the same module cache directory. 
Making the directory based on the this info allows this directory's contents to 
be deleted and replaced when the file gets updated on disk. This keeps the 
cache from growing over time during the compile/edit/debug cycle and prevents 
out of space issues.

If the cache is enabled, the symbol table will be loaded from the cache the 
next time you debug if the module has not changed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113789

Files:
  lldb/include/lldb/Core/Mangled.h
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Symbol/Symbol.h
  lldb/include/lldb/Symbol/Symtab.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Mangled.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/test/API/functionalities/module_cache/bsd/Makefile
  lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
  lldb/test/API/functionalities/module_cache/bsd/a.c
  lldb/test/API/functionalities/module_cache/bsd/b.c
  lldb/test/API/functionalities/module_cache/bsd/c.c
  lldb/test/API/functionalities/module_cache/bsd/main.c
  lldb/test/API/functionalities/module_cache/simple_exe/Makefile
  lldb/test/API/functionalities/module_cache/simple_exe/TestModuleCacheSimple.py
  lldb/test/API/functionalities/module_cache/simple_exe/main.c
  lldb/test/API/functionalities/module_cache/universal/Makefile
  
lldb/test/API/functionalities/module_cache/universal/TestModuleCacheUniversal.py
  lldb/test/API/functionalities/module_cache/universal/main.c
  lldb/test/API/macosx/universal/main.c
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/SymbolTest.cpp

Index: lldb/unittests/Symbol/SymbolTest.cpp
===
--- /dev/null
+++ lldb/unittests/Symbol/SymbolTest.cpp
@@ -0,0 +1,261 @@
+//===-- SymbolTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Core/Section.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Utility/DataExtractor.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/GSYM/FileWriter.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+static llvm::support::endianness GetLLVMByteOrder(bool little_endian) {
+  return little_endian ? llvm::support::little : llvm::support::big;
+}
+
+static ByteOrder GetLLDBByteOrder(bool little_endian) {
+  return little_endian ? eByteOrderLittle : eByteOrderBig;
+}
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list,
+ bool little_endian) {
+  llvm::SmallStrin

[Lldb-commits] [PATCH] D113789: Add the ability to cache information for a module between debugger instances.

2021-11-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

This patch effectively introduces a file format to cache lldb internal state. 
While the tests and the code do give some information for what it looks like, 
some documentation about this format would be nice.

I like this idea a lot! My comments were kind of surface level but should help 
fix some of the rough edges of the patch.




Comment at: lldb/include/lldb/Core/Module.h:879
   StatsDuration &GetSymtabParseTime() { return m_symtab_parse_time; }
-  
   /// Accessor for the symbol table index time metric.

nit: unnecessary whitespace change



Comment at: lldb/include/lldb/Core/Module.h:951
+  ///
+  /// The hash should be enough to indentify the file on disk and the
+  /// architecture of the file. If the module represents an object inside of a

typo: `indentify` -> `identify`



Comment at: lldb/include/lldb/Core/Module.h:959
+  ///   from the same file
+  /// - a .o file inside of a BSD archive. Each .o file will have a object name
+  ///   and object offset that should produce a unique hash. The object offset

`have a object name` -> `have an object name`



Comment at: lldb/include/lldb/Symbol/ObjectFile.h:710-713
+  lldb::addr_t m_file_offset;
+  /// The length of this object file if it is known. This can be zero if length
+  /// is unknown or can't be determined.
+  lldb::addr_t m_length;

Curious to know, why `lldb::addr_t` instead of something like `lldb::offset_t`?



Comment at: lldb/include/lldb/Symbol/Symbol.h:21-22
+  class FileWriter;
+}
+}
+

nit: you have a namespace comment when you do this in an earlier file but not 
here. what does clang-format do?



Comment at: lldb/source/Core/Mangled.cpp:411-412
+  MangledOnly = 2u,
+  /// If we have a Mangled object with two different names that are not related
+  /// then we need to save both strings.
+  MangledAndDemangled = 3u

What does "two different names that are not related" mean here?



Comment at: lldb/source/Core/Module.cpp:65
 
+
 #include 

nit: unrelated whitespace change



Comment at: lldb/source/Core/Module.cpp:1706
+  // Append the object name to the path as a directory. The object name will be
+  // valie if we have an object file from a BSD archive like "foo.a(bar.o)".
+  if (m_object_name)

typo: `valie` -> `valid`



Comment at: lldb/source/Host/common/FileSystem.cpp:134
+return false;
+  auto file_or_err = Open(file_spec, File::OpenOptions::eOpenOptionReadWrite, 
lldb::eFilePermissionsUserRead | lldb::eFilePermissionsUserWrite, 
/*should_close_fd=*/true);
+  if (file_or_err)

Could you break this line into multiple lines?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113789

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


[Lldb-commits] [PATCH] D113810: Add the stop count to "statistics dump" in each target's dictionary.

2021-11-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: labath, JDevlieghere, jingham, aadsm, wallace.
clayborg requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

It is great to know how many times the target has stopped over its lifetime as 
each time the target stops, and possibly resumes without the user seeing it for 
things like shared library loading and signals that are not notified and auto 
continued, to help explain why a debug session might be slow. This is now 
included as "stopCount" inside each target JSON.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113810

Files:
  lldb/source/Target/Statistics.cpp
  lldb/test/API/commands/statistics/basic/TestStats.py


Index: lldb/test/API/commands/statistics/basic/TestStats.py
===
--- lldb/test/API/commands/statistics/basic/TestStats.py
+++ lldb/test/API/commands/statistics/basic/TestStats.py
@@ -118,6 +118,12 @@
 stats = self.get_target_stats(self.get_stats())
 self.verify_success_fail_count(stats, 'frameVariable', 1, 0)
 
+# Test that "stopCount" is available when the process has run
+self.assertEqual('stopCount' in stats, True,
+ 'ensure "stopCount" is in target JSON')
+self.assertGreater(stats['stopCount'], 0,
+   'make sure "stopCount" is greater than zero')
+
 def test_default_no_run(self):
 """Test "statistics dump" without running the target.
 
@@ -154,7 +160,7 @@
 target = self.createTestTarget()
 debug_stats = self.get_stats()
 debug_stat_keys = [
-'modules', 
+'modules',
 'targets',
 'totalSymbolTableParseTime',
 'totalSymbolTableIndexTime',
@@ -217,7 +223,7 @@
   lldb.SBFileSpec("main.c"))
 debug_stats = self.get_stats()
 debug_stat_keys = [
-'modules', 
+'modules',
 'targets',
 'totalSymbolTableParseTime',
 'totalSymbolTableIndexTime',
@@ -255,7 +261,7 @@
 target = self.createTestTarget(file_path=exe)
 debug_stats = self.get_stats()
 debug_stat_keys = [
-'modules', 
+'modules',
 'targets',
 'totalSymbolTableParseTime',
 'totalSymbolTableIndexTime',
@@ -315,7 +321,7 @@
 "details": {...},
 "id": 2,
 "resolveTime": 4.363258166997
-}
+}
 ]
 }
 ],
@@ -333,7 +339,7 @@
 self.runCmd("b a_function")
 debug_stats = self.get_stats()
 debug_stat_keys = [
-'modules', 
+'modules',
 'targets',
 'totalSymbolTableParseTime',
 'totalSymbolTableIndexTime',
@@ -363,5 +369,5 @@
 'resolveTime'
 ]
 for breakpoint in breakpoints:
-self.verify_keys(breakpoint, 'target_stats["breakpoints"]', 
+self.verify_keys(breakpoint, 'target_stats["breakpoints"]',
  bp_keys_exist, None)
Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -103,6 +103,8 @@
 if (unix_signals_sp)
   target_metrics_json.try_emplace("signals",
   
unix_signals_sp->GetHitCountStatistics());
+uint32_t stop_id = process_sp->GetStopID();
+target_metrics_json.try_emplace("stopCount", stop_id);
   }
   target_metrics_json.try_emplace("breakpoints", std::move(breakpoints_array));
   target_metrics_json.try_emplace("totalBreakpointResolveTime",


Index: lldb/test/API/commands/statistics/basic/TestStats.py
===
--- lldb/test/API/commands/statistics/basic/TestStats.py
+++ lldb/test/API/commands/statistics/basic/TestStats.py
@@ -118,6 +118,12 @@
 stats = self.get_target_stats(self.get_stats())
 self.verify_success_fail_count(stats, 'frameVariable', 1, 0)
 
+# Test that "stopCount" is available when the process has run
+self.assertEqual('stopCount' in stats, True,
+ 'ensure "stopCount" is in target JSON')
+self.assertGreater(stats['stopCount'], 0,
+   'make sure "stopCount" is greater than zero')
+
 def test_default_no_run(self):
 """Test "statistics dump" without running the target.
 
@@ -154,7 +160,7 @@
 target = self.createTestTarget()
 debug_stats = self.get_stats()
 debug_stat_keys = [
-'modules', 
+'modules',
 'targets',

[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386967.
lawrence_danna added a comment.

cleanup cmake usage


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/get-python-config.py
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,31 @@
   return g_spec;
 }
 
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sys
+
+def main(lldb_python_dir, python_exe_relative_path):
+  info = {
+"lldb-pythonpath": lldb_python_dir,
+"language": "python",
+"prefix": sys.prefix,
+"executable": os.path.join(sys.prefix, python_exe_relative_path)
+  }
+  return info
+)";
+
+static const char python_exe_relative_path[] = LLDB_PYTHON_EXE_RELATIVE_PATH;
+
 StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
   GIL gil;
   FileSpec python_dir_spec = GetPythonDir();
   if (!python_dir_spec)
 return nullptr;
-  PythonString python_dir(python_dir_spec.GetPath());
-  PythonDictionary info(PyInitialValue::Empty);
-  llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
-  if (error)
-return nullptr;
-  static const char script[] = R"(
-def main(info):
-  import sys
-  import os
-  name = 'python' + str(sys.version_info.major)
-  info.update({
-"language": "python",
-"prefix": sys.prefix,
-"executable": os.path.join(sys.prefix, "bin", name),
-  })
-  return info
-)";
-  PythonScript get_info(script);
-  auto info_json = unwrapIgnoringErrors(As(get_info(info)));
+  PythonScript get_info(GetInterpreterInfoScript);
+  auto info_json = unwrapIgnoringErrors(
+  As(get_info(PythonString(python_dir_spec.GetPath()),
+PythonString(python_exe_relative_path;
   if (!info_json)
 return nullptr;
   return info_json.CreateStructuredDictionary();
Index: lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -3,6 +3,12 @@
 endif()
 add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${LLDB_PYTHON_RELATIVE_PATH}")
 
+if(NOT LLDB_PYTHON_EXE_RELATIVE_PATH)
+  message(FATAL_ERROR "LLDB_PYTHON_EXE_RELATIVE_PATH is not set.")
+endif()
+add_definitions(-DLLDB_PYTHON_EXE_RELATIVE_PATH="${LLDB_PYTHON_EXE_RELATIVE_PATH}")
+
+
 if (LLDB_ENABLE_LIBEDIT)
   list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES})
 endif()
Index: lldb/bindings/python/get-python-config.py
===
--- /dev/null
+++ lldb/bindings/python/get-python-config.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import argparse
+import sysconfig
+import distutils.sysconfig
+
+
+def relpath_nodots(path, base):
+rel = os.path.normpath(os.path.relpath(path, base))
+assert not os.path.isabs(rel)
+parts = rel.split(os.path.sep)
+if parts and parts[0] == '..':
+raise ValueError(f"{path} is not under {base}")
+return rel
+
+def main():
+parser = argparse.ArgumentParser(description="extract cmake variables from python")
+parser.add_argument("variable_name")
+args = parser.parse_args()
+if args.variable_name == "LLDB_PYTHON_RELATIVE_PATH":
+print(distutils.sysconfig.get_python_lib(True, False, ''))
+elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
+tried = list()
+exe = sys.executable
+while True:
+try:
+print(relpath_nodots(exe, sys.prefix))
+break
+except ValueError:
+tried.append(exe)
+if os.path.islink(exe):
+exe = os.path.join(os.path.dirname(exe), os.readlink(exe))
+continue
+else:
+print("Could not find a relative path to sys.executable under sys.prefix", file=sys.stderr)
+for e in tried:
+print("tried:", e, file=sys.stderr)
+print("sys.prefix:", sys.prefix, file=sys.stderr)
+sys.exit(1)
+
+else:
+parser.error(f"unknown variable {args.variable_name}")
+
+if __name__ == '__main__':
+main()
\ No newline at end of file
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -31,24 +31,28 @@
 endif()
 
 if (LLDB_ENABLE_PYT

[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

Can you please disable the test on Windows or back your change out until 
there's a fix? There are already other failures that are getting missed because 
the bot is red.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

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


[Lldb-commits] [PATCH] D104886: [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT

2021-11-12 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

This broke the build on Windows. The buildbot was, sadly, already red because 
of another test failure:

https://lab.llvm.org/buildbot/#/builders/83/builds/11931


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104886

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


[Lldb-commits] [lldb] 19cd6f3 - [lldb] temporarily disable TestPaths.test_interpreter_info on windows

2021-11-12 Thread Lawrence D'Anna via lldb-commits

Author: Lawrence D'Anna
Date: 2021-11-12T15:41:39-08:00
New Revision: 19cd6f31d83ec9cf4712e76668b2076a4c9741e4

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

LOG: [lldb] temporarily disable TestPaths.test_interpreter_info on windows

I'm disabling this test until the fix is reviewed
(here https://reviews.llvm.org/D113650/)

Added: 


Modified: 
lldb/test/API/functionalities/paths/TestPaths.py

Removed: 




diff  --git a/lldb/test/API/functionalities/paths/TestPaths.py 
b/lldb/test/API/functionalities/paths/TestPaths.py
index da26da28a562..7b00f2126ec5 100644
--- a/lldb/test/API/functionalities/paths/TestPaths.py
+++ b/lldb/test/API/functionalities/paths/TestPaths.py
@@ -51,6 +51,8 @@ def test_interpreter_info(self):
 stream = lldb.SBStream()
 self.assertTrue(info_sd.GetAsJSON(stream).Success())
 info = json.loads(stream.GetData())
+if os.name == 'nt': #FIXME
+return
 prefix = info['prefix']
 self.assertEqual(os.path.realpath(sys.prefix), 
os.path.realpath(prefix))
 self.assertEqual(



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


[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna added a comment.

In D113650#3128674 , 
@stella.stamenova wrote:

> Can you please disable the test on Windows or back your change out until 
> there's a fix? There are already other failures that are getting missed 
> because the bot is red.

done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

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


[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386968.
lawrence_danna added a comment.

revert change that disabled the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/get-python-config.py
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/test/API/functionalities/paths/TestPaths.py

Index: lldb/test/API/functionalities/paths/TestPaths.py
===
--- lldb/test/API/functionalities/paths/TestPaths.py
+++ lldb/test/API/functionalities/paths/TestPaths.py
@@ -51,8 +51,6 @@
 stream = lldb.SBStream()
 self.assertTrue(info_sd.GetAsJSON(stream).Success())
 info = json.loads(stream.GetData())
-if os.name == 'nt': #FIXME
-return
 prefix = info['prefix']
 self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix))
 self.assertEqual(
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,31 @@
   return g_spec;
 }
 
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sys
+
+def main(lldb_python_dir, python_exe_relative_path):
+  info = {
+"lldb-pythonpath": lldb_python_dir,
+"language": "python",
+"prefix": sys.prefix,
+"executable": os.path.join(sys.prefix, python_exe_relative_path)
+  }
+  return info
+)";
+
+static const char python_exe_relative_path[] = LLDB_PYTHON_EXE_RELATIVE_PATH;
+
 StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
   GIL gil;
   FileSpec python_dir_spec = GetPythonDir();
   if (!python_dir_spec)
 return nullptr;
-  PythonString python_dir(python_dir_spec.GetPath());
-  PythonDictionary info(PyInitialValue::Empty);
-  llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
-  if (error)
-return nullptr;
-  static const char script[] = R"(
-def main(info):
-  import sys
-  import os
-  name = 'python' + str(sys.version_info.major)
-  info.update({
-"language": "python",
-"prefix": sys.prefix,
-"executable": os.path.join(sys.prefix, "bin", name),
-  })
-  return info
-)";
-  PythonScript get_info(script);
-  auto info_json = unwrapIgnoringErrors(As(get_info(info)));
+  PythonScript get_info(GetInterpreterInfoScript);
+  auto info_json = unwrapIgnoringErrors(
+  As(get_info(PythonString(python_dir_spec.GetPath()),
+PythonString(python_exe_relative_path;
   if (!info_json)
 return nullptr;
   return info_json.CreateStructuredDictionary();
Index: lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -3,6 +3,12 @@
 endif()
 add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${LLDB_PYTHON_RELATIVE_PATH}")
 
+if(NOT LLDB_PYTHON_EXE_RELATIVE_PATH)
+  message(FATAL_ERROR "LLDB_PYTHON_EXE_RELATIVE_PATH is not set.")
+endif()
+add_definitions(-DLLDB_PYTHON_EXE_RELATIVE_PATH="${LLDB_PYTHON_EXE_RELATIVE_PATH}")
+
+
 if (LLDB_ENABLE_LIBEDIT)
   list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES})
 endif()
Index: lldb/bindings/python/get-python-config.py
===
--- /dev/null
+++ lldb/bindings/python/get-python-config.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import argparse
+import sysconfig
+import distutils.sysconfig
+
+
+def relpath_nodots(path, base):
+rel = os.path.normpath(os.path.relpath(path, base))
+assert not os.path.isabs(rel)
+parts = rel.split(os.path.sep)
+if parts and parts[0] == '..':
+raise ValueError(f"{path} is not under {base}")
+return rel
+
+def main():
+parser = argparse.ArgumentParser(description="extract cmake variables from python")
+parser.add_argument("variable_name")
+args = parser.parse_args()
+if args.variable_name == "LLDB_PYTHON_RELATIVE_PATH":
+print(distutils.sysconfig.get_python_lib(True, False, ''))
+elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
+tried = list()
+exe = sys.executable
+while True:
+try:
+print(relpath_nodots(exe, sys.prefix))
+break
+except ValueError:
+tried.append(exe)
+if os.path.islink(exe):
+exe = os.path.join(os.path.dirname(exe), os.readlink(exe))
+continue
+else:
+

[Lldb-commits] [PATCH] D112972: [lldb] use EXT_SUFFIX for python extension

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386970.
lawrence_danna added a comment.

rebased, and include win32


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112972

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt
  lldb/bindings/python/get-python-config.py


Index: lldb/bindings/python/get-python-config.py
===
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -39,9 +39,10 @@
 print("tried:", e, file=sys.stderr)
 print("sys.prefix:", sys.prefix, file=sys.stderr)
 sys.exit(1)
-
+elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
+print(sysconfig.get_config_var('EXT_SUFFIX'))
 else:
 parser.error(f"unknown variable {args.variable_name}")
 
 if __name__ == '__main__':
 main()
\ No newline at end of file
Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -149,15 +149,7 @@
   else()
 set(LIBLLDB_SYMLINK_DEST 
"${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
-  if(WIN32)
-if(CMAKE_BUILD_TYPE STREQUAL Debug)
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
-else()
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
-endif()
-  else()
-set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
-  endif()
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
   ${lldb_python_target_dir} 
${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -35,8 +35,10 @@
 "Path where Python modules are installed, relative to install prefix")
   set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
 "Path to python interpreter exectuable, relative to install prefix")
+  set(cachestring_LLDB_PYTHON_EXT_SUFFIX
+"Filename extension for native code python modules")
 
-  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH)
+  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH 
LLDB_PYTHON_EXT_SUFFIX)
 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}


Index: lldb/bindings/python/get-python-config.py
===
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -39,9 +39,10 @@
 print("tried:", e, file=sys.stderr)
 print("sys.prefix:", sys.prefix, file=sys.stderr)
 sys.exit(1)
-
+elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
+print(sysconfig.get_config_var('EXT_SUFFIX'))
 else:
 parser.error(f"unknown variable {args.variable_name}")
 
 if __name__ == '__main__':
 main()
\ No newline at end of file
Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -149,15 +149,7 @@
   else()
 set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
-  if(WIN32)
-if(CMAKE_BUILD_TYPE STREQUAL Debug)
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
-else()
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
-endif()
-  else()
-set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
-  endif()
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
   ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -35,8 +35,10 @@
 "Path where Python modules are installed, relative to install prefix")
   set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
 "Path to python interpreter exectuable, relative to install prefix")
+  set(cachestring_LLDB_PYTHON_EXT_SUFFIX
+"Filename extension for native code python modules")
 
-  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH)
+  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113789: Add the ability to cache information for a module between debugger instances.

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

Added more comments to the encoding functions to detail how things are encoded.
Fixed error typos.
Added version to symbol table cache file so we can improve the format as time 
goes on and avoid loading out of data caches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113789

Files:
  lldb/include/lldb/Core/Mangled.h
  lldb/include/lldb/Core/MappedHash.h
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Symbol/Symbol.h
  lldb/include/lldb/Symbol/Symtab.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/CoreProperties.td
  lldb/source/Core/Mangled.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/test/API/functionalities/module_cache/bsd/Makefile
  lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
  lldb/test/API/functionalities/module_cache/bsd/a.c
  lldb/test/API/functionalities/module_cache/bsd/b.c
  lldb/test/API/functionalities/module_cache/bsd/c.c
  lldb/test/API/functionalities/module_cache/bsd/main.c
  lldb/test/API/functionalities/module_cache/simple_exe/Makefile
  lldb/test/API/functionalities/module_cache/simple_exe/TestModuleCacheSimple.py
  lldb/test/API/functionalities/module_cache/simple_exe/main.c
  lldb/test/API/functionalities/module_cache/universal/Makefile
  
lldb/test/API/functionalities/module_cache/universal/TestModuleCacheUniversal.py
  lldb/test/API/functionalities/module_cache/universal/main.c
  lldb/test/API/macosx/universal/main.c
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/SymbolTest.cpp

Index: lldb/unittests/Symbol/SymbolTest.cpp
===
--- /dev/null
+++ lldb/unittests/Symbol/SymbolTest.cpp
@@ -0,0 +1,261 @@
+//===-- SymbolTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Core/Section.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Utility/DataExtractor.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/GSYM/FileWriter.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+static llvm::support::endianness GetLLVMByteOrder(bool little_endian) {
+  return little_endian ? llvm::support::little : llvm::support::big;
+}
+
+static ByteOrder GetLLDBByteOrder(bool little_endian) {
+  return little_endian ? eByteOrderLittle : eByteOrderBig;
+}
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list,
+ bool little_endian) {
+  llvm::SmallString<512> str;
+  llvm::raw_svector_ostream strm(str);
+  llvm::gsym::FileWriter file(strm, GetLLVMByteOrder(little_endian));
+  object.Encode(file);
+  llvm::StringRef bytes = strm.str();
+  DataExtractor data(bytes.data(), bytes.size(),
+ GetLLDBByteOrder(little_endian), 4);
+  Symbol decoded_object;
+  offset_t data_offset = 0;
+  decoded_object.Decode(data, &data_offset, sect_list);
+  EXPECT_EQ(object, decoded_object);
+}
+
+static void EncodeDecode(const Symbol &object, const SectionList *sect_list) {
+  EncodeDecode(object, sect_list, /*little_endian=*/true);
+  EncodeDecode(object, sect_list, /*little_endian=*/false);
+}
+
+TEST(SymbolTest, EncodeDecodeSymbol) {
+
+  SectionSP sect_sp(new Section(
+  /*module_sp=*/ModuleSP(),
+  /*obj_file=*/nullptr,
+  /*sect_id=*/1,
+  /*name=*/ConstString(".text"),
+  /*sect_type=*/eSectionTypeCode,
+  /*file_vm_addr=*/0x1000,
+  /*vm_size=*/0x1000,
+  /*file_offset=*/0,
+  /*file_size=*/0,
+  /*log2align=*/5,
+  /*flags=*/0x10203040));
+
+  SectionList sect_list;
+  sect_list.AddSection(sect_sp);
+
+  Symbol symbol(
+  /*symID=*/0x10203040,
+  /*name=*/"main",
+  /*type=*/eSymbolTypeCode,
+  /*bool external=*/false,
+  /*bool is_debug=*/false,
+  /*bool is_trampoline=*/false,
+  /*bool is_artificial=*/false,
+  /*section_sp=*/sect_sp,
+  /*offset=*/0x0,
+  /*size=*/0x100,
+  /*s

[Lldb-commits] [PATCH] D113789: Add the ability to cache information for a module between debugger instances.

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



Comment at: lldb/include/lldb/Symbol/ObjectFile.h:713
+  /// is unknown or can't be determined.
+  lldb::addr_t m_length;
+  /// The data for this object file so things can be parsed lazily.

Because it can be an address in memory as well for object file that are read 
from memory only with no backing object file on disk



Comment at: lldb/include/lldb/Symbol/Symbol.h:22
+}
+}
+

clang format didn't catch this, as I have it enabled.



Comment at: lldb/source/Core/Mangled.cpp:412
+  /// If we have a Mangled object with two different names that are not related
+  /// then we need to save both strings.
+  MangledAndDemangled = 3u

I will improve the comment on this to explain!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113789

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


[Lldb-commits] [PATCH] D113810: Add the stop count to "statistics dump" in each target's dictionary.

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

The stop id includes all the user expression stops.  So the same "drive through 
code" could produce very different stop counts if you ran a bunch of `p`-s in 
one session but not the other.  You can't do better than that at present since 
we only track the natural/vrs. expression stop id for the last stop.  But if it 
mattered you could keep a separate "natural stop" counter and report that 
instead.  You can't quite get back to the natural stops by subtracting the 
number of expressions, because not all expressions run the target, and some do 
twice (if the one-thread run times out).

I'm not sure that's terribly important, provided people doing this analysis 
know that both stops are getting counted, and this is a useful statistic either 
way.

Anyway, other than that, LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113810

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


[Lldb-commits] [PATCH] D113821: [LLDB][NativePDB] Fix image lookup by address

2021-11-12 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu created this revision.
zequanwu added a reviewer: labath.
zequanwu requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, sstefan1.
Herald added a project: LLDB.

`image lookup -a ` doesn't work because the compilands list is always empty.
Create CU at given index if doesn't exit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113821

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp


Index: lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp
@@ -0,0 +1,20 @@
+// clang-format off
+// REQUIRES: lld, x86
+
+// RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -GR- -c /Fo%t.obj -- %s
+// RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe 
-pdb:%t.pdb
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -O "target create %t.exe" -o 
"image lookup -n main" -o "exit" > %t.out
+// RUN: FileCheck --input-file=%t.out %s --check-prefix=NAME
+// RUN: address=`grep "Address:" %t.out | sed "s/.*Address: 
lookup-by-address.cpp.tmp.exe\[\(.*\)\].*/\1/"`
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -O "target create %t.exe" -o 
"image lookup -a $address" -o "exit" | FileCheck %s --check-prefix=ADDRESS
+int main(int argc, char **argv) {
+  return 0;
+}
+
+// NAME: image lookup -n main
+// NAME: Address: lookup-by-address.cpp.tmp.exe[{{.*}}] 
(lookup-by-address.cpp.tmp.exe..text
+// NAME: Summary: lookup-by-address.cpp.tmp.exe`main at 
lookup-by-address.cpp:10
+
+// ADDRESS: image lookup -a {{.*}}
+// ADDRESS: Address: lookup-by-address.cpp.tmp.exe[{{.*}}] 
(lookup-by-address.cpp.tmp.exe..text
+// ADDRESS: Summary: lookup-by-address.cpp.tmp.exe`main at 
lookup-by-address.cpp:10
Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -945,11 +945,11 @@
 llvm::Optional modi = m_index->GetModuleIndexForVa(file_addr);
 if (!modi)
   return 0;
-CompilandIndexItem *cci = m_index->compilands().GetCompiland(*modi);
-if (!cci)
+CompUnitSP cu_sp = GetCompileUnitAtIndex(modi.getValue());
+if (!cu_sp)
   return 0;
 
-sc.comp_unit = GetOrCreateCompileUnit(*cci).get();
+sc.comp_unit = cu_sp.get();
 resolved_flags |= eSymbolContextCompUnit;
   }
 


Index: lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp
@@ -0,0 +1,20 @@
+// clang-format off
+// REQUIRES: lld, x86
+
+// RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -GR- -c /Fo%t.obj -- %s
+// RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe -pdb:%t.pdb
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -O "target create %t.exe" -o "image lookup -n main" -o "exit" > %t.out
+// RUN: FileCheck --input-file=%t.out %s --check-prefix=NAME
+// RUN: address=`grep "Address:" %t.out | sed "s/.*Address: lookup-by-address.cpp.tmp.exe\[\(.*\)\].*/\1/"`
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -O "target create %t.exe" -o "image lookup -a $address" -o "exit" | FileCheck %s --check-prefix=ADDRESS
+int main(int argc, char **argv) {
+  return 0;
+}
+
+// NAME: image lookup -n main
+// NAME: Address: lookup-by-address.cpp.tmp.exe[{{.*}}] (lookup-by-address.cpp.tmp.exe..text
+// NAME: Summary: lookup-by-address.cpp.tmp.exe`main at lookup-by-address.cpp:10
+
+// ADDRESS: image lookup -a {{.*}}
+// ADDRESS: Address: lookup-by-address.cpp.tmp.exe[{{.*}}] (lookup-by-address.cpp.tmp.exe..text
+// ADDRESS: Summary: lookup-by-address.cpp.tmp.exe`main at lookup-by-address.cpp:10
Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -945,11 +945,11 @@
 llvm::Optional modi = m_index->GetModuleIndexForVa(file_addr);
 if (!modi)
   return 0;
-CompilandIndexItem *cci = m_index->compilands().GetCompiland(*modi);
-if (!cci)
+CompUnitSP cu_sp = GetCompileUnitAtIndex(modi.getValue());
+if (!cu_sp)
   return 0;
 
-sc.comp_unit = GetOrCreateCompileUnit(*cci).get();
+sc.comp_unit = cu_sp.get();
 resolved_flags |= eSymbolContextCompUnit;
   }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113724: [LLDB][NativePDB] Fix missing symbol info when backtrace minidump

2021-11-12 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu added a comment.

> The ast thing could be tested by running "image dump ast" on an appropriate 
> piece of debug info.

I didn't observe any difference before and after this patch with `image dump 
ast` tested on 
https://github.com/llvm/llvm-project/blob/main/lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp.
I found that code path could get executed by `FindFunctions` when using `image 
lookup -n ...` and `break ...` on class methods, but there is a bug blocking me 
from adding tests for it. If the name has namespace like this `A::foo`, it 
fails to find it because lldb passes "foo" to plugins' `FindFunctions` and 
`PdbIndex` can only find the symbol if full name is provided. So, I need to 
either fix that bug first or find other ways to trigger this issue.

> I'm hoping that the second one could be tested through "image lookup -a"

Yeah, sent out D113821 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113724

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


[Lldb-commits] [PATCH] D113650: [lldb] fix -print-script-interpreter-info on windows

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386995.
lawrence_danna added a comment.

cmake fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113650

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/get-python-config.py
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/test/API/functionalities/paths/TestPaths.py

Index: lldb/test/API/functionalities/paths/TestPaths.py
===
--- lldb/test/API/functionalities/paths/TestPaths.py
+++ lldb/test/API/functionalities/paths/TestPaths.py
@@ -51,8 +51,6 @@
 stream = lldb.SBStream()
 self.assertTrue(info_sd.GetAsJSON(stream).Success())
 info = json.loads(stream.GetData())
-if os.name == 'nt': #FIXME
-return
 prefix = info['prefix']
 self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix))
 self.assertEqual(
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,30 +410,31 @@
   return g_spec;
 }
 
+static const char GetInterpreterInfoScript[] = R"(
+import os
+import sys
+
+def main(lldb_python_dir, python_exe_relative_path):
+  info = {
+"lldb-pythonpath": lldb_python_dir,
+"language": "python",
+"prefix": sys.prefix,
+"executable": os.path.join(sys.prefix, python_exe_relative_path)
+  }
+  return info
+)";
+
+static const char python_exe_relative_path[] = LLDB_PYTHON_EXE_RELATIVE_PATH;
+
 StructuredData::DictionarySP ScriptInterpreterPython::GetInterpreterInfo() {
   GIL gil;
   FileSpec python_dir_spec = GetPythonDir();
   if (!python_dir_spec)
 return nullptr;
-  PythonString python_dir(python_dir_spec.GetPath());
-  PythonDictionary info(PyInitialValue::Empty);
-  llvm::Error error = info.SetItem("lldb-pythonpath", python_dir);
-  if (error)
-return nullptr;
-  static const char script[] = R"(
-def main(info):
-  import sys
-  import os
-  name = 'python' + str(sys.version_info.major)
-  info.update({
-"language": "python",
-"prefix": sys.prefix,
-"executable": os.path.join(sys.prefix, "bin", name),
-  })
-  return info
-)";
-  PythonScript get_info(script);
-  auto info_json = unwrapIgnoringErrors(As(get_info(info)));
+  PythonScript get_info(GetInterpreterInfoScript);
+  auto info_json = unwrapIgnoringErrors(
+  As(get_info(PythonString(python_dir_spec.GetPath()),
+PythonString(python_exe_relative_path;
   if (!info_json)
 return nullptr;
   return info_json.CreateStructuredDictionary();
Index: lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -3,6 +3,12 @@
 endif()
 add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${LLDB_PYTHON_RELATIVE_PATH}")
 
+if(NOT LLDB_PYTHON_EXE_RELATIVE_PATH)
+  message(FATAL_ERROR "LLDB_PYTHON_EXE_RELATIVE_PATH is not set.")
+endif()
+add_definitions(-DLLDB_PYTHON_EXE_RELATIVE_PATH="${LLDB_PYTHON_EXE_RELATIVE_PATH}")
+
+
 if (LLDB_ENABLE_LIBEDIT)
   list(APPEND LLDB_LIBEDIT_LIBS ${LibEdit_LIBRARIES})
 endif()
Index: lldb/bindings/python/get-python-config.py
===
--- /dev/null
+++ lldb/bindings/python/get-python-config.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import argparse
+import sysconfig
+import distutils.sysconfig
+
+
+def relpath_nodots(path, base):
+rel = os.path.normpath(os.path.relpath(path, base))
+assert not os.path.isabs(rel)
+parts = rel.split(os.path.sep)
+if parts and parts[0] == '..':
+raise ValueError(f"{path} is not under {base}")
+return rel
+
+def main():
+parser = argparse.ArgumentParser(description="extract cmake variables from python")
+parser.add_argument("variable_name")
+args = parser.parse_args()
+if args.variable_name == "LLDB_PYTHON_RELATIVE_PATH":
+print(distutils.sysconfig.get_python_lib(True, False, ''))
+elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
+tried = list()
+exe = sys.executable
+while True:
+try:
+print(relpath_nodots(exe, sys.prefix))
+break
+except ValueError:
+tried.append(exe)
+if os.path.islink(exe):
+exe = os.path.join(os.path.dirname(exe), os.readlink(exe))
+continue
+else:
+print("

[Lldb-commits] [PATCH] D112972: [lldb] use EXT_SUFFIX for python extension

2021-11-12 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 386996.
lawrence_danna added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112972

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt
  lldb/bindings/python/get-python-config.py


Index: lldb/bindings/python/get-python-config.py
===
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -39,9 +39,10 @@
 print("tried:", e, file=sys.stderr)
 print("sys.prefix:", sys.prefix, file=sys.stderr)
 sys.exit(1)
-
+elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
+print(sysconfig.get_config_var('EXT_SUFFIX'))
 else:
 parser.error(f"unknown variable {args.variable_name}")
 
 if __name__ == '__main__':
 main()
\ No newline at end of file
Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -149,15 +149,7 @@
   else()
 set(LIBLLDB_SYMLINK_DEST 
"${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
-  if(WIN32)
-if(CMAKE_BUILD_TYPE STREQUAL Debug)
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
-else()
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
-endif()
-  else()
-set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
-  endif()
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
   ${lldb_python_target_dir} 
${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -35,8 +35,10 @@
 "Path where Python modules are installed, relative to install prefix")
   set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
 "Path to python interpreter exectuable, relative to install prefix")
+  set(cachestring_LLDB_PYTHON_EXT_SUFFIX
+"Filename extension for native code python modules")
 
-  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH)
+  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH 
LLDB_PYTHON_EXT_SUFFIX)
 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}


Index: lldb/bindings/python/get-python-config.py
===
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -39,9 +39,10 @@
 print("tried:", e, file=sys.stderr)
 print("sys.prefix:", sys.prefix, file=sys.stderr)
 sys.exit(1)
-
+elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
+print(sysconfig.get_config_var('EXT_SUFFIX'))
 else:
 parser.error(f"unknown variable {args.variable_name}")
 
 if __name__ == '__main__':
 main()
\ No newline at end of file
Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -149,15 +149,7 @@
   else()
 set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
-  if(WIN32)
-if(CMAKE_BUILD_TYPE STREQUAL Debug)
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
-else()
-  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
-endif()
-  else()
-set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
-  endif()
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
   ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -35,8 +35,10 @@
 "Path where Python modules are installed, relative to install prefix")
   set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
 "Path to python interpreter exectuable, relative to install prefix")
+  set(cachestring_LLDB_PYTHON_EXT_SUFFIX
+"Filename extension for native code python modules")
 
-  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH)
+  foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113789: Add the ability to cache information for a module between debugger instances.

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

There are two things that could be added. One is already mentioned in the 
comments, which is logging error messages in a way that we can track bugs in an 
automated fashion, as right now the errors are being thrown away or transformed 
into simple true/false values that lose the information of the actual issue. 
Now that we have a rich telemetry in place, we should use llvm::Error/Expected 
as much as possible and log the errors in both a log channel and the target 
stats. The second item to discuss is that there should be a configurable 
maximum size of the entire cache folder (e.g. 70GB), so that, for example, when 
lldb initializes it cleans up the oldest items that make the cache blow up. I 
can also add telemetry from the IDE side to track the size of the total cache 
folder, but I imagine that if we don't put a limiter, we might cause some 
issues.




Comment at: lldb/include/lldb/Core/Mangled.h:24-28
+namespace llvm {
+namespace gsym {
+class FileWriter;
+} // namespace gsym
+} // namespace llvm

being a little bit strict, you should move the FileWriter class out of gsym. 
That will also make it more generic and compelling to use for other stuff



Comment at: lldb/include/lldb/Host/FileSystem.h:93
+  /// Set the access and modification time of the given file.
+  bool SetAccessAndModificationTime(const FileSpec &file_spec,
+llvm::sys::TimePoint<> time);

this should return an llvm::Error and the caller should decide whether to 
consume the error or not.



Comment at: lldb/include/lldb/Host/FileSystem.h:167-168
+  /// \{
+  Status Remove(const FileSpec &file_spec);
+  Status Remove(const llvm::Twine &path);
+  /// \}

Rename this to RemoveFile to avoid any ambiguities



Comment at: lldb/source/Core/CoreProperties.td:23
+DefaultStringValue<"">,
+Desc<"The path to the LLDB module cache directory.">;
 }

mention here what the default directory ends up being used if this setting is 
left unchanged



Comment at: lldb/source/Core/Module.cpp:1669-1676
+  id_strm << m_file.GetPath() << m_arch.GetTriple().str();
+  if (m_object_name)
+id_strm << m_object_name.GetStringRef();
+  if (m_object_offset > 0)
+id_strm << m_object_offset;
+  const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
+  if (mtime > 0)

i'd prefer if there's a separator character like `;` between each element just 
to avoid any future possible bugs



Comment at: lldb/source/Core/Module.cpp:1680
+
+llvm::Optional Module::GetCacheDirectory() {
+  using namespace llvm;

this function is doing many things and reading is harder. Besides splitting it, 
we should log in the target stats if the cache was enabled or not, if the cache 
was used or not in a per module basis and any errors associated. This will help 
us fix issues without having to wait for users' reports.
you should also print the error in a log channel



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2723
+  if (m_symtab_up->LoadFromCache())
+return m_symtab_up.get();
   symbol_id += ParseSymbolTable(m_symtab_up.get(), symbol_id, symtab);

log here in the target stats if the cache was effectively used or not



Comment at: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp:602
+  if (m_symtab_up->LoadFromCache())
+return m_symtab_up.get();
   std::lock_guard guard(m_symtab_up->GetMutex());

same here about telemetry


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113789

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