[Lldb-commits] [PATCH] D142552: [lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines

2023-03-06 Thread David Stenberg via Phabricator via lldb-commits
dstenb added a comment.

In D142552#4083939 , @clayborg wrote:

> As long as there are no regressions in the test suite this looks good to me

Thanks, and sorry for the delay with landing this! I have ran check-lldb. I 
will land this shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142552

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


[Lldb-commits] [lldb] 98c3dc3 - [lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines

2023-03-06 Thread David Stenberg via lldb-commits

Author: David Stenberg
Date: 2023-03-06T14:23:29+01:00
New Revision: 98c3dc3fa748072fc42054fb90b295c2d5190bfe

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

LOG: [lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines

In an upcoming patch, D142556, Clang is proposed to be changed to emit
line locations that are inlined at line 0. This clashed with the behavior of
GetDIENamesAndRanges() which used 0 as a default value to determine if
file, line or column numbers had been set. Users of that function then
checked for any non-0 values when setting up the call site:

  if (call_file != 0 || call_line != 0 || call_column != 0)
[...]

which did not work with the Clang change since all three values then
could be 0.

This changes the function to use std::optional to catch non-set values
instead.

Reviewed By: clayborg

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

Added: 
lldb/test/Shell/SymbolFile/DWARF/Inputs/inlined-file0-line0-col0.yaml
lldb/test/Shell/SymbolFile/DWARF/inlined-file0-line0-col0.test

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index ca0982c1f900..cf794854c843 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2394,12 +2394,12 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit 
&comp_unit,
   DWARFRangeList func_ranges;
   const char *name = nullptr;
   const char *mangled = nullptr;
-  int decl_file = 0;
-  int decl_line = 0;
-  int decl_column = 0;
-  int call_file = 0;
-  int call_line = 0;
-  int call_column = 0;
+  std::optional decl_file;
+  std::optional decl_line;
+  std::optional decl_column;
+  std::optional call_file;
+  std::optional call_line;
+  std::optional call_column;
   DWARFExpressionList frame_base;
 
   const dw_tag_t tag = die.Tag();
@@ -2429,9 +2429,10 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit 
&comp_unit,
 
 FunctionSP func_sp;
 std::unique_ptr decl_up;
-if (decl_file != 0 || decl_line != 0 || decl_column != 0)
-  decl_up = std::make_unique(die.GetCU()->GetFile(decl_file),
-  decl_line, decl_column);
+if (decl_file || decl_line || decl_column)
+  decl_up = std::make_unique(
+  die.GetCU()->GetFile(decl_file ? *decl_file : 0),
+  decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);
 
 SymbolFileDWARF *dwarf = die.GetDWARF();
 // Supply the type _only_ if it has already been parsed

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index 7b9da6fa166f..65fab503deb2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -439,8 +439,9 @@ bool DWARFDIE::IsMethod() const {
 
 bool DWARFDIE::GetDIENamesAndRanges(
 const char *&name, const char *&mangled, DWARFRangeList &ranges,
-int &decl_file, int &decl_line, int &decl_column, int &call_file,
-int &call_line, int &call_column,
+std::optional &decl_file, std::optional &decl_line,
+std::optional &decl_column, std::optional &call_file,
+std::optional &call_line, std::optional &call_column,
 lldb_private::DWARFExpressionList *frame_base) const {
   if (IsValid()) {
 return m_die->GetDIENamesAndRanges(

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
index 3564f757dbd8..031ea26ad405 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
@@ -83,12 +83,12 @@ class DWARFDIE : public DWARFBaseDIE {
   DWARFDIE
   GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;
 
-  bool
-  GetDIENamesAndRanges(const char *&name, const char *&mangled,
-   DWARFRangeList &ranges, int &decl_file, int &decl_line,
-   int &decl_column, int &call_file, int &call_line,
-   int &call_column,
-   lldb_private::DWARFExpressionList *frame_base) const;
+  bool GetDIENamesAndRanges(
+  const char *&name, const char *&mangled, DWARFRangeList &ranges,
+  std::optional &decl_file, std::optional &decl_line,
+  std::optional &decl_colum

[Lldb-commits] [PATCH] D142552: [lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines

2023-03-06 Thread David Stenberg via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98c3dc3fa748: [lldb] Make GetDIENamesAndRanges() allow 
0-valued decl and call lines (authored by dstenb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142552

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/Shell/SymbolFile/DWARF/Inputs/inlined-file0-line0-col0.yaml
  lldb/test/Shell/SymbolFile/DWARF/inlined-file0-line0-col0.test

Index: lldb/test/Shell/SymbolFile/DWARF/inlined-file0-line0-col0.test
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/inlined-file0-line0-col0.test
@@ -0,0 +1,34 @@
+# RUN: yaml2obj %S/Inputs/inlined-file0-line0-col0.yaml -o %t
+# RUN: %lldb %t -s %s -o exit | FileCheck %s
+
+#  1 void abort(void);
+#  2 int g1 = 4, g2 = 6;
+#  3
+#  4 inline __attribute__((always_inline)) void bar(int q) {
+#  5   if (q > 5)
+#  6 abort();
+#  7 }
+#  8
+#  9 inline __attribute__((always_inline)) void foo(int q) {
+# 10   bar(q);
+# 11 }
+# 12
+# 13 int main() {
+# 14   foo(g1);
+# 15   foo(g2);
+# 16   return 0;
+# 17 }
+
+# The input object file contains a single abort invocation for the two inlined
+# instances of foo() in main() at line 0. As the file, line and column numbers
+# are all 0, file and line number information would be missing for foo and main
+# in the lookup information.
+#
+# A line number 0 is not printed for main in this case, but the same holds
+# for a non-inlined location with line number 0.
+
+# CHECK: Summary: inlined-file0-line0-col0.test.tmp`main + 30 [inlined] bar + 4 at inlined-file0-line0-col0.c:6:5
+# CHECK-NEXT: inlined-file0-line0-col0.test.tmp`main + 26 [inlined] foo at inlined-file0-line0-col0.c:10:3
+# CHECK-NEXT: inlined-file0-line0-col0.test.tmp`main + 26 at inlined-file0-line0-col0.c
+
+image lookup -a 0x1e
Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/inlined-file0-line0-col0.yaml
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/inlined-file0-line0-col0.yaml
@@ -0,0 +1,699 @@
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x107
+  cpusubtype:  0x3
+  filetype:0x1
+  ncmds:   3
+  sizeofcmds:  736
+  flags:   0x2000
+  reserved:0x0
+LoadCommands:
+  - cmd: LC_SEGMENT_64
+cmdsize: 632
+segname: ''
+vmaddr:  0
+vmsize:  814
+fileoff: 768
+filesize:814
+maxprot: 7
+initprot:7
+nsects:  7
+flags:   0
+Sections:
+  - sectname:__text
+segname: __TEXT
+addr:0x0
+size:31
+offset:  0x300
+align:   4
+reloff:  0x630
+nreloc:  3
+flags:   0x8400
+reserved1:   0x0
+reserved2:   0x0
+reserved3:   0x0
+content: 554889E5833D067D0D833D067D0431C05DC3E8
+relocations:
+  - address: 0x1B
+symbolnum:   3
+pcrel:   true
+length:  2
+extern:  true
+type:2
+scattered:   false
+value:   0
+  - address: 0xF
+symbolnum:   1
+pcrel:   true
+length:  2
+extern:  true
+type:6
+scattered:   false
+value:   0
+  - address: 0x6
+symbolnum:   0
+pcrel:   true
+length:  2
+extern:  true
+type:6
+scattered:   false
+value:   0
+  - sectname:__data
+segname: __DATA
+addr:0x20
+size:8
+offset:  0x320
+align:   2
+reloff:  0x0
+nreloc:  0
+flags:   0x0
+reserved1:   0x0
+reserved2:   0x0
+reserved3:   0x0
+content: '04000600'
+  - sectname:__debug_abbrev
+segname: __DWARF
+addr:0x28
+size:182
+offset:  0x328
+align:   0
+reloff:  0x0
+

[Lldb-commits] [PATCH] D143104: [lldb/Plugins] Add Attach capabilities to ScriptedProcess

2023-03-06 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/source/Utility/ProcessInfo.cpp:11
 
+#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Utility/ArchSpec.h"

This is a layering violation. Can we restructure this so that it this does not 
depend on code outside the Utility library? Maybe the ScriptedMetadata thingy 
could be moved into the Utility library?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143104

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


[Lldb-commits] [PATCH] D145377: [LLDB] Show sub type of faults for ELF core files

2023-03-06 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: atanasyan, arichardson, sdardis, emaste.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

Previously we only looked at the si_signo field, so you got:

  (lldb) bt
  * thread #1, name = 'a.out.mte', stop reason = signal SIGSEGV
* frame #0: 0x004007f4

This patch adds si_code so we can show:

  (lldb) bt
  * thread #1, name = 'a.out.mte', stop reason = signal SIGSEGV: sync tag
  check fault
* frame #0: 0x004007f4

Core files (at least for Linux) don't contain the fault address,
so that argument to GetCrashReasonString is now optional.
(this is also the reason we can't do memory tag annotations)

Removed the assert from GetCrashReason because both existing uses
were already guarded and it let's me use it as a validity check.
This is mainly used for multi threaded core files where the thread
that stopped will have a valid signal number but the others will not.

The order of errno and code was incorrect in ElfLinuxSigInfo::Parse.
It was the order that a "swapped" siginfo arch would use, which for Linux,
is only MIPS. We removed MIPS Linux support some time ago.

See:
https://github.com/torvalds/linux/blob/fe15c26ee26efa11741a7b632e9f23b01aca4cc6/include/uapi/asm-generic/siginfo.h#L121


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145377

Files:
  lldb/source/Plugins/Process/POSIX/CrashReason.cpp
  lldb/source/Plugins/Process/POSIX/CrashReason.h
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
  lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
  lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
  
lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -188,6 +188,10 @@
   omit defaulted template parameters. The full template parameter list can still be
   viewed with `expr --raw-output`/`frame var --raw-output`. (`D141828 `_)
 
+* LLDB will now use the value of the ``siginfo`` ``si_code`` field to report
+  more specific signal types when debugging an ELF core file. For example
+  "sync tag check fault", which is a specific type of SIGSEGV.
+
 Changes to Sanitizers
 -
 
Index: lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
===
--- lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
+++ lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
@@ -166,3 +166,14 @@
 # the MTE core file which does support it but does not allow writing tags.
 self.expect("memory tag write 0 1",
 substrs=["error: Process does not support memory tagging"], error=True)
+
+@skipIfLLVMTargetMissing("AArch64")
+def test_mte_tag_fault_reason(self):
+""" Test that we correctly report the fault reason. """
+self.runCmd("target create --core core.mte")
+
+# There is no fault address shown here because core files do not include
+# si_addr.
+self.expect("bt", substrs=[
+"* thread #1, name = 'a.out.mte', stop reason = signal SIGSEGV: "
+"sync tag check fault"])
Index: lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
===
--- lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -128,6 +128,7 @@
   std::vector notes;
   lldb::tid_t tid;
   int signo = 0;
+  int code = 0;
   int prstatus_sig = 0;
   std::string name;
 };
@@ -166,6 +167,7 @@
   lldb::RegisterContextSP m_thread_reg_ctx_sp;
 
   int m_signo;
+  int m_code;
 
   lldb_private::DataExtractor m_gpregset_data;
   std::vector m_notes;
Index: lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
===
--- lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 
+#include "Plugins/Process/POSIX/CrashReason.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
@@ -39,6 +40,7 @@
 #include "ThreadElfCore.h"
 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -46,7 +48,8 @@
 // Construct a Thread object with given data
 ThreadElfCore::ThreadElfCore(Process &process, const ThreadData &td)
 : Thread(process, td.tid

[Lldb-commits] [PATCH] D145377: [LLDB] Show sub type of signals for ELF core files

2023-03-06 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp:230
+
+  siginfo_t info;
+  info.si_signo = m_signo;

I think this won't work on Windows (no siginfo_t type, nor constants to decode 
it) -- and it may return garbage on other platforms if they use different 
constants.

If I may suggest an alternative implementation:
- Implement ThreadElfCore::GetSiginfo to return (verbatim) copy of the 
siginfo_t from the core file
- Implement a generic stop info description calculation (on platform class) 
function

Besides the stop description, this should also make the `thread siginfo` 
command work, and we can consider removing the lldb-server-based stop info 
computation logic, since this impl should cover both live and post-portem use 
cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145377

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


[Lldb-commits] [PATCH] D145136: Add a Debugger interruption mechanism in parallel to the Command Interpreter interruption

2023-03-06 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I kinda like this.




Comment at: lldb/include/lldb/Core/Debugger.h:563
+  // the previous IOHandler thread.
+  const HostThread SetIOHandlerThread(HostThread &new_thread);
 

`const` on a return value rarely makes sense. OTOH, `const` on the argument 
usually does. Did you want this the other way around?



Comment at: lldb/include/lldb/Core/Debugger.h:647
+  uint32_t m_interrupt_requested = 0;
+  std::vector m_interrupt_stack;
+  std::recursive_mutex m_interrupt_mutex;

I think this is unused



Comment at: lldb/include/lldb/Core/Debugger.h:648
+  std::vector m_interrupt_stack;
+  std::recursive_mutex m_interrupt_mutex;
 

can we make this non-recursive?



Comment at: lldb/source/API/SBDebugger.cpp:1700
+}
+  void SBDebugger::CancelInterruptRequest()  {
+  LLDB_INSTRUMENT_VA(this);

bad formatting



Comment at: 
lldb/test/API/python_api/was_interrupted/TestDebuggerInterruption.py:39
+def rendevous(self):
+# We smuggle out lock and event to the runner thread using thread 
local data:
+import interruptible

This had me confused for a while, because "thread local data" has a very 
specific meaning. Could you rename this to something else?



Comment at: 
lldb/test/API/python_api/was_interrupted/TestDebuggerInterruption.py:112
+if not "check" in args:
+self.lock = threading.Lock()
+self.event = threading.Event()

I am confused as to what this lock's purpose is. I can see that it's taken on 
one thread and released on another (which is in itself an unusual thing to do, 
even though python permits it), but I still don't understand what does it 
achieve. Lock are generally used for protecting a certain object. If the goal 
is to control the interleaving of two threads, then maybe a sequence of 
barriers would be better. Something like:
```
#thread 1
work1()
t1_done.wait()
t2_done.wait()
work3()
t1_done.wait()
# etc.. odd-numbered work happens on this thread

#thread 2
t1_done.wait()
work2()
t2_done.wait()
t1_done.wait()
work4()
# etc.. even-numbered work happens here
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145136

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


[Lldb-commits] [PATCH] D145377: [LLDB] Show sub type of signals for ELF core files

2023-03-06 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett planned changes to this revision.
DavidSpickett added inline comments.



Comment at: lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp:230
+
+  siginfo_t info;
+  info.si_signo = m_signo;

labath wrote:
> I think this won't work on Windows (no siginfo_t type, nor constants to 
> decode it) -- and it may return garbage on other platforms if they use 
> different constants.
> 
> If I may suggest an alternative implementation:
> - Implement ThreadElfCore::GetSiginfo to return (verbatim) copy of the 
> siginfo_t from the core file
> - Implement a generic stop info description calculation (on platform class) 
> function
> 
> Besides the stop description, this should also make the `thread siginfo` 
> command work, and we can consider removing the lldb-server-based stop info 
> computation logic, since this impl should cover both live and post-portem use 
> cases.
Yes, of course.

I'll try what you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145377

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


[Lldb-commits] [lldb] 960126e - [LLDB][NativePDB] Check string table in PDB files.

2023-03-06 Thread Zequan Wu via lldb-commits

Author: Zequan Wu
Date: 2023-03-06T10:25:38-05:00
New Revision: 960126e04a6faad1b71e110a4262c5733e50fab7

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

LOG: [LLDB][NativePDB] Check string table in PDB files.

Usually PDB files have a string table (aka: Named Stream "/names" ). PDB for
some windows system libraries might not have that. This adds the check for it to
avoid crash in the absence of string table.

Reviewed By: labath

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

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
index e2e06491e8c17..06cb720b1e9f7 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
@@ -162,9 +162,13 @@ CompilandIndexItem 
&CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) {
   ParseExtendedInfo(m_index, *cci);
   ParseInlineeLineTableForCompileUnit(*cci);
 
-  cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
-  PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());
-  cci->m_strings.setStrings(strings.getStringTable());
+  auto strings = m_index.pdb().getStringTable();
+  if (strings) {
+cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
+cci->m_strings.setStrings(strings->getStringTable());
+  } else {
+consumeError(strings.takeError());
+  }
 
   // We want the main source file to always comes first.  Note that we can't
   // just push_back the main file onto the front because `GetMainSourceFile`

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
index 164bfa8b3726a..888bd89a72625 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
@@ -703,8 +703,12 @@ static bool GetFrameDataProgram(PdbIndex &index,
   if (frame_data_it == new_fpo_data.end())
 return false;
 
-  PDBStringTable &strings = cantFail(index.pdb().getStringTable());
-  out_program = cantFail(strings.getStringForID(frame_data_it->FrameFunc));
+  auto strings = index.pdb().getStringTable();
+  if (!strings) {
+consumeError(strings.takeError());
+return false;
+  }
+  out_program = cantFail(strings->getStringForID(frame_data_it->FrameFunc));
   return true;
 }
 

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 82d3707acfa4b..b99e9ec82f126 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1341,6 +1341,9 @@ bool SymbolFileNativePDB::ParseDebugMacros(CompileUnit 
&comp_unit) {
 llvm::Expected
 SymbolFileNativePDB::GetFileIndex(const CompilandIndexItem &cii,
   uint32_t file_id) {
+  if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
+return llvm::make_error(raw_error_code::no_entry);
+
   const auto &checksums = cii.m_strings.checksums().getArray();
   const auto &strings = cii.m_strings.strings();
   // Indices in this structure are actually offsets of records in the



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


[Lldb-commits] [PATCH] D145115: [LLDB][NativePDB] Check string table in PDB files.

2023-03-06 Thread Zequan Wu via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG960126e04a6f: [LLDB][NativePDB] Check string table in PDB 
files. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145115

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp


Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1341,6 +1341,9 @@
 llvm::Expected
 SymbolFileNativePDB::GetFileIndex(const CompilandIndexItem &cii,
   uint32_t file_id) {
+  if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
+return llvm::make_error(raw_error_code::no_entry);
+
   const auto &checksums = cii.m_strings.checksums().getArray();
   const auto &strings = cii.m_strings.strings();
   // Indices in this structure are actually offsets of records in the
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
@@ -703,8 +703,12 @@
   if (frame_data_it == new_fpo_data.end())
 return false;
 
-  PDBStringTable &strings = cantFail(index.pdb().getStringTable());
-  out_program = cantFail(strings.getStringForID(frame_data_it->FrameFunc));
+  auto strings = index.pdb().getStringTable();
+  if (!strings) {
+consumeError(strings.takeError());
+return false;
+  }
+  out_program = cantFail(strings->getStringForID(frame_data_it->FrameFunc));
   return true;
 }
 
Index: lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
@@ -162,9 +162,13 @@
   ParseExtendedInfo(m_index, *cci);
   ParseInlineeLineTableForCompileUnit(*cci);
 
-  cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
-  PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());
-  cci->m_strings.setStrings(strings.getStringTable());
+  auto strings = m_index.pdb().getStringTable();
+  if (strings) {
+cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
+cci->m_strings.setStrings(strings->getStringTable());
+  } else {
+consumeError(strings.takeError());
+  }
 
   // We want the main source file to always comes first.  Note that we can't
   // just push_back the main file onto the front because `GetMainSourceFile`


Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1341,6 +1341,9 @@
 llvm::Expected
 SymbolFileNativePDB::GetFileIndex(const CompilandIndexItem &cii,
   uint32_t file_id) {
+  if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
+return llvm::make_error(raw_error_code::no_entry);
+
   const auto &checksums = cii.m_strings.checksums().getArray();
   const auto &strings = cii.m_strings.strings();
   // Indices in this structure are actually offsets of records in the
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
@@ -703,8 +703,12 @@
   if (frame_data_it == new_fpo_data.end())
 return false;
 
-  PDBStringTable &strings = cantFail(index.pdb().getStringTable());
-  out_program = cantFail(strings.getStringForID(frame_data_it->FrameFunc));
+  auto strings = index.pdb().getStringTable();
+  if (!strings) {
+consumeError(strings.takeError());
+return false;
+  }
+  out_program = cantFail(strings->getStringForID(frame_data_it->FrameFunc));
   return true;
 }
 
Index: lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
@@ -162,9 +162,13 @@
   ParseExtendedInfo(m_index, *cci);
   ParseInlineeLineTableForCompileUnit(*cci);
 
-  cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
-  PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());
-  cci->m_strings.setStrings(strings.getStringTable());
+  

[Lldb-commits] [PATCH] D143520: Add a new SBDebugger::SetDestroyCallback() API

2023-03-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

Just change HandleDestroryCallback to a member function and this is good to go.




Comment at: lldb/source/Core/Debugger.cpp:688-694
+void Debugger::HandleDestroyCallback(const DebuggerSP &debugger_sp) {
+  if (debugger_sp->m_destroy_callback) {
+debugger_sp->m_destroy_callback(debugger_sp->GetID(),
+debugger_sp->m_destroy_callback_baton);
+debugger_sp->m_destroy_callback = nullptr;
+  }
+}

This should be a member function instead of a static function that takes a 
debugger_sp an argument.



Comment at: lldb/source/Core/Debugger.cpp:700
 
+  HandleDestroyCallback(debugger_sp);
   CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143520

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


[Lldb-commits] [PATCH] D145348: [lldb] Test 'v' support for direct ivar access (NFC)

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 502716.
kastiglione added a comment.

Split into separate cpp/this and objc/self tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145348

Files:
  lldb/test/API/commands/frame/var/direct-ivar/Makefile
  lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
  lldb/test/API/commands/frame/var/direct-ivar/main.mm


Index: lldb/test/API/commands/frame/var/direct-ivar/main.mm
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/main.mm
@@ -0,0 +1,28 @@
+#include 
+
+struct Structure {
+  int m_field;
+  int fun() { return this->m_field; }
+};
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  return self->_ivar;
+}
+@end
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+
+  Classic *c = [Classic new];
+  c->_ivar = 41;
+  [c fun];
+}
Index: lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "this", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")
+
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "self", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 41")
Index: lldb/test/API/commands/frame/var/direct-ivar/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/Makefile
@@ -0,0 +1,2 @@
+OBJCXX_SOURCES := main.mm
+include Makefile.rules


Index: lldb/test/API/commands/frame/var/direct-ivar/main.mm
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/main.mm
@@ -0,0 +1,28 @@
+#include 
+
+struct Structure {
+  int m_field;
+  int fun() { return this->m_field; }
+};
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  return self->_ivar;
+}
+@end
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+
+  Classic *c = [Classic new];
+  c->_ivar = 41;
+  [c fun];
+}
Index: lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "this", lldb.SBFileSpec("main.mm"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")
+
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "self", lldb.SBFileSpec("main.mm"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 41")
Index: lldb/test/API/commands/frame/var/direct-ivar/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/Makefile
@@ -0,0 +1,2 @@
+OBJCXX_SOURCES := main.mm
+include Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145348: [lldb] Test 'v' support for direct ivar access (NFC)

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03e5c46e15b4: [lldb] Test 'v' support for direct 
ivar access (NFC) (authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145348

Files:
  lldb/test/API/commands/frame/var/direct-ivar/Makefile
  lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
  lldb/test/API/commands/frame/var/direct-ivar/main.mm


Index: lldb/test/API/commands/frame/var/direct-ivar/main.mm
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/main.mm
@@ -0,0 +1,28 @@
+#include 
+
+struct Structure {
+  int m_field;
+  int fun() { return this->m_field; }
+};
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  return self->_ivar;
+}
+@end
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+
+  Classic *c = [Classic new];
+  c->_ivar = 41;
+  [c fun];
+}
Index: lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "this", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")
+
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "self", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 41")
Index: lldb/test/API/commands/frame/var/direct-ivar/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/Makefile
@@ -0,0 +1,2 @@
+OBJCXX_SOURCES := main.mm
+include Makefile.rules


Index: lldb/test/API/commands/frame/var/direct-ivar/main.mm
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/main.mm
@@ -0,0 +1,28 @@
+#include 
+
+struct Structure {
+  int m_field;
+  int fun() { return this->m_field; }
+};
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  return self->_ivar;
+}
+@end
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+
+  Classic *c = [Classic new];
+  c->_ivar = 41;
+  [c fun];
+}
Index: lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "this", lldb.SBFileSpec("main.mm"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")
+
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "self", lldb.SBFileSpec("main.mm"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 41")
Index: lldb/test/API/commands/frame/var/direct-ivar/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/frame/var/direct-ivar/Makefile
@@ -0,0 +1,2 @@
+OBJCXX_SOURCES := main.mm
+include Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 03e5c46 - [lldb] Test 'v' support for direct ivar access (NFC)

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T10:41:51-08:00
New Revision: 03e5c46e15b4a196cdca0c646e61f0c92a6dc7e1

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

LOG: [lldb] Test 'v' support for direct ivar access (NFC)

Add basic tests for `frame variable`'s ability to direct access fields of 
`this` and
ivars of `self`.

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

Added: 
lldb/test/API/commands/frame/var/direct-ivar/Makefile
lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
lldb/test/API/commands/frame/var/direct-ivar/main.mm

Modified: 


Removed: 




diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/Makefile 
b/lldb/test/API/commands/frame/var/direct-ivar/Makefile
new file mode 100644
index ..551d06d6c922
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/Makefile
@@ -0,0 +1,2 @@
+OBJCXX_SOURCES := main.mm
+include Makefile.rules

diff  --git 
a/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py 
b/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
new file mode 100644
index ..1a3f81464034
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "this", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")
+
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "self", 
lldb.SBFileSpec("main.mm"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 41")

diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/main.mm 
b/lldb/test/API/commands/frame/var/direct-ivar/main.mm
new file mode 100644
index ..d4a584689efe
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/main.mm
@@ -0,0 +1,28 @@
+#include 
+
+struct Structure {
+  int m_field;
+  int fun() { return this->m_field; }
+};
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  return self->_ivar;
+}
+@end
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+
+  Classic *c = [Classic new];
+  c->_ivar = 41;
+  [c fun];
+}



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


[Lldb-commits] [lldb] 8794712 - [lldb] Add variable completion to dwim-print

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T10:42:32-08:00
New Revision: 8794712e8877ed366542c32e28abe40d0a9ced6d

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

LOG: [lldb] Add variable completion to dwim-print

Enable completion of variables for `dwim-print` command.

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Commands/CommandObjectDWIMPrint.h
lldb/test/API/functionalities/completion/TestCompletion.py

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a348f416af22..e2e6f6706dee 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -32,6 +32,10 @@ 
CommandObjectDWIMPrint::CommandObjectDWIMPrint(CommandInterpreter &interpreter)
"Print a variable or expression.",
"dwim-print [ | ]",
eCommandProcessMustBePaused | eCommandTryTargetAPILock) 
{
+
+  CommandArgumentData var_name_arg(eArgTypeVarName, eArgRepeatPlain);
+  m_arguments.push_back({var_name_arg});
+
   m_option_group.Append(&m_format_options,
 OptionGroupFormat::OPTION_GROUP_FORMAT |
 OptionGroupFormat::OPTION_GROUP_GDB_FMT,
@@ -44,6 +48,13 @@ 
CommandObjectDWIMPrint::CommandObjectDWIMPrint(CommandInterpreter &interpreter)
 
 Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; }
 
+void CommandObjectDWIMPrint::HandleArgumentCompletion(
+CompletionRequest &request, OptionElementVector &opt_element_vector) {
+  CommandCompletions::InvokeCommonCompletionCallbacks(
+  GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
+  request, nullptr);
+}
+
 bool CommandObjectDWIMPrint::DoExecute(StringRef command,
CommandReturnObject &result) {
   m_option_group.NotifyOptionParsingStarting(&m_exe_ctx);

diff  --git a/lldb/source/Commands/CommandObjectDWIMPrint.h 
b/lldb/source/Commands/CommandObjectDWIMPrint.h
index 8a14a6c7bb53..3fc6c01d4729 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.h
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.h
@@ -37,6 +37,12 @@ class CommandObjectDWIMPrint : public CommandObjectRaw {
 
   Options *GetOptions() override;
 
+  bool WantsCompletion() override { return true; }
+
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+   OptionElementVector &opt_element_vector) override;
+
 private:
   bool DoExecute(llvm::StringRef command, CommandReturnObject &result) 
override;
 

diff  --git a/lldb/test/API/functionalities/completion/TestCompletion.py 
b/lldb/test/API/functionalities/completion/TestCompletion.py
index f2d3fb704900..baaf9f57162c 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -36,42 +36,55 @@ def test_de(self):
 
 def test_frame_variable(self):
 self.build()
-self.main_source = "main.cpp"
-self.main_source_spec = lldb.SBFileSpec(self.main_source)
 
-(target, process, thread, bkpt) = 
lldbutil.run_to_source_breakpoint(self,
-  '// Break here', 
self.main_source_spec)
+_, process, _, _ = lldbutil.run_to_source_breakpoint(
+self, '// Break here', lldb.SBFileSpec("main.cpp"))
 self.assertState(process.GetState(), lldb.eStateStopped)
 
 # Since CommandInterpreter has been corrected to update the current 
execution
 # context at the beginning of HandleCompletion, we're here explicitly 
testing
 # the scenario where "frame var" is completed without any preceding 
commands.
+self.do_test_variable_completion('frame variable')
 
-self.complete_from_to('frame variable fo',
-  'frame variable fooo')
-self.complete_from_to('frame variable fooo.',
-  'frame variable fooo.')
-self.complete_from_to('frame variable fooo.dd',
-  'frame variable fooo.dd')
-
-self.complete_from_to('frame variable ptr_fooo->',
-  'frame variable ptr_fooo->')
-self.complete_from_to('frame variable ptr_fooo->dd',
-  'frame variable ptr_fooo->dd')
-
-self.complete_from_to('frame variable cont',
-  'frame variable container')
-self.complete_from_to('frame variable container.',
-  'frame variable container.MemberVar')
-self.complete_from_to('frame variable containe

[Lldb-commits] [PATCH] D145124: [lldb] Add variable completion to dwim-print

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8794712e8877: [lldb] Add variable completion to dwim-print 
(authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145124

Files:
  lldb/source/Commands/CommandObjectDWIMPrint.cpp
  lldb/source/Commands/CommandObjectDWIMPrint.h
  lldb/test/API/functionalities/completion/TestCompletion.py

Index: lldb/test/API/functionalities/completion/TestCompletion.py
===
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -36,42 +36,55 @@
 
 def test_frame_variable(self):
 self.build()
-self.main_source = "main.cpp"
-self.main_source_spec = lldb.SBFileSpec(self.main_source)
 
-(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
-  '// Break here', self.main_source_spec)
+_, process, _, _ = lldbutil.run_to_source_breakpoint(
+self, '// Break here', lldb.SBFileSpec("main.cpp"))
 self.assertState(process.GetState(), lldb.eStateStopped)
 
 # Since CommandInterpreter has been corrected to update the current execution
 # context at the beginning of HandleCompletion, we're here explicitly testing
 # the scenario where "frame var" is completed without any preceding commands.
+self.do_test_variable_completion('frame variable')
 
-self.complete_from_to('frame variable fo',
-  'frame variable fooo')
-self.complete_from_to('frame variable fooo.',
-  'frame variable fooo.')
-self.complete_from_to('frame variable fooo.dd',
-  'frame variable fooo.dd')
-
-self.complete_from_to('frame variable ptr_fooo->',
-  'frame variable ptr_fooo->')
-self.complete_from_to('frame variable ptr_fooo->dd',
-  'frame variable ptr_fooo->dd')
-
-self.complete_from_to('frame variable cont',
-  'frame variable container')
-self.complete_from_to('frame variable container.',
-  'frame variable container.MemberVar')
-self.complete_from_to('frame variable container.Mem',
-  'frame variable container.MemberVar')
-
-self.complete_from_to('frame variable ptr_cont',
-  'frame variable ptr_container')
-self.complete_from_to('frame variable ptr_container->',
-  'frame variable ptr_container->MemberVar')
-self.complete_from_to('frame variable ptr_container->Mem',
-  'frame variable ptr_container->MemberVar')
+def test_dwim_print(self):
+self.build()
+
+_, process, _, _ = lldbutil.run_to_source_breakpoint(
+self, '// Break here', lldb.SBFileSpec("main.cpp"))
+self.assertState(process.GetState(), lldb.eStateStopped)
+
+# Since CommandInterpreter has been corrected to update the current execution
+# context at the beginning of HandleCompletion, we're here explicitly testing
+# the scenario where "frame var" is completed without any preceding commands.
+self.do_test_variable_completion('dwim-print')
+
+
+def do_test_variable_completion(self, command):
+self.complete_from_to(f'{command} fo',
+  f'{command} fooo')
+self.complete_from_to(f'{command} fooo.',
+  f'{command} fooo.')
+self.complete_from_to(f'{command} fooo.dd',
+  f'{command} fooo.dd')
+
+self.complete_from_to(f'{command} ptr_fooo->',
+  f'{command} ptr_fooo->')
+self.complete_from_to(f'{command} ptr_fooo->dd',
+  f'{command} ptr_fooo->dd')
+
+self.complete_from_to(f'{command} cont',
+  f'{command} container')
+self.complete_from_to(f'{command} container.',
+  f'{command} container.MemberVar')
+self.complete_from_to(f'{command} container.Mem',
+  f'{command} container.MemberVar')
+
+self.complete_from_to(f'{command} ptr_cont',
+  f'{command} ptr_container')
+self.complete_from_to(f'{command} ptr_container->',
+  f'{command} ptr_container->MemberVar')
+self.complete_from_to(f'{command} ptr_container->Mem',
+  f'{command} ptr_container->MemberVar')
 
 def test_process_attach_dash_dash_con(self):
 """Test that 'process attach --con' completes to 'process attach --

[Lldb-commits] [lldb] 3df28ef - Revert "[lldb] Test 'v' support for direct ivar access (NFC)"

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T11:12:28-08:00
New Revision: 3df28efaa0d2611e033a5fdce8e369446da9d3dc

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

LOG: Revert "[lldb] Test 'v' support for direct ivar access (NFC)"

This reverts commit 03e5c46e15b4a196cdca0c646e61f0c92a6dc7e1.

Added: 


Modified: 


Removed: 
lldb/test/API/commands/frame/var/direct-ivar/Makefile
lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
lldb/test/API/commands/frame/var/direct-ivar/main.mm



diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/Makefile 
b/lldb/test/API/commands/frame/var/direct-ivar/Makefile
deleted file mode 100644
index 551d06d6c9227..0
--- a/lldb/test/API/commands/frame/var/direct-ivar/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-OBJCXX_SOURCES := main.mm
-include Makefile.rules

diff  --git 
a/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py 
b/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
deleted file mode 100644
index 1a3f81464034e..0
--- a/lldb/test/API/commands/frame/var/direct-ivar/TestFrameVarDirectIvar.py
+++ /dev/null
@@ -1,15 +0,0 @@
-import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class TestCase(TestBase):
-def test_cpp_this(self):
-self.build()
-lldbutil.run_to_source_breakpoint(self, "this", 
lldb.SBFileSpec("main.mm"))
-self.expect("frame variable m_field", startstr="(int) m_field = 30")
-
-def test_objc_self(self):
-self.build()
-lldbutil.run_to_source_breakpoint(self, "self", 
lldb.SBFileSpec("main.mm"))
-self.expect("frame variable _ivar", startstr="(int) _ivar = 41")

diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/main.mm 
b/lldb/test/API/commands/frame/var/direct-ivar/main.mm
deleted file mode 100644
index d4a584689efe3..0
--- a/lldb/test/API/commands/frame/var/direct-ivar/main.mm
+++ /dev/null
@@ -1,28 +0,0 @@
-#include 
-
-struct Structure {
-  int m_field;
-  int fun() { return this->m_field; }
-};
-
-@interface Classic : NSObject {
-@public
-  int _ivar;
-}
-@end
-
-@implementation Classic
-- (int)fun {
-  return self->_ivar;
-}
-@end
-
-int main() {
-  Structure s;
-  s.m_field = 30;
-  s.fun();
-
-  Classic *c = [Classic new];
-  c->_ivar = 41;
-  [c fun];
-}



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


[Lldb-commits] [lldb] 23ee705 - Recommit [lldb] Test 'v' support for direct ivar access (NFC)

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T11:52:41-08:00
New Revision: 23ee705ac99aade24cec0ebb8f6c4cfc76bcdb08

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

LOG: Recommit [lldb] Test 'v' support for direct ivar access (NFC)

Add basic tests for `frame variable`'s ability to direct access fields of 
`this` and
ivars of `self`.

This splits the tests, preventing ObjC tests from running on Linux.

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

Added: 
lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile

lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py
lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp
lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile

lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
lldb/test/API/commands/frame/var/direct-ivar/objc/main.m

Modified: 


Removed: 




diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile 
b/lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile
new file mode 100644
index 0..3d0b98f13f3d7
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile
@@ -0,0 +1,2 @@
+CXX_SOURCES := main.cpp
+include Makefile.rules

diff  --git 
a/lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py 
b/lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py
new file mode 100644
index 0..f483899a75509
--- /dev/null
+++ 
b/lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py
@@ -0,0 +1,11 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+def test_cpp_this(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// check this", 
lldb.SBFileSpec("main.cpp"))
+self.expect("frame variable m_field", startstr="(int) m_field = 30")

diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp 
b/lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp
new file mode 100644
index 0..eadb02be38368
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp
@@ -0,0 +1,12 @@
+struct Structure {
+  int m_field;
+  void fun() {
+// check this
+  }
+};
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+}

diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile 
b/lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
new file mode 100644
index 0..d0aadc1af9e58
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
@@ -0,0 +1,2 @@
+OBJC_SOURCES := main.m
+include Makefile.rules

diff  --git 
a/lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
 
b/lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
new file mode 100644
index 0..395e014b2d88f
--- /dev/null
+++ 
b/lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
@@ -0,0 +1,12 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@skipUnlessDarwin
+def test_objc_self(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// check self", 
lldb.SBFileSpec("main.m"))
+self.expect("frame variable _ivar", startstr="(int) _ivar = 30")

diff  --git a/lldb/test/API/commands/frame/var/direct-ivar/objc/main.m 
b/lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
new file mode 100644
index 0..3d5ef38dd3187
--- /dev/null
+++ b/lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
@@ -0,0 +1,19 @@
+#include 
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  // check self
+}
+@end
+
+int main() {
+  Classic *c = [Classic new];
+  c->_ivar = 30;
+  [c fun];
+}



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


[Lldb-commits] [PATCH] D145414: [lldb/Utility] Fix layering violation caused by ScriptedMetadata

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

This patch moves `ScriptedMetadata.h` from the `Interpreter` directory to
the `Utility` sub-directory since `ProcessInfo.h` depends on it.

It also gets rid of the unused `OptionGroupPythonClassWithDict`
constructor for `ScriptedMetadata` which would address the layering
violation.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145414

Files:
  lldb/include/lldb/Interpreter/ScriptedMetadata.h
  lldb/include/lldb/Utility/ScriptedMetadata.h
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/Commands/CommandObjectPlatform.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Utility/ProcessInfo.cpp

Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -8,8 +8,8 @@
 
 #include "lldb/Utility/ProcessInfo.h"
 
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/UserIDResolver.h"
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -9,9 +9,9 @@
 #ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
 #define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
 
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 #include "lldb/Utility/Status.h"
 
 #include "ScriptedThread.h"
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -18,11 +18,11 @@
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Interpreter/OptionGroupBoolean.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/MemoryRegionInfo.h"
 #include "lldb/Target/Queue.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 #include "lldb/Utility/State.h"
 
 #include 
Index: lldb/source/Commands/CommandObjectProcess.cpp
===
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -25,7 +25,6 @@
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
 #include "lldb/Interpreter/Options.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
@@ -33,6 +32,7 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 #include "lldb/Utility/State.h"
 
 #include "llvm/ADT/ScopeExit.h"
Index: lldb/source/Commands/CommandObjectPlatform.cpp
===
--- lldb/source/Commands/CommandObjectPlatform.cpp
+++ lldb/source/Commands/CommandObjectPlatform.cpp
@@ -20,11 +20,11 @@
 #include "lldb/Interpreter/OptionGroupFile.h"
 #include "lldb/Interpreter/OptionGroupPlatform.h"
 #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 
 #include "llvm/ADT/SmallString.h"
 
Index: lldb/source/API/SBLaunchInfo.cpp
===
--- lldb/source/API/SBLaunchInfo.cpp
+++ lldb/source/API/SBLaunchInfo.cpp
@@ -17,7 +17,7 @@
 #include "lldb/API/SBStructuredData.h"
 #include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/Host/ProcessLaunchInfo.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 
 using namespace lldb;
 using namespace lldb_private;
Index: lldb/source/API/SBAttachInfo.cpp
===
--- lldb/source/API/SBAttachInfo.cpp
+++ lldb/source/API/SBAttachInfo.cpp
@@ -11,9 +11,9 @@
 #include "lldb/API/SBFileSpec.h"
 #incl

[Lldb-commits] [PATCH] D143104: [lldb/Plugins] Add Attach capabilities to ScriptedProcess

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



Comment at: lldb/source/Utility/ProcessInfo.cpp:11
 
+#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Utility/ArchSpec.h"

labath wrote:
> This is a layering violation. Can we restructure this so that it this does 
> not depend on code outside the Utility library? Maybe the ScriptedMetadata 
> thingy could be moved into the Utility library?
@labath Thanks for pointing this out! I fixed it in D145414


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143104

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


[Lldb-commits] [PATCH] D145189: [lldb] Redefine p alias to dwim-print command

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added a comment.

> So, one could say that (right now) this patch is NFC for end-users, because 
> `dwim-print` supports all use-cases that the old `p` alias supported?

Correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145189

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


[Lldb-commits] [lldb] a00801d - [lldb] Redefine p alias to dwim-print command

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T12:27:15-08:00
New Revision: a00801d94b02eaebd1385b03fb9e549c07cc8585

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

LOG: [lldb] Redefine p alias to dwim-print command

Redefine the `p` alias to the `dwim-print` command instead of `expression`.

See https://reviews.llvm.org/D138315 for the introduction of `dwim-print`.

To summarize, `dwim-print` is, as the name suggests, a command for printing. 
How a value
gets printed, is decided by `dwim-print`. In some cases, `dwim-print` will 
print values
using the same means as `frame variable` (because it's generally more reliable 
and
faster that `expression` evaluation), and in other cases `dwim-print` uses the 
same code
path as `expression`.

This change has been tested in two different ways:

1. Re-aliasing `p` to `dwim-print`, as in this patch
2. Redefinining the `expression` command to `CommandObjectDWIMPrint`

Previously, many of the lldb's tests used `p`, and which meant a test run with 
`p`
aliases to `dwim-print` was a good way to test `dwim-print`. However most of 
those tests
were updated to use `expression` explicitly (in anticipation of this change). 
Now, the
best way to test `dwim-print` is the second approach:

```
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index 373c894f34f5..9c943cd30c7c 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -539,7 +539,7 @@ void CommandInterpreter::LoadCommandDictionary() {
   REGISTER_COMMAND_OBJECT("diagnostics", CommandObjectDiagnostics);
   REGISTER_COMMAND_OBJECT("disassemble", CommandObjectDisassemble);
   REGISTER_COMMAND_OBJECT("dwim-print", CommandObjectDWIMPrint);
-  REGISTER_COMMAND_OBJECT("expression", CommandObjectExpression);
+  REGISTER_COMMAND_OBJECT("expression", CommandObjectDWIMPrint);
   REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame);
   REGISTER_COMMAND_OBJECT("gui", CommandObjectGUI);
   REGISTER_COMMAND_OBJECT("help", CommandObjectHelp);
```

When the test suite is run with this change, there are two main categories of 
test
failures for specific to features that `dwim-print` intentionally doesn't 
support:

1. Top level expressions (`--top-level`/`-p`)
2. Multiline expressions

In cases where the behavior of `expression` is needed, users can use 
`expression` at
those times.

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

Added: 


Modified: 
lldb/source/Interpreter/CommandInterpreter.cpp

Removed: 




diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index 1437ca464e760..c03806d94210c 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -413,17 +413,21 @@ void CommandInterpreter::Initialize() {
 
   alias_arguments_vector_sp = std::make_shared();
 
-  cmd_obj_sp = GetCommandSPExact("expression");
+  cmd_obj_sp = GetCommandSPExact("dwim-print");
   if (cmd_obj_sp) {
 AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
 AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
-AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
   po->SetHelp("Evaluate an expression on the current thread.  Displays any 
"
   "returned value with formatting "
   "controlled by the type's author.");
   po->SetHelpLong("");
 }
+  }
+
+  cmd_obj_sp = GetCommandSPExact("expression");
+  if (cmd_obj_sp) {
+AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 CommandAlias *parray_alias =
 AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
 if (parray_alias) {



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


[Lldb-commits] [PATCH] D145189: [lldb] Redefine p alias to dwim-print command

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa00801d94b02: [lldb] Redefine p alias to dwim-print command 
(authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145189

Files:
  lldb/source/Interpreter/CommandInterpreter.cpp


Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -413,17 +413,21 @@
 
   alias_arguments_vector_sp = std::make_shared();
 
-  cmd_obj_sp = GetCommandSPExact("expression");
+  cmd_obj_sp = GetCommandSPExact("dwim-print");
   if (cmd_obj_sp) {
 AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
 AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
-AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
   po->SetHelp("Evaluate an expression on the current thread.  Displays any 
"
   "returned value with formatting "
   "controlled by the type's author.");
   po->SetHelpLong("");
 }
+  }
+
+  cmd_obj_sp = GetCommandSPExact("expression");
+  if (cmd_obj_sp) {
+AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 CommandAlias *parray_alias =
 AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
 if (parray_alias) {


Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -413,17 +413,21 @@
 
   alias_arguments_vector_sp = std::make_shared();
 
-  cmd_obj_sp = GetCommandSPExact("expression");
+  cmd_obj_sp = GetCommandSPExact("dwim-print");
   if (cmd_obj_sp) {
 AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
 AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
-AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
   po->SetHelp("Evaluate an expression on the current thread.  Displays any "
   "returned value with formatting "
   "controlled by the type's author.");
   po->SetHelpLong("");
 }
+  }
+
+  cmd_obj_sp = GetCommandSPExact("expression");
+  if (cmd_obj_sp) {
+AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 CommandAlias *parray_alias =
 AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
 if (parray_alias) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145276: [lldb] Let 'v' command directly access ivars of _any_ self/this

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
kastiglione updated this revision to Diff 502753.
kastiglione added a comment.
kastiglione edited the summary of this revision.
kastiglione added reviewers: aprantl, Michael137, jingham.
kastiglione published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Add tests; rebase


The `v` (`frame variable`) command can access ivars/fields of `this` or `self`. 
This
change relaxes the criteria for finding `this`/`self`.

There are cases where a `this`/`self` variable does exist, but are cases in 
which `v` did not
support direct access of ivars -- meaning the user would have to type 
`this->field` or
`self->_ivar` to access. This change allows those cases to also work without 
explicitly
dereferencing `this`/`self`.

For example:

  __weak Type *weakSelf = self;
  void (^block)() = ^{
 Type *self = weakSelf; // Re-establish strong reference.
 // ...
  };

In this case, `self` exists but `v` wouldn't use it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145276

Files:
  lldb/include/lldb/Symbol/CompilerDeclContext.h
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/source/Symbol/CompilerDeclContext.cpp
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Target/StackFrame.cpp
  lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
  
lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
  lldb/test/API/commands/frame/var/direct-ivar/objc/main.m

Index: lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
===
--- lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
+++ lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
@@ -7,13 +7,25 @@
 @end
 
 @implementation Classic
-- (int)fun {
+- (void)fun {
   // check self
 }
+
+- (void)run {
+  __weak Classic *weakSelf = self;
+  ^{
+Classic *self = weakSelf;
+// check idiomatic self
+
+// Use `self` to extend its lifetime (for lldb to inspect the variable).
+[self copy];
+  }();
+}
 @end
 
 int main() {
   Classic *c = [Classic new];
   c->_ivar = 30;
   [c fun];
+  [c run];
 }
Index: lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
===
--- lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
+++ lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
@@ -10,3 +10,11 @@
 self.build()
 lldbutil.run_to_source_breakpoint(self, "// check self", lldb.SBFileSpec("main.m"))
 self.expect("frame variable _ivar", startstr="(int) _ivar = 30")
+
+@skipUnlessDarwin
+def test_objc_self_capture_idiom(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// check idiomatic self", lldb.SBFileSpec("main.m"))
+self.expect("frame variable weakSelf", startstr="(Classic *) weakSelf = 0x")
+self.expect("frame variable self", startstr="(Classic *) self = 0x")
+self.expect("frame variable _ivar", startstr="(int) _ivar = 30")
Index: lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
===
--- lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
+++ lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
@@ -1,2 +1,4 @@
 OBJC_SOURCES := main.m
+CFLAGS_EXTRAS := -fblocks -fobjc-arc
+LD_EXTRAS := -lobjc
 include Makefile.rules
Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -567,23 +567,20 @@
 // Check for direct ivars access which helps us with implicit access to
 // ivars using "this" or "self".
 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
-ConstString method_object_name;
-if (m_sc.GetFunctionMethodInfo(method_object_name)) {
-  if (method_object_name) {
-var_sp = variable_list->FindVariable(method_object_name);
-if (var_sp) {
-  separator_idx = 0;
-  if (Type *var_type = var_sp->GetType())
-if (auto compiler_type = var_type->GetForwardCompilerType())
-  if (!compiler_type.IsPointerType())
-var_expr_storage = ".";
+if (auto instance_var_name = m_sc.GetInstanceVariableName()) {
+  var_sp = variable_list->FindVariable(instance_var_name);
+  if (var_sp) {
+separator_idx = 0;
+if (Type *var_type = var_sp->GetType())
+  if (auto compiler_type = var_type->GetForwardCompilerType())
+if (!compiler_type.IsPointerType())
+  var_expr_storage = "

[Lldb-commits] [PATCH] D145414: [lldb/Utility] Fix layering violation caused by ScriptedMetadata

2023-03-06 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lldb/include/lldb/Utility/ScriptedMetadata.h:33-38
-  ScriptedMetadata(const OptionGroupPythonClassWithDict &option_group) {
-auto opt_group = const_cast(option_group);
-m_class_name = opt_group.GetName();
-m_args_sp = opt_group.GetStructuredData();
-  }
-

I guess this just isn't used?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145414

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


[Lldb-commits] [PATCH] D145414: [lldb/Utility] Fix layering violation caused by ScriptedMetadata

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/include/lldb/Utility/ScriptedMetadata.h:33-38
-  ScriptedMetadata(const OptionGroupPythonClassWithDict &option_group) {
-auto opt_group = const_cast(option_group);
-m_class_name = opt_group.GetName();
-m_args_sp = opt_group.GetStructuredData();
-  }
-

bulbazord wrote:
> I guess this just isn't used?
yep


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145414

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


[Lldb-commits] [lldb] 3675e0b - [lldb/API] Introduce SBProcess::ForceScriptedState method

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:14:15-08:00
New Revision: 3675e0bb67fa86b8476a67bb1a7623a6b1a373b3

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

LOG: [lldb/API] Introduce SBProcess::ForceScriptedState method

This patch introduces a new method to the SBProcess API called
ForceScriptedState. As the name suggests, this affordance will allow the
user to alter the private state of the scripted process programatically.

This is necessary to update the scripted process state when perform
interactive debugging.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 




diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index be0048763a25d..4b87d4afa310c 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -187,6 +187,14 @@ class LLDB_API SBProcess {
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its private state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new private state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 3ffacb52299b9..fb16bb05e9f1f 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2544,6 +2544,8 @@ void PruneThreadPlans();
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 

diff  --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index ca473175f18f0..2004b66eafe34 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@ SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) 
{
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 3601173e99cf3..502197d21a939 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -88,6 +88,10 @@ class ScriptedProcess : public Process {
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);



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


[Lldb-commits] [lldb] 3c33d72 - [lldb] Move ScriptedProcess private state update to implementation

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:14:15-08:00
New Revision: 3c33d72e7fa83beb8a9b39fb3b8ecf4ee00c697d

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

LOG: [lldb] Move ScriptedProcess private state update to implementation

While debugging a Scripted Process, in order to update its state and
work nicely with lldb's execution model, it needs to toggle its private
state from running to stopped, which will result in broadcasting a
process state changed event to the debugger listener.

Originally, this state update was done systematically in the Scripted
Process C++ plugin, however in order to make scripted process
interactive, we need to be able to update their state dynamically.

This patch makes use of the recent addition of the
`SBProcess::ForceScriptedState` to programatically, and moves the
process private state update to the python implementation of the `resume`
method instead of doing it in `ScriptedProcess::DoResume`.

This patch also removes the unused `ShouldStop` & `Stop` scripted
process APIs, and adds new ScriptedInterface transform methods for
boolean arguments. This allow the user to programmatically decide if
after running the process, we should stop it (which is the default setting).

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

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

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h

Removed: 




diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index 044aee1338808..8b3c16153e286 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -160,30 +160,24 @@ def attach(self, attach_info):
 """
 return lldb.SBError()
 
-def resume(self):
+def resume(self, should_stop=True):
 """ Simulate the scripted process resume.
 
-Returns:
-lldb.SBError: An `lldb.SBError` with error code 0.
-"""
-return lldb.SBError()
-
-@abstractmethod
-def should_stop(self):
-""" Check if the scripted process plugin should produce the stop event.
-
-Returns:
-bool: True if scripted process should broadcast a stop event.
-  False otherwise.
-"""
-pass
-
-def stop(self):
-""" Trigger the scripted process stop.
+Args:
+should_stop (bool): If True, resume will also 
 
 Returns:
 lldb.SBError: An `lldb.SBError` with error code 0.
 """
+process = self.target.GetProcess()
+if not process:
+error = lldb.SBError()
+error.SetErrorString("Invalid process.")
+return error
+
+process.ForceScriptedState(lldb.eStateRunning);
+if (should_stop):
+process.ForceScriptedState(lldb.eStateStopped);
 return lldb.SBError()
 
 @abstractmethod

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index ba4743077e029..977a8d923c355 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -38,10 +38,6 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 
   virtual Status Resume() { return Status("ScriptedProcess did not resume"); }
 
-  virtual bool ShouldStop() { return true; }
-
-  virtual Status Stop() { return Status("ScriptedProcess did not stop"); }
-
   virtual std::optional
   GetMemoryRegionContainingAddress(lldb::addr_t address, Status &error) {
 error.SetErrorString("ScriptedProcess have no memory region.");

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 948ee691ecbe4..79365f9b69758 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -187,8 +187,6 @@ Status ScriptedProcess::DoResume() {
   if (resume) {
 LLDB_LOGF(log, "ScriptedProcess::%s sending resume", __FUNCTION__);
 
-SetPrivateState(eStateRunning);
-SetPrivateState(eStateStopped);
 

[Lldb-commits] [lldb] cfe06f4 - [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:14:15-08:00
New Revision: cfe06f495beb520ab366957d1108bb80c7c92832

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

LOG: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

This patch adds support for breakpoint setting to Scripted Processes.

For now, Scripted Processes only support setting software breakpoints.

When doing interactive scripted process debugging, it makes use of the
memory writing capability to write the trap opcodes in the memory of the
driving process. However the real process' target doesn't keep track of
the breakpoints that got added by the scripted process. This is a design
that we might need to change in the future, since we'll probably need to
do some book keeping to handle breakpoints that were set by different
scripted processes.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 




diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 79365f9b69758..c5a68271c75f0 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -267,6 +267,20 @@ size_t ScriptedProcess::DoWriteMemory(lldb::addr_t 
vm_addr, const void *buf,
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 728c96a904e4b..73b28a3f39fd0 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -72,6 +72,8 @@ class ScriptedProcess : public Process {
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status



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


[Lldb-commits] [lldb] 70b9822 - [lldb] Add an example of interactive scripted process debugging (NFC)

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:14:15-08:00
New Revision: 70b9822ef3b0774609c72d380504c9abfa717f81

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

LOG: [lldb] Add an example of interactive scripted process debugging (NFC)

This patch is a proof of concept that shows how a scripted process could
be used with real process to perform interactive debugging.

In this example, we run a process that spawns 10 threads. Then, we
create a intermediary scripted process who's job will be to wrap the
real process while intercepting it's process events and dispatching them
back either to the real process or to other child scripted processes.

In this example, we have 2 child scripted processes, with even and odd
thread indices. The goal is to be able to do thread filtering and
explore the various interactive debugging approaches, by letting a child
process running when stopping the other process and inspecting it.
Another approach would be to have the child processes execution in-sync
to force running every child process when one of them starts running.

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/test/API/functionalities/interactive_scripted_process/Makefile

lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
lldb/test/API/functionalities/interactive_scripted_process/main.cpp

Modified: 


Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/Makefile 
b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
new file mode 100644
index 0..f2bee8980e62e
--- /dev/null
+++ b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
@@ -0,0 +1,6 @@
+CXXFLAGS=--std=c++17 -g
+
+all: main
+
+clean:
+   rm -rf main *.dSYM

diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
new file mode 100644
index 0..7d354ea2780e0
--- /dev/null
+++ 
b/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
@@ -0,0 +1,349 @@
+# Usage:
+# ./bin/lldb 
$LLVM/lldb/test/API/functionalities/interactive_scripted_process/main \
+#   -o "br set -p 'Break here'" -o "run" \
+#   -o "command script import
+#   
$LLVM/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py"
 \
+#   -o "br set -p 'also break here'" -o 'continue'
+
+import os,json,struct,signal
+
+from threading import Thread
+from typing import Any, Dict
+
+import lldb
+from lldb.plugins.scripted_process import ScriptedProcess
+from lldb.plugins.scripted_process import ScriptedThread
+
+class PassthruScriptedProcess(ScriptedProcess):
+driving_target = None
+driving_process = None
+
+def __init__(self, exe_ctx: lldb.SBExecutionContext, args : 
lldb.SBStructuredData):
+super().__init__(exe_ctx, args)
+
+self.driving_target = None
+self.driving_process = None
+
+self.driving_target_idx = args.GetValueForKey("driving_target_idx")
+if (self.driving_target_idx and self.driving_target_idx.IsValid()):
+if self.driving_target_idx.GetType() == 
lldb.eStructuredDataTypeInteger:
+idx = self.driving_target_idx.GetIntegerValue(42)
+if self.driving_target_idx.GetType() == 
lldb.eStructuredDataTypeString:
+idx = int(self.driving_target_idx.GetStringValue(100))
+self.driving_target = 
self.target.GetDebugger().GetTargetAtIndex(idx)
+self.driving_process = self.driving_target.GetProcess()
+for driving_thread in self.driving_process:
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(json.dumps({
+"driving_target_idx" : idx,
+"thread_idx" : driving_thread.GetIndexID()
+}))
+
+self.threads[driving_thread.GetThreadID()] = 
PassthruScriptedThread(self, structured_data)
+
+for module in self.driving_target.modules:
+path = module.file.fullpath
+load_addr = 
module.GetObjectFileHeaderAddress().GetLoadAddress(self.driving_target)
+self.loaded_images.append({"path": path, "load_addr": 
load_addr})
+
+def get_memory_region_containing_address(self, addr: int) -> 
lldb.SBMemoryRegionInfo:
+mem_region = lldb.SBMemoryRegionInfo()
+error = self.driving_process.GetMemoryRegionInfo(addr, mem_region)
+if error.Fail():
+return None
+return mem_region
+
+def read_memory_at_address(self, addr: int, size: int, error: 
lldb.SBError) -> lldb.SBData:
+da

[Lldb-commits] [lldb] 601583e - [lldb/Utility] Fix layering violation caused by ScriptedMetadata

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:14:15-08:00
New Revision: 601583e5a3083b87b48bc6747c12dc0027b09481

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

LOG: [lldb/Utility] Fix layering violation caused by ScriptedMetadata

This patch moves `ScriptedMetadata.h` from the `Interpreter` directory to
the `Utility` sub-directory since `ProcessInfo.h` depends on it.

It also gets rid of the unused `OptionGroupPythonClassWithDict`
constructor for `ScriptedMetadata` which would address the layering
violation.

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/include/lldb/Utility/ScriptedMetadata.h

Modified: 
lldb/source/API/SBAttachInfo.cpp
lldb/source/API/SBLaunchInfo.cpp
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Utility/ProcessInfo.cpp

Removed: 
lldb/include/lldb/Interpreter/ScriptedMetadata.h



diff  --git a/lldb/include/lldb/Interpreter/ScriptedMetadata.h 
b/lldb/include/lldb/Utility/ScriptedMetadata.h
similarity index 82%
rename from lldb/include/lldb/Interpreter/ScriptedMetadata.h
rename to lldb/include/lldb/Utility/ScriptedMetadata.h
index a4dfe54b762f4..945e9c4031ad8 100644
--- a/lldb/include/lldb/Interpreter/ScriptedMetadata.h
+++ b/lldb/include/lldb/Utility/ScriptedMetadata.h
@@ -9,8 +9,6 @@
 #ifndef LLDB_INTERPRETER_SCRIPTEDMETADATA_H
 #define LLDB_INTERPRETER_SCRIPTEDMETADATA_H
 
-#include "OptionGroupPythonClassWithDict.h"
-
 #include "lldb/Host/Host.h"
 #include "lldb/Utility/ProcessInfo.h"
 #include "lldb/Utility/StructuredData.h"
@@ -30,12 +28,6 @@ class ScriptedMetadata {
 }
   }
 
-  ScriptedMetadata(const OptionGroupPythonClassWithDict &option_group) {
-auto opt_group = const_cast(option_group);
-m_class_name = opt_group.GetName();
-m_args_sp = opt_group.GetStructuredData();
-  }
-
   explicit operator bool() const { return !m_class_name.empty(); }
 
   llvm::StringRef GetClassName() const { return m_class_name; }

diff  --git a/lldb/source/API/SBAttachInfo.cpp 
b/lldb/source/API/SBAttachInfo.cpp
index ffc61b5860d05..0d2dacbf9c78c 100644
--- a/lldb/source/API/SBAttachInfo.cpp
+++ b/lldb/source/API/SBAttachInfo.cpp
@@ -11,9 +11,9 @@
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBStructuredData.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 
 using namespace lldb;
 using namespace lldb_private;

diff  --git a/lldb/source/API/SBLaunchInfo.cpp 
b/lldb/source/API/SBLaunchInfo.cpp
index 5800ac63dddb6..21ae84b4e3cc4 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -17,7 +17,7 @@
 #include "lldb/API/SBStructuredData.h"
 #include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/Host/ProcessLaunchInfo.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 
 using namespace lldb;
 using namespace lldb_private;

diff  --git a/lldb/source/Commands/CommandObjectPlatform.cpp 
b/lldb/source/Commands/CommandObjectPlatform.cpp
index 213631a250bd7..60d37121844b4 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -20,11 +20,11 @@
 #include "lldb/Interpreter/OptionGroupFile.h"
 #include "lldb/Interpreter/OptionGroupPlatform.h"
 #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 
 #include "llvm/ADT/SmallString.h"
 

diff  --git a/lldb/source/Commands/CommandObjectProcess.cpp 
b/lldb/source/Commands/CommandObjectProcess.cpp
index 4362b25f9663c..5b578454f1ad6 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -25,7 +25,6 @@
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
 #include "lldb/Interpreter/Options.h"
-#include "lldb/Interpreter/ScriptedMetadata.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
@@ -33,6 +32,7 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ScriptedMetadata.h"
 #include "lldb/Utility/State.h"
 
 #include "llvm/ADT/ScopeExit.h"

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scrip

[Lldb-commits] [PATCH] D145294: [lldb/API] Introduce SBProcess::ForceScriptedState method

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3675e0bb67fa: [lldb/API] Introduce 
SBProcess::ForceScriptedState method (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145294

Files:
  lldb/include/lldb/API/SBProcess.h
  lldb/include/lldb/Target/Process.h
  lldb/source/API/SBProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -88,6 +88,10 @@
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2544,6 +2544,8 @@
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 
Index: lldb/include/lldb/API/SBProcess.h
===
--- lldb/include/lldb/API/SBProcess.h
+++ lldb/include/lldb/API/SBProcess.h
@@ -187,6 +187,14 @@
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its private state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new private state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -88,6 +88,10 @@
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2544,6 +2544,8 @@
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 
Index: lldb/include/lldb/API/SBProcess.h
===
--- lldb/include/lldb/API/SBProcess.h
+++ lldb/include/lldb/API/SBProcess.h
@@ -187,6 +187,14 @@
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its private state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new private state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t Writ

[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3c33d72e7fa8: [lldb] Move ScriptedProcess private state 
update to implementation (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -113,6 +113,11 @@
 return {object};
   }
 
+  python::PythonObject Transform(bool arg) {
+// Boolean arguments need to be turned into python objects.
+return python::PythonBoolean(arg);
+  }
+
   python::PythonObject Transform(Status arg) {
 return python::ToSWIGWrapper(arg);
   }
@@ -141,6 +146,15 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
+  template <>
+  void ReverseTransform(bool &original_arg,
+python::PythonObject transformed_arg, Status &error) {
+python::PythonBoolean boolean_arg = python::PythonBoolean(
+python::PyRefType::Borrowed, transformed_arg.get());
+if (boolean_arg.IsValid())
+  original_arg = boolean_arg.GetValue();
+  }
+
   template 
   auto TransformTuple(const std::tuple &args,
   std::index_sequence) {
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -37,10 +37,6 @@
 
   Status Resume() override;
 
-  bool ShouldStop() override;
-
-  Status Stop() override;
-
   std::optional
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -80,21 +80,8 @@
 }
 
 Status ScriptedProcessPythonInterface::Resume() {
-  return GetStatusFromMethod("resume");
-}
-
-bool ScriptedProcessPythonInterface::ShouldStop() {
-  Status error;
-  StructuredData::ObjectSP obj = Dispatch("is_alive", error);
-
-  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
-return {};
-
-  return obj->GetBooleanValue();
-}
-
-Status ScriptedProcessPythonInterface::Stop() {
-  return GetStatusFromMethod("stop");
+  // When calling ScriptedProcess.Resume from lldb we should always stop.
+  return GetStatusFromMethod("resume", /*should_stop=*/true);
 }
 
 std::optional
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -201,6 +201,7 @@
 template <>
 struct PythonFormat : PassthroughFormat {};
 template <> struct PythonFormat : PassthroughFormat {};
+template <> struct PythonFormat : PassthroughFormat {};
 template <>
 struct PythonFormat : PassthroughFormat {};
 template <> struct PythonFormat : PassthroughFormat {};
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -96,8 +96,6 @@
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
 
-  Status DoStop();
-
   void Clear();
 
   bool DoUpdateThreadList(ThreadList &old_thread_list,
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -

[Lldb-commits] [PATCH] D145296: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfe06f495beb: [lldb/Plugin] Add breakpoint setting support 
to ScriptedProcesses. (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145296

Files:
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -72,6 +72,8 @@
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -267,6 +267,20 @@
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -72,6 +72,8 @@
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -267,6 +267,20 @@
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 480eb74 - Revert "[lldb/API] Introduce SBProcess::ForceScriptedState method"

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:17:40-08:00
New Revision: 480eb744982f2cecd9aa75ef32910fe023d8d4dc

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

LOG: Revert "[lldb/API] Introduce SBProcess::ForceScriptedState method"

This reverts commit 3675e0bb67fa86b8476a67bb1a7623a6b1a373b3.

Added: 


Modified: 
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 




diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 4b87d4afa310c..be0048763a25d 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -187,14 +187,6 @@ class LLDB_API SBProcess {
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
-  /// If the process is a scripted process, changes its private state.
-  /// No-op otherwise.
-  ///
-  /// \param [in] new_state
-  ///   The new private state that the scripted process should be set to.
-  ///
-  void ForceScriptedState(StateType new_state);
-
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index fb16bb05e9f1f..3ffacb52299b9 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2544,8 +2544,6 @@ void PruneThreadPlans();
 
   virtual void *GetImplementation() { return nullptr; }
 
-  virtual void ForceScriptedState(lldb::StateType state) {}
-
 protected:
   friend class Trace;
 

diff  --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 2004b66eafe34..ca473175f18f0 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -466,16 +466,6 @@ SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) 
{
   return sb_event;
 }
 
-void SBProcess::ForceScriptedState(StateType new_state) {
-  LLDB_INSTRUMENT_VA(this, new_state);
-
-  if (ProcessSP process_sp = GetSP()) {
-std::lock_guard guard(
-process_sp->GetTarget().GetAPIMutex());
-process_sp->ForceScriptedState(new_state);
-  }
-}
-
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index fd8e3132b620a..d72c19a19720f 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -90,10 +90,6 @@ class ScriptedProcess : public Process {
 
   void *GetImplementation() override;
 
-  void ForceScriptedState(lldb::StateType state) override {
-SetPrivateState(state);
-  }
-
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);



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


[Lldb-commits] [lldb] 20dbb29 - Revert "[lldb] Move ScriptedProcess private state update to implementation"

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:17:43-08:00
New Revision: 20dbb29a1a94c60b556f8880ab841b150e83ab25

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

LOG: Revert "[lldb] Move ScriptedProcess private state update to implementation"

This reverts commit 3c33d72e7fa83beb8a9b39fb3b8ecf4ee00c697d.

Added: 


Modified: 
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

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

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h

Removed: 




diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index 8b3c16153e286..044aee1338808 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -160,24 +160,30 @@ def attach(self, attach_info):
 """
 return lldb.SBError()
 
-def resume(self, should_stop=True):
+def resume(self):
 """ Simulate the scripted process resume.
 
-Args:
-should_stop (bool): If True, resume will also 
+Returns:
+lldb.SBError: An `lldb.SBError` with error code 0.
+"""
+return lldb.SBError()
+
+@abstractmethod
+def should_stop(self):
+""" Check if the scripted process plugin should produce the stop event.
+
+Returns:
+bool: True if scripted process should broadcast a stop event.
+  False otherwise.
+"""
+pass
+
+def stop(self):
+""" Trigger the scripted process stop.
 
 Returns:
 lldb.SBError: An `lldb.SBError` with error code 0.
 """
-process = self.target.GetProcess()
-if not process:
-error = lldb.SBError()
-error.SetErrorString("Invalid process.")
-return error
-
-process.ForceScriptedState(lldb.eStateRunning);
-if (should_stop):
-process.ForceScriptedState(lldb.eStateStopped);
 return lldb.SBError()
 
 @abstractmethod

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index 977a8d923c355..ba4743077e029 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -38,6 +38,10 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 
   virtual Status Resume() { return Status("ScriptedProcess did not resume"); }
 
+  virtual bool ShouldStop() { return true; }
+
+  virtual Status Stop() { return Status("ScriptedProcess did not stop"); }
+
   virtual std::optional
   GetMemoryRegionContainingAddress(lldb::addr_t address, Status &error) {
 error.SetErrorString("ScriptedProcess have no memory region.");

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index e26d5f3a2d7cf..4fd7a46804de6 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -187,6 +187,8 @@ Status ScriptedProcess::DoResume() {
   if (resume) {
 LLDB_LOGF(log, "ScriptedProcess::%s sending resume", __FUNCTION__);
 
+SetPrivateState(eStateRunning);
+SetPrivateState(eStateStopped);
 error = GetInterface().Resume();
   }
 
@@ -221,6 +223,19 @@ void ScriptedProcess::DidAttach(ArchSpec &process_arch) {
   process_arch = GetArchitecture();
 }
 
+Status ScriptedProcess::DoStop() {
+  Log *log = GetLog(LLDBLog::Process);
+
+  if (GetInterface().ShouldStop()) {
+SetPrivateState(eStateStopped);
+LLDB_LOGF(log, "ScriptedProcess::%s Immediate stop", __FUNCTION__);
+return {};
+  }
+
+  LLDB_LOGF(log, "ScriptedProcess::%s Delayed stop", __FUNCTION__);
+  return GetInterface().Stop();
+}
+
 Status ScriptedProcess::DoDestroy() { return Status(); }
 
 bool ScriptedProcess::IsAlive() { return GetInterface().IsAlive(); }

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index d72c19a19720f..44a514a096d3a 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -94,6 +94,8 @@ class ScriptedProcess : public Process {
   ScriptedPr

[Lldb-commits] [lldb] f9a663f - Revert "[lldb] Add an example of interactive scripted process debugging (NFC)"

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:17:46-08:00
New Revision: f9a663f9692f5e5342be0cbb27abc74cdf417434

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

LOG: Revert "[lldb] Add an example of interactive scripted process debugging 
(NFC)"

This reverts commit 70b9822ef3b0774609c72d380504c9abfa717f81.

Added: 


Modified: 


Removed: 
lldb/test/API/functionalities/interactive_scripted_process/Makefile

lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
lldb/test/API/functionalities/interactive_scripted_process/main.cpp



diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/Makefile 
b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
deleted file mode 100644
index f2bee8980e62e..0
--- a/lldb/test/API/functionalities/interactive_scripted_process/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-CXXFLAGS=--std=c++17 -g
-
-all: main
-
-clean:
-   rm -rf main *.dSYM

diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
deleted file mode 100644
index 7d354ea2780e0..0
--- 
a/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
+++ /dev/null
@@ -1,349 +0,0 @@
-# Usage:
-# ./bin/lldb 
$LLVM/lldb/test/API/functionalities/interactive_scripted_process/main \
-#   -o "br set -p 'Break here'" -o "run" \
-#   -o "command script import
-#   
$LLVM/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py"
 \
-#   -o "br set -p 'also break here'" -o 'continue'
-
-import os,json,struct,signal
-
-from threading import Thread
-from typing import Any, Dict
-
-import lldb
-from lldb.plugins.scripted_process import ScriptedProcess
-from lldb.plugins.scripted_process import ScriptedThread
-
-class PassthruScriptedProcess(ScriptedProcess):
-driving_target = None
-driving_process = None
-
-def __init__(self, exe_ctx: lldb.SBExecutionContext, args : 
lldb.SBStructuredData):
-super().__init__(exe_ctx, args)
-
-self.driving_target = None
-self.driving_process = None
-
-self.driving_target_idx = args.GetValueForKey("driving_target_idx")
-if (self.driving_target_idx and self.driving_target_idx.IsValid()):
-if self.driving_target_idx.GetType() == 
lldb.eStructuredDataTypeInteger:
-idx = self.driving_target_idx.GetIntegerValue(42)
-if self.driving_target_idx.GetType() == 
lldb.eStructuredDataTypeString:
-idx = int(self.driving_target_idx.GetStringValue(100))
-self.driving_target = 
self.target.GetDebugger().GetTargetAtIndex(idx)
-self.driving_process = self.driving_target.GetProcess()
-for driving_thread in self.driving_process:
-structured_data = lldb.SBStructuredData()
-structured_data.SetFromJSON(json.dumps({
-"driving_target_idx" : idx,
-"thread_idx" : driving_thread.GetIndexID()
-}))
-
-self.threads[driving_thread.GetThreadID()] = 
PassthruScriptedThread(self, structured_data)
-
-for module in self.driving_target.modules:
-path = module.file.fullpath
-load_addr = 
module.GetObjectFileHeaderAddress().GetLoadAddress(self.driving_target)
-self.loaded_images.append({"path": path, "load_addr": 
load_addr})
-
-def get_memory_region_containing_address(self, addr: int) -> 
lldb.SBMemoryRegionInfo:
-mem_region = lldb.SBMemoryRegionInfo()
-error = self.driving_process.GetMemoryRegionInfo(addr, mem_region)
-if error.Fail():
-return None
-return mem_region
-
-def read_memory_at_address(self, addr: int, size: int, error: 
lldb.SBError) -> lldb.SBData:
-data = lldb.SBData()
-bytes_read = self.driving_process.ReadMemory(addr, size, error)
-
-if error.Fail():
-return data
-
-data.SetDataWithOwnership(error, bytes_read,
-  self.driving_target.GetByteOrder(),
-  self.driving_target.GetAddressByteSize())
-
-return data
-
-def write_memory_at_address(self, addr, data, error):
-return self.driving_process.WriteMemory(addr,
-bytearray(data.uint8.all()),
-error)
-
-def get_loaded_images(self):
-return self.loaded_images
-
-def get_process_id(self) -> int:
-return 42
-
-def is_alive(self) -> bool:
- 

[Lldb-commits] [lldb] 896a346 - Revert "[lldb/Plugin] Add breakpoint setting support to ScriptedProcesses."

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T13:17:45-08:00
New Revision: 896a3469802122a37bba04bfebf2ab302c84cc87

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

LOG: Revert "[lldb/Plugin] Add breakpoint setting support to ScriptedProcesses."

This reverts commit cfe06f495beb520ab366957d1108bb80c7c92832.

Added: 


Modified: 
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 




diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 4fd7a46804de..9a670276a8b8 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -282,20 +282,6 @@ size_t ScriptedProcess::DoWriteMemory(lldb::addr_t 
vm_addr, const void *buf,
   return bytes_written;
 }
 
-Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
-  assert(bp_site != nullptr);
-
-  if (bp_site->IsEnabled()) {
-return {};
-  }
-
-  if (bp_site->HardwareRequired()) {
-return Status("Scripted Processes don't support hardware breakpoints");
-  }
-
-  return EnableSoftwareBreakpoint(bp_site);
-}
-
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 44a514a096d3..368c54b1b461 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -72,8 +72,6 @@ class ScriptedProcess : public Process {
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
-  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
-
   ArchSpec GetArchitecture();
 
   Status



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


[Lldb-commits] [PATCH] D145414: [lldb/Utility] Fix layering violation caused by ScriptedMetadata

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib closed this revision.
mib added a comment.

Landed in 601583e5a3083b87b48bc6747c12dc0027b09481 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145414

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


[Lldb-commits] [lldb] 9f8c974 - [lldb] Fix cyclic dependency issue in ScriptedMetadata

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T14:00:06-08:00
New Revision: 9f8c974f792d9d29387858842f05b86e92b0636c

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

LOG: [lldb] Fix cyclic dependency issue in ScriptedMetadata

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Utility/ScriptedMetadata.h

Removed: 




diff  --git a/lldb/include/lldb/Utility/ScriptedMetadata.h 
b/lldb/include/lldb/Utility/ScriptedMetadata.h
index 945e9c4031ad..69c83edce909 100644
--- a/lldb/include/lldb/Utility/ScriptedMetadata.h
+++ b/lldb/include/lldb/Utility/ScriptedMetadata.h
@@ -9,7 +9,6 @@
 #ifndef LLDB_INTERPRETER_SCRIPTEDMETADATA_H
 #define LLDB_INTERPRETER_SCRIPTEDMETADATA_H
 
-#include "lldb/Host/Host.h"
 #include "lldb/Utility/ProcessInfo.h"
 #include "lldb/Utility/StructuredData.h"
 



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


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

If these files can be used as the only source of information (without a 
stripped executable), we really should include a serialized SectionList in the 
JSON that can be loaded into ObjectFileJSON. This would be very useful for 
easily creating unit tests.




Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

Do we something that says "value is an address"? Or are we inferring that from 
the lldb::SymbolType?



Comment at: lldb/test/API/macosx/symbols/TestSymbolFileJSON.py:39
+"size": main_symbol.GetSize(),
+"value": main_symbol.addr.GetFileAddress(),
+})

we probably should test that the "id" and "section_id" fields work correctly. 
We should also test that we are able to make symbols with only an address and 
name, then add tests for symbols that each add a new optional value that can be 
specified to ensure we can correctly make symbols. 


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

https://reviews.llvm.org/D145180

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


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/include/lldb/Symbol/Symbol.h:351-356
+bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
+  llvm::json::Path path);
+
+bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
+  llvm::json::Path path);
+

Do we want to stick with JSONSymbol or just teach lldb_private::Symbol to 
serialize and deserialize from JSON? If we so the latter, we can create any 
type of symbol we need and it would be useful for easily making unit tests that 
could use ObjectFileJSON as the basis. 


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

https://reviews.llvm.org/D145180

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


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked 3 inline comments as done.
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

clayborg wrote:
> Do we something that says "value is an address"? Or are we inferring that 
> from the lldb::SymbolType?
In the Symbolc constructor that takes a JSONSymbol, I assume the value is an 
address if there's no section_id and an offset otherwise. We can definitely 
tweak that or add a sanity check based on the symbol type. 



Comment at: lldb/include/lldb/Symbol/Symbol.h:351-356
+bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
+  llvm::json::Path path);
+
+bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
+  llvm::json::Path path);
+

clayborg wrote:
> Do we want to stick with JSONSymbol or just teach lldb_private::Symbol to 
> serialize and deserialize from JSON? If we so the latter, we can create any 
> type of symbol we need and it would be useful for easily making unit tests 
> that could use ObjectFileJSON as the basis. 
I think we really want the `JSONSymbol` class. That also matches what we do for 
the tracing objects as well, where there's a JSON object and a "real" object. 
For the crashlog use case where I don't have sections in the JSON, I want to be 
able to reuse the existing section list from the module so I need a way to pass 
that in. To (de)serialize the Symbol object directly, we'd need a way to pass 
that in, which I don't think exists today. 



Comment at: lldb/test/API/macosx/symbols/TestSymbolFileJSON.py:39
+"size": main_symbol.GetSize(),
+"value": main_symbol.addr.GetFileAddress(),
+})

clayborg wrote:
> we probably should test that the "id" and "section_id" fields work correctly. 
> We should also test that we are able to make symbols with only an address and 
> name, then add tests for symbols that each add a new optional value that can 
> be specified to ensure we can correctly make symbols. 
Yep, I saw that working manually but I can extend the test case to include 
that. 


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

https://reviews.llvm.org/D145180

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


[Lldb-commits] [lldb] 7975e3b - Revert "[lldb] Redefine p alias to dwim-print command"

2023-03-06 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-03-06T15:05:15-08:00
New Revision: 7975e3b1255d8506b7a4c9a33ab91c39291996ba

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

LOG: Revert "[lldb] Redefine p alias to dwim-print command"

This reverts commit a00801d94b02eaebd1385b03fb9e549c07cc8585.

Broke TestVSCode_completions.py

Added: 


Modified: 
lldb/source/Interpreter/CommandInterpreter.cpp

Removed: 




diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index c03806d94210..1437ca464e76 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -413,21 +413,17 @@ void CommandInterpreter::Initialize() {
 
   alias_arguments_vector_sp = std::make_shared();
 
-  cmd_obj_sp = GetCommandSPExact("dwim-print");
+  cmd_obj_sp = GetCommandSPExact("expression");
   if (cmd_obj_sp) {
 AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
 AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
+AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
   po->SetHelp("Evaluate an expression on the current thread.  Displays any 
"
   "returned value with formatting "
   "controlled by the type's author.");
   po->SetHelpLong("");
 }
-  }
-
-  cmd_obj_sp = GetCommandSPExact("expression");
-  if (cmd_obj_sp) {
-AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
 CommandAlias *parray_alias =
 AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
 if (parray_alias) {



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


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

JDevlieghere wrote:
> clayborg wrote:
> > Do we something that says "value is an address"? Or are we inferring that 
> > from the lldb::SymbolType?
> In the Symbolc constructor that takes a JSONSymbol, I assume the value is an 
> address if there's no section_id and an offset otherwise. We can definitely 
> tweak that or add a sanity check based on the symbol type. 
Remember there are some symbols that are not addresses. Think of trying to 
create a N_OSO symbol where the value isn't an address, but it is a time stamp 
integer. 

Symbols in the symbol table for mach-o files can have a section ID that is 
valid and the value is not an offset, it is still an address. Not sure if that 
matters. 

One way to make this clear is if we have a "section_id" then "value" is an 
address, and if not, then "value" is just an integer? It does require that we 
always specify section IDs though. Also, section IDs are not human readable, we 
could change "std::optional section_id;" to be 
"std::optional section;" and thid becomes the fully qualified 
section name like "__TEXT.__text" or "PT_LOAD[0]..text". Much more readable. 
And easy to dig up the section from the Module's section list.



Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

clayborg wrote:
> JDevlieghere wrote:
> > clayborg wrote:
> > > Do we something that says "value is an address"? Or are we inferring that 
> > > from the lldb::SymbolType?
> > In the Symbolc constructor that takes a JSONSymbol, I assume the value is 
> > an address if there's no section_id and an offset otherwise. We can 
> > definitely tweak that or add a sanity check based on the symbol type. 
> Remember there are some symbols that are not addresses. Think of trying to 
> create a N_OSO symbol where the value isn't an address, but it is a time 
> stamp integer. 
> 
> Symbols in the symbol table for mach-o files can have a section ID that is 
> valid and the value is not an offset, it is still an address. Not sure if 
> that matters. 
> 
> One way to make this clear is if we have a "section_id" then "value" is an 
> address, and if not, then "value" is just an integer? It does require that we 
> always specify section IDs though. Also, section IDs are not human readable, 
> we could change "std::optional section_id;" to be 
> "std::optional section;" and thid becomes the fully qualified 
> section name like "__TEXT.__text" or "PT_LOAD[0]..text". Much more readable. 
> And easy to dig up the section from the Module's section list.
Another way to do this would be to have JSONSymbol know if it has an address or 
just an integer value by defining this as:
```
std::optional address;
std::optional value;
```
The deserializer would verify that only one of these is valid and fail if both 
or neither were specified



Comment at: lldb/include/lldb/Symbol/Symbol.h:351-356
+bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
+  llvm::json::Path path);
+
+bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
+  llvm::json::Path path);
+

JDevlieghere wrote:
> clayborg wrote:
> > Do we want to stick with JSONSymbol or just teach lldb_private::Symbol to 
> > serialize and deserialize from JSON? If we so the latter, we can create any 
> > type of symbol we need and it would be useful for easily making unit tests 
> > that could use ObjectFileJSON as the basis. 
> I think we really want the `JSONSymbol` class. That also matches what we do 
> for the tracing objects as well, where there's a JSON object and a "real" 
> object. For the crashlog use case where I don't have sections in the JSON, I 
> want to be able to reuse the existing section list from the module so I need 
> a way to pass that in. To (de)serialize the Symbol object directly, we'd need 
> a way to pass that in, which I don't think exists today. 
Any ObjectFile can always get the section list from the Module, so if there is 
no serialized section list, ObjectFileJSON doesn't need to provide any 
sections, and it can just call:
```
SectionList *sections = GetModule()->GetSectionList();
```
Any object files within a module are asked to add their own sections if they 
have any extra sections. We do this with dSYM files where we add the __DWARF 
segment to the Module's main section list. So the executable adds "__PAGEZERO, 
__TEXT, DATA_, etc", then the dSYM object file just adds any extra sections it 
need with a call to:
```
void ObjectFile::CreateSections(SectionList &unified_section_list);
```
So if we have a section list already in ObjectFileJSON, we need to verify that 
they all match with any pre-existing sections that are already in the 
SectionList, and can add any

[Lldb-commits] [PATCH] D145437: [lldb-vscode] Use `expression` command for completion

2023-03-06 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added a reviewer: aprantl.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Change lldb-vscode to use the `expression` command for generating completions, 
instead
of the `p` alias.

Aliases are user overrideable, and even deletable, but the `expression` command 
is
unchangeable.

See D141539  where a similar replacement was 
done to tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145437

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1065,7 +1065,7 @@
 text = text.substr(1);
 actual_column--;
   } else {
-text = "p " + text;
+text = "expression -- " + text;
 actual_column += 2;
   }
   lldb::SBStringList matches;


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1065,7 +1065,7 @@
 text = text.substr(1);
 actual_column--;
   } else {
-text = "p " + text;
+text = "expression -- " + text;
 actual_column += 2;
   }
   lldb::SBStringList matches;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked 3 inline comments as done.
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

clayborg wrote:
> clayborg wrote:
> > JDevlieghere wrote:
> > > clayborg wrote:
> > > > Do we something that says "value is an address"? Or are we inferring 
> > > > that from the lldb::SymbolType?
> > > In the Symbolc constructor that takes a JSONSymbol, I assume the value is 
> > > an address if there's no section_id and an offset otherwise. We can 
> > > definitely tweak that or add a sanity check based on the symbol type. 
> > Remember there are some symbols that are not addresses. Think of trying to 
> > create a N_OSO symbol where the value isn't an address, but it is a time 
> > stamp integer. 
> > 
> > Symbols in the symbol table for mach-o files can have a section ID that is 
> > valid and the value is not an offset, it is still an address. Not sure if 
> > that matters. 
> > 
> > One way to make this clear is if we have a "section_id" then "value" is an 
> > address, and if not, then "value" is just an integer? It does require that 
> > we always specify section IDs though. Also, section IDs are not human 
> > readable, we could change "std::optional section_id;" to be 
> > "std::optional section;" and thid becomes the fully qualified 
> > section name like "__TEXT.__text" or "PT_LOAD[0]..text". Much more 
> > readable. And easy to dig up the section from the Module's section list.
> Another way to do this would be to have JSONSymbol know if it has an address 
> or just an integer value by defining this as:
> ```
> std::optional address;
> std::optional value;
> ```
> The deserializer would verify that only one of these is valid and fail if 
> both or neither were specified
Sure, that sounds reasonable. 



Comment at: lldb/include/lldb/Symbol/Symbol.h:351-356
+bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
+  llvm::json::Path path);
+
+bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
+  llvm::json::Path path);
+

clayborg wrote:
> JDevlieghere wrote:
> > clayborg wrote:
> > > Do we want to stick with JSONSymbol or just teach lldb_private::Symbol to 
> > > serialize and deserialize from JSON? If we so the latter, we can create 
> > > any type of symbol we need and it would be useful for easily making unit 
> > > tests that could use ObjectFileJSON as the basis. 
> > I think we really want the `JSONSymbol` class. That also matches what we do 
> > for the tracing objects as well, where there's a JSON object and a "real" 
> > object. For the crashlog use case where I don't have sections in the JSON, 
> > I want to be able to reuse the existing section list from the module so I 
> > need a way to pass that in. To (de)serialize the Symbol object directly, 
> > we'd need a way to pass that in, which I don't think exists today. 
> Any ObjectFile can always get the section list from the Module, so if there 
> is no serialized section list, ObjectFileJSON doesn't need to provide any 
> sections, and it can just call:
> ```
> SectionList *sections = GetModule()->GetSectionList();
> ```
> Any object files within a module are asked to add their own sections if they 
> have any extra sections. We do this with dSYM files where we add the __DWARF 
> segment to the Module's main section list. So the executable adds 
> "__PAGEZERO, __TEXT, DATA_, etc", then the dSYM object file just adds any 
> extra sections it need with a call to:
> ```
> void ObjectFile::CreateSections(SectionList &unified_section_list);
> ```
> So if we have a section list already in ObjectFileJSON, we need to verify 
> that they all match with any pre-existing sections that are already in the 
> SectionList, and can add any extra sections if needed. If the ObjectFileJSON 
> was the only object file, it could fully populate a Module's section list on 
> its own.
I'm aware the data is present but I don't see how to pass that into the JSON 
deserialization function if we don't go through an intermediary object. As far 
as I can tell, there's no way to pass this additional data into `fromJSON`. 
That's why I have a ctor (`Symbol(const JSONSymbol &symbol, SectionList 
*section_list);`) that takes both the deserialized symbol and the section list. 
If there's a way to do that I'm happy to scrap the `JSONSymbol`. 


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

https://reviews.llvm.org/D145180

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


[Lldb-commits] [PATCH] D145294: [lldb/API] Introduce SBProcess::ForceScriptedState method

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib reopened this revision.
mib added a comment.

I landed this by mistake ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145294

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


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/include/lldb/Symbol/Symbol.h:23
+struct JSONSymbol {
+  uint64_t value;
+  std::optional size;

JDevlieghere wrote:
> clayborg wrote:
> > clayborg wrote:
> > > JDevlieghere wrote:
> > > > clayborg wrote:
> > > > > Do we something that says "value is an address"? Or are we inferring 
> > > > > that from the lldb::SymbolType?
> > > > In the Symbolc constructor that takes a JSONSymbol, I assume the value 
> > > > is an address if there's no section_id and an offset otherwise. We can 
> > > > definitely tweak that or add a sanity check based on the symbol type. 
> > > Remember there are some symbols that are not addresses. Think of trying 
> > > to create a N_OSO symbol where the value isn't an address, but it is a 
> > > time stamp integer. 
> > > 
> > > Symbols in the symbol table for mach-o files can have a section ID that 
> > > is valid and the value is not an offset, it is still an address. Not sure 
> > > if that matters. 
> > > 
> > > One way to make this clear is if we have a "section_id" then "value" is 
> > > an address, and if not, then "value" is just an integer? It does require 
> > > that we always specify section IDs though. Also, section IDs are not 
> > > human readable, we could change "std::optional section_id;" to 
> > > be "std::optional section;" and thid becomes the fully 
> > > qualified section name like "__TEXT.__text" or "PT_LOAD[0]..text". Much 
> > > more readable. And easy to dig up the section from the Module's section 
> > > list.
> > Another way to do this would be to have JSONSymbol know if it has an 
> > address or just an integer value by defining this as:
> > ```
> > std::optional address;
> > std::optional value;
> > ```
> > The deserializer would verify that only one of these is valid and fail if 
> > both or neither were specified
> Sure, that sounds reasonable. 
And we can add tests that verify we get an error back if neither or both are 
specified.


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

https://reviews.llvm.org/D145180

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


[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib reopened this revision.
mib added a comment.

Landed this by mistake, please take another look


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

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


[Lldb-commits] [PATCH] D145296: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib reopened this revision.
mib added a comment.

I've landed this by mistake, please take another look


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145296

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


[Lldb-commits] [PATCH] D145446: Fix LLDB windows build

2023-03-06 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid created this revision.
omjavaid added a reviewer: mib.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
omjavaid requested review of this revision.

LLDB WoA buildbot is failing due to pid_t redefinition after recent changes in 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp.
Process.h includes PosixApi.h which defines pid_t. Python.h on windows also 
typedefs
pid_t. To make sure that we include Python.h before PosixApi this patch 
renforces 
the workaround previously set up to guard this issue.

https://lab.llvm.org/buildbot/#/builders/219


https://reviews.llvm.org/D145446

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


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,6 +7,10 @@
 
//===--===//
 
 #include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
@@ -14,9 +18,6 @@
 
 #if LLDB_ENABLE_PYTHON
 
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
 #include "SWIGPythonBridge.h"
 #include "ScriptInterpreterPythonImpl.h"
 #include "ScriptedProcessPythonInterface.h"


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,6 +7,10 @@
 //===--===//
 
 #include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
@@ -14,9 +18,6 @@
 
 #if LLDB_ENABLE_PYTHON
 
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
 #include "SWIGPythonBridge.h"
 #include "ScriptInterpreterPythonImpl.h"
 #include "ScriptedProcessPythonInterface.h"
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145450: [lldb] Respect empty arguments in target.run-args

2023-03-06 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, clayborg, jingham, mib, jasonmolenda.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Currently empty arguments are not respected. They are silently dropped
in two places: (1) when extracting them from the target.run-args
setting and (2) when constructing the lldb-argdumper invocation.

(1) is actually a regression from a few years ago. We did not always
drop empty arguments. See 31d97a5c8ab78c619deada0cdb1fcf64021d25dd.

rdar://106279228


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145450

Files:
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Interpreter/OptionValueArgs.cpp
  lldb/test/Shell/Driver/Inputs/dumpargs.c
  lldb/test/Shell/Driver/TestEmptyArgument.test


Index: lldb/test/Shell/Driver/TestEmptyArgument.test
===
--- /dev/null
+++ lldb/test/Shell/Driver/TestEmptyArgument.test
@@ -0,0 +1,7 @@
+# RUN: %clang_host %S/Inputs/dumpargs.c -o %t.out
+# RUN: %lldb -b -o "r" %t.out -- "one" "two" "" "three" | FileCheck %s
+
+# CHECK: argv[1] = "one"
+# CHECK: argv[2] = "two"
+# CHECK: argv[3] = ""
+# CHECK: argv[4] = "three"
Index: lldb/test/Shell/Driver/Inputs/dumpargs.c
===
--- /dev/null
+++ lldb/test/Shell/Driver/Inputs/dumpargs.c
@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char *argv[]) {
+  for (int i = 0; i < argc; i++) {
+printf("argv[%d] = \"%s\"\n", i, argv[i]);
+  }
+  return 0;
+}
Index: lldb/source/Interpreter/OptionValueArgs.cpp
===
--- lldb/source/Interpreter/OptionValueArgs.cpp
+++ lldb/source/Interpreter/OptionValueArgs.cpp
@@ -17,8 +17,7 @@
   args.Clear();
   for (const auto &value : m_values) {
 llvm::StringRef string_value = value->GetStringValue();
-if (!string_value.empty())
-  args.AppendArgument(string_value);
+args.AppendArgument(string_value);
   }
 
   return args.GetArgumentCount();
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -321,6 +321,8 @@
   } else {
 for (size_t i = 0; argv[i] != nullptr; ++i) {
   std::string safe_arg = Args::GetShellSafeArgument(m_shell, argv[i]);
+  if (safe_arg.empty())
+safe_arg = "\"\"";
   // Add a space to separate this arg from the previous one.
   shell_command.PutCString(" ");
   shell_command.PutCString(safe_arg);


Index: lldb/test/Shell/Driver/TestEmptyArgument.test
===
--- /dev/null
+++ lldb/test/Shell/Driver/TestEmptyArgument.test
@@ -0,0 +1,7 @@
+# RUN: %clang_host %S/Inputs/dumpargs.c -o %t.out
+# RUN: %lldb -b -o "r" %t.out -- "one" "two" "" "three" | FileCheck %s
+
+# CHECK: argv[1] = "one"
+# CHECK: argv[2] = "two"
+# CHECK: argv[3] = ""
+# CHECK: argv[4] = "three"
Index: lldb/test/Shell/Driver/Inputs/dumpargs.c
===
--- /dev/null
+++ lldb/test/Shell/Driver/Inputs/dumpargs.c
@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char *argv[]) {
+  for (int i = 0; i < argc; i++) {
+printf("argv[%d] = \"%s\"\n", i, argv[i]);
+  }
+  return 0;
+}
Index: lldb/source/Interpreter/OptionValueArgs.cpp
===
--- lldb/source/Interpreter/OptionValueArgs.cpp
+++ lldb/source/Interpreter/OptionValueArgs.cpp
@@ -17,8 +17,7 @@
   args.Clear();
   for (const auto &value : m_values) {
 llvm::StringRef string_value = value->GetStringValue();
-if (!string_value.empty())
-  args.AppendArgument(string_value);
+args.AppendArgument(string_value);
   }
 
   return args.GetArgumentCount();
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -321,6 +321,8 @@
   } else {
 for (size_t i = 0; argv[i] != nullptr; ++i) {
   std::string safe_arg = Args::GetShellSafeArgument(m_shell, argv[i]);
+  if (safe_arg.empty())
+safe_arg = "\"\"";
   // Add a space to separate this arg from the previous one.
   shell_command.PutCString(" ");
   shell_command.PutCString(safe_arg);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145180: [lldb] Introduce new SymbolFileJSON and ObjectFileJSON

2023-03-06 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 502854.
JDevlieghere added a comment.

Implement Greg's features. I'll add a unit test for the deserialization later 
today.


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

https://reviews.llvm.org/D145180

Files:
  lldb/include/lldb/Symbol/Symbol.h
  lldb/source/Plugins/ObjectFile/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/JSON/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
  lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h
  lldb/source/Plugins/SymbolFile/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/JSON/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.cpp
  lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.h
  lldb/source/Symbol/Symbol.cpp
  lldb/test/API/macosx/symbols/Makefile
  lldb/test/API/macosx/symbols/TestSymbolFileJSON.py
  lldb/test/API/macosx/symbols/main.c

Index: lldb/test/API/macosx/symbols/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/symbols/main.c
@@ -0,0 +1,2 @@
+int foo() { return 1; }
+int main() { return foo(); }
Index: lldb/test/API/macosx/symbols/TestSymbolFileJSON.py
===
--- /dev/null
+++ lldb/test/API/macosx/symbols/TestSymbolFileJSON.py
@@ -0,0 +1,166 @@
+""" Testing symbol loading via JSON file. """
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TargetSymbolsFileJSON(TestBase):
+
+def setUp(self):
+TestBase.setUp(self)
+self.source = 'main.c'
+
+@no_debug_info_test
+def test_symbol_file_json_address(self):
+"""Test that 'target symbols add' can load the symbols from a JSON file using file addresses."""
+
+self.build()
+stripped = self.getBuildArtifact("stripped.out")
+unstripped = self.getBuildArtifact("a.out")
+
+# Create a JSON symbol file from the unstripped target.
+unstripped_target = self.dbg.CreateTarget(unstripped)
+self.assertTrue(unstripped_target, VALID_TARGET)
+
+unstripped_module = unstripped_target.GetModuleAtIndex(0)
+main_symbol = unstripped_module.FindSymbol("main")
+foo_symbol = unstripped_module.FindSymbol("foo")
+
+data = {
+"triple": unstripped_module.GetTriple(),
+"uuid": unstripped_module.GetUUIDString(),
+"symbols": list()
+}
+data['symbols'].append({
+"name": "main",
+"type": "code",
+"size": main_symbol.GetSize(),
+"address": main_symbol.addr.GetFileAddress(),
+})
+data['symbols'].append({
+"name": "foo",
+"type": "code",
+"size": foo_symbol.GetSize(),
+"address": foo_symbol.addr.GetFileAddress(),
+})
+
+json_object = json.dumps(data, indent=4)
+json_symbol_file = self.getBuildArtifact("a.json")
+with open(json_symbol_file, "w") as outfile:
+outfile.write(json_object)
+
+# Create a stripped target.
+stripped_target = self.dbg.CreateTarget(stripped)
+self.assertTrue(stripped_target, VALID_TARGET)
+
+# Ensure there's no symbol for main and foo.
+stripped_module = stripped_target.GetModuleAtIndex(0)
+self.assertFalse(stripped_module.FindSymbol("main").IsValid())
+self.assertFalse(stripped_module.FindSymbol("foo").IsValid())
+
+main_bp = stripped_target.BreakpointCreateByName(
+"main", "stripped.out")
+self.assertTrue(main_bp, VALID_BREAKPOINT)
+self.assertEqual(main_bp.num_locations, 0)
+
+# Load the JSON symbol file.
+self.runCmd("target symbols add -s %s %s" %
+(stripped, self.getBuildArtifact("a.json")))
+
+stripped_main_symbol = stripped_module.FindSymbol("main")
+stripped_foo_symbol = stripped_module.FindSymbol("foo")
+
+# Ensure main and foo are available now.
+self.assertTrue(stripped_main_symbol.IsValid())
+self.assertTrue(stripped_foo_symbol.IsValid())
+self.assertEqual(main_bp.num_locations, 1)
+
+# Ensure the file address matches between the stripped and unstripped target.
+self.assertEqual(stripped_main_symbol.addr.GetFileAddress(),
+ main_symbol.addr.GetFileAddress())
+self.assertEqual(stripped_main_symbol.addr.GetFileAddress(),
+ main_symbol.addr.GetFileAddress())
+
+# Ensure the size matches.
+self.assertEqual(stripped_main_symbol.GetSize(), main_symbol.GetSize())
+self.assertEqual(stripped_main_symbol.GetSize(), main_symbol.GetSize())
+
+# Ensure the type matches.
+self.assertEqual(stripped_main_symbol.GetType(), main_symbol.GetType())
+self.assertEqual(stripped_main_symbol.GetType(), main_

[Lldb-commits] [lldb] aa728ff - [lldb] Fix stack-use-after-scope issue in ScriptedInterface.h

2023-03-06 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-03-06T16:35:24-08:00
New Revision: aa728ff754e9de91f20fca1e2847d69a81cccb75

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

LOG: [lldb] Fix stack-use-after-scope issue in ScriptedInterface.h

This patch should fix a `stack-use-after-scope` in the helper function
`ScriptedInterface::ErrorWithMessage`.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Interpreter/ScriptedInterface.h

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedInterface.h
index 8785e31f7b932..ab61425932643 100644
--- a/lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -40,12 +40,16 @@ class ScriptedInterface {
   LLDBLog log_caterogy = LLDBLog::Process) {
 LLDB_LOGF(GetLog(log_caterogy), "%s ERROR = %s", caller_name.data(),
   error_msg.data());
-llvm::Twine err = llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
-  llvm::Twine(error_msg));
+std::string full_error_message =
+llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
+llvm::Twine(error_msg))
+.str();
 if (const char *detailed_error = error.AsCString())
-  err.concat(llvm::Twine(" (") + llvm::Twine(detailed_error) +
- llvm::Twine(")"));
-error.SetErrorString(err.str());
+  full_error_message +=
+  llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
+  llvm::Twine(")"))
+  .str();
+error.SetErrorString(full_error_message);
 return {};
   }
 



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


[Lldb-commits] [lldb] 470fd9c - [lldb] Stop opening Console.app and TextEdit.app when running the testsuite on macOS

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

Author: Alex Langford
Date: 2023-03-06T16:47:56-08:00
New Revision: 470fd9c50a20a79e75b116ab938b9f87f38cba5c

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

LOG: [lldb] Stop opening Console.app and TextEdit.app when running the 
testsuite on macOS

Added: 


Modified: 
lldb/test/API/commands/session/save/TestSessionSave.py

Removed: 




diff  --git a/lldb/test/API/commands/session/save/TestSessionSave.py 
b/lldb/test/API/commands/session/save/TestSessionSave.py
index 5474cb354dae0..e1b60af05dd26 100644
--- a/lldb/test/API/commands/session/save/TestSessionSave.py
+++ b/lldb/test/API/commands/session/save/TestSessionSave.py
@@ -30,7 +30,8 @@ def test_session_save(self):
 settings = [
   'settings set interpreter.echo-commands true',
   'settings set interpreter.echo-comment-commands true',
-  'settings set interpreter.stop-command-source-on-error false'
+  'settings set interpreter.stop-command-source-on-error false',
+  'settings set interpreter.open-transcript-in-editor false',
 ]
 
 for setting in settings:
@@ -102,6 +103,7 @@ def test_session_save_on_quit(self):
   'settings set interpreter.stop-command-source-on-error false',
   'settings set interpreter.save-session-on-quit true',
   'settings set interpreter.save-session-directory ' + td.name,
+  'settings set interpreter.open-transcript-in-editor false',
 ]
 
 for setting in settings:



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


[Lldb-commits] [PATCH] D143104: [lldb/Plugins] Add Attach capabilities to ScriptedProcess

2023-03-06 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

Looks like this change broke the windows lldb build: 
https://lab.llvm.org/buildbot/#/builders/83/builds/29801


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143104

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


[Lldb-commits] [PATCH] D145242: [lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function pointers

2023-03-06 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

Looks like either this change or D125241  
broke the Windows lldb bot: 
https://lab.llvm.org/buildbot/#/builders/83/builds/29800. Since it's been 
broken for a few days, if you can't address the failure soon, I'll go ahead and 
revert the changes to bring it back to green.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145242

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


[Lldb-commits] [PATCH] D143104: [lldb/Plugins] Add Attach capabilities to ScriptedProcess

2023-03-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added a subscriber: omjavaid.
mib added a comment.

In D143104#4173574 , 
@stella.stamenova wrote:

> Looks like this change broke the windows lldb build: 
> https://lab.llvm.org/buildbot/#/builders/83/builds/29801

Hi @stella.stamenova ! @omjavaid have a fix for this 
https://reviews.llvm.org/D145446


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143104

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


[Lldb-commits] [PATCH] D145242: [lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function pointers

2023-03-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D145242#4173577 , 
@stella.stamenova wrote:

> Looks like either this change or D125241  
> broke the Windows lldb bot: 
> https://lab.llvm.org/buildbot/#/builders/83/builds/29800. Since it's been 
> broken for a few days, if you can't address the failure soon, I'll go ahead 
> and revert the changes to bring it back to green.

Ah thanks for pointing it out. Thought I had fixed it with 
https://reviews.llvm.org/rG96e39fdbb90b26191fc79b6226f299e3c10e559b

Looks like it only fails on Arm64 Windows? That's pretty confusing to me, also 
don't really have a way to repro that. I have a Windows machine and all tests 
pass on it. Tempted to skip the test for this specific platforms


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145242

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


[Lldb-commits] [PATCH] D145242: [lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function pointers

2023-03-06 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

In D145242#4173592 , @Michael137 
wrote:

> In D145242#4173577 , 
> @stella.stamenova wrote:
>
>> Looks like either this change or D125241  
>> broke the Windows lldb bot: 
>> https://lab.llvm.org/buildbot/#/builders/83/builds/29800. Since it's been 
>> broken for a few days, if you can't address the failure soon, I'll go ahead 
>> and revert the changes to bring it back to green.
>
> Ah thanks for pointing it out. Thought I had fixed it with 
> https://reviews.llvm.org/rG96e39fdbb90b26191fc79b6226f299e3c10e559b
>
> Will check on my Windows machine. But feel free to revert, since I'm only 
> going to be able to look at it tomorrow

The lldb bot I pointed you is not an arm buildbot, it's x64. Also the test you 
fixed is `ast-types`, but there were actually two failing tests - 
`TestDataFormatterCpp.py` is still failing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145242

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


[Lldb-commits] [PATCH] D145276: [lldb] Let 'v' command directly access ivars of _any_ self/this

2023-03-06 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.
Herald added a subscriber: JDevlieghere.

From an end-user perspective, I like this.




Comment at: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:9818
+if (ClangASTMetadata *metadata = GetMetadata(fun_decl))
+  return metadata->GetObjectPtrLanguage();
+  }

Couple of questions for my understanding:

1. Do you see any opportunities for this to spectacularly do the wrong thing in 
an ObjectiveC++ program by guessing the wrong language? I suppose this just 
tries to do a best effort?

2. We're not using the DW_AT_APPLE_runtime_language attribute because it's only 
attached to Objective-C classes?

3. We're not using the DW_AT_language of the DW_TAG_compile_unit because it 
won't help us in an ObjC++ program?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145276

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


[Lldb-commits] [PATCH] D145437: [lldb-vscode] Use `expression` command for completion

2023-03-06 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

That seems to be clearly better, since `p` could be aliased to anything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145437

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


[Lldb-commits] [PATCH] D145437: [lldb-vscode] Use `expression` command for completion

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

We might consider using dwim-print here in the future?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145437

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


[Lldb-commits] [PATCH] D145242: [lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function pointers

2023-03-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D145242#4173609 , 
@stella.stamenova wrote:

> In D145242#4173592 , @Michael137 
> wrote:
>
>> In D145242#4173577 , 
>> @stella.stamenova wrote:
>>
>>> Looks like either this change or D125241  
>>> broke the Windows lldb bot: 
>>> https://lab.llvm.org/buildbot/#/builders/83/builds/29800. Since it's been 
>>> broken for a few days, if you can't address the failure soon, I'll go ahead 
>>> and revert the changes to bring it back to green.
>>
>> Ah thanks for pointing it out. Thought I had fixed it with 
>> https://reviews.llvm.org/rG96e39fdbb90b26191fc79b6226f299e3c10e559b
>>
>> Will check on my Windows machine. But feel free to revert, since I'm only 
>> going to be able to look at it tomorrow
>
> The lldb bot I pointed you is not an arm buildbot, it's x64. Also the test 
> you fixed is `ast-types`, but there were actually two failing tests - 
> `TestDataFormatterCpp.py` is still failing.



In D145242#4173609 , 
@stella.stamenova wrote:

> In D145242#4173592 , @Michael137 
> wrote:
>
>> In D145242#4173577 , 
>> @stella.stamenova wrote:
>>
>>> Looks like either this change or D125241  
>>> broke the Windows lldb bot: 
>>> https://lab.llvm.org/buildbot/#/builders/83/builds/29800. Since it's been 
>>> broken for a few days, if you can't address the failure soon, I'll go ahead 
>>> and revert the changes to bring it back to green.
>>
>> Ah thanks for pointing it out. Thought I had fixed it with 
>> https://reviews.llvm.org/rG96e39fdbb90b26191fc79b6226f299e3c10e559b
>>
>> Will check on my Windows machine. But feel free to revert, since I'm only 
>> going to be able to look at it tomorrow
>
> The lldb bot I pointed you is not an arm buildbot, it's x64. Also the test 
> you fixed is `ast-types`, but there were actually two failing tests - 
> `TestDataFormatterCpp.py` is still failing.

@stella.stamenova could you symbolicate the crash stack trace for me if you get 
the chance? It's hard to decipher from the log what's going on and I can't 
reproduce it on my Windows machine if I run the test steps manually in the LLDB 
CLI.

  0.HandleCommand(command = “frame variable”)
  Exception Code: 0xC005
   #0 0x7ff85276e154 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x371e154)
   #1 0x7ff8529000bc PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x38b00bc)
   #2 0x7ff85272456f PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x36d456f)
   #3 0x7ff852723bdb PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x36d3bdb)
   #4 0x7ff84f8e76a6 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x8976a6)
   #5 0x7ff84f4f5bf1 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x4a5bf1)
   #6 0x7ff84f889e83 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x839e83)
   #7 0x7ff84f88fb09 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x83fb09)
   #8 0x7ff84f86d8c1 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x81d8c1)
   #9 0x7ff84f866a6f PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x816a6f)
  #10 0x7ff84f8710e0 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x8210e0)
  #11 0x7ff84f87166c PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x82166c)
  #12 0x7ff84f4debd9 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x48ebd9)
  #13 0x7ff84f3da575 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x38a575)
  #14 0x7ff84f42cb8b PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x3dcb8b)
  #15 0x7ff84f3da744 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x38a744)
  #16 0x7ff84f562deb PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x512deb)
  #17 0x7ff84f423557 PyInit__lldb 
(C:\buildbot\lldb-x64-windows-ninja\build\Lib\site-packages\lldb\_lldb.cp39-win_amd64.pyd+0x3d3557)
  #18 0

[Lldb-commits] [lldb] 71b3806 - Fix LLDB windows build

2023-03-06 Thread Muhammad Omair Javaid via lldb-commits

Author: Muhammad Omair Javaid
Date: 2023-03-07T05:37:15+04:00
New Revision: 71b38063b282937640e05ab219c2baa6ed7d4ac7

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

LOG: Fix LLDB windows build

LLDB WoA buildbot is failing due to pid_t redefinition after recent changes in
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp.
Process.h includes PosixApi.h which defines pid_t. Python.h on windows also 
typedefs
pid_t. To make sure that we include Python.h before PosixApi this patch 
renforces
the workaround previously set up to guard this issue.

https://lab.llvm.org/buildbot/#/builders/219

Reviewed By: mib

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

Added: 


Modified: 

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

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index cffa3bda3ab03..c985065835727 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,6 +7,10 @@
 
//===--===//
 
 #include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
@@ -14,9 +18,6 @@
 
 #if LLDB_ENABLE_PYTHON
 
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
 #include "SWIGPythonBridge.h"
 #include "ScriptInterpreterPythonImpl.h"
 #include "ScriptedProcessPythonInterface.h"



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


[Lldb-commits] [PATCH] D145446: Fix LLDB windows build

2023-03-06 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71b38063b282: Fix LLDB windows build (authored by omjavaid).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145446

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


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,6 +7,10 @@
 
//===--===//
 
 #include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
@@ -14,9 +18,6 @@
 
 #if LLDB_ENABLE_PYTHON
 
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
 #include "SWIGPythonBridge.h"
 #include "ScriptInterpreterPythonImpl.h"
 #include "ScriptedProcessPythonInterface.h"


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,6 +7,10 @@
 //===--===//
 
 #include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
@@ -14,9 +18,6 @@
 
 #if LLDB_ENABLE_PYTHON
 
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
 #include "SWIGPythonBridge.h"
 #include "ScriptInterpreterPythonImpl.h"
 #include "ScriptedProcessPythonInterface.h"
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D143520: Add a new SBDebugger::SetDestroyCallback() API

2023-03-06 Thread jeffrey tan via Phabricator via lldb-commits
yinghuitan updated this revision to Diff 502897.
yinghuitan added a comment.

Address review feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143520

Files:
  lldb/bindings/python/python-typemaps.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/Core/Debugger.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/Debugger.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py

Index: lldb/test/API/python_api/debugger/TestDebuggerAPI.py
===
--- lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -30,7 +30,7 @@
 self.dbg.SetPrompt(None)
 self.dbg.SetCurrentPlatform(None)
 self.dbg.SetCurrentPlatformSDKRoot(None)
-
+
 fresh_dbg = lldb.SBDebugger()
 self.assertEquals(len(fresh_dbg), 0)
 
@@ -146,3 +146,16 @@
 self.assertEqual(platform2.GetName(), expected_platform)
 self.assertTrue(platform2.GetWorkingDirectory().endswith("bar"),
 platform2.GetWorkingDirectory())
+
+def test_SetDestroyCallback(self):
+destroy_dbg_id = None
+def foo(dbg_id):
+# Need nonlocal to modify closure variable.
+nonlocal destroy_dbg_id
+destroy_dbg_id = dbg_id
+
+self.dbg.SetDestroyCallback(foo)
+
+original_dbg_id = self.dbg.GetID()
+self.dbg.Destroy(self.dbg)
+self.assertEqual(destroy_dbg_id,  original_dbg_id)
Index: lldb/source/Core/Debugger.cpp
===
--- lldb/source/Core/Debugger.cpp
+++ lldb/source/Core/Debugger.cpp
@@ -560,6 +560,12 @@
   assert(g_debugger_list_ptr &&
  "Debugger::Terminate called without a matching Debugger::Initialize!");
 
+  if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
+std::lock_guard guard(*g_debugger_list_mutex_ptr);
+for (const auto &debugger : *g_debugger_list_ptr)
+  debugger->HandleDestroyCallback();
+  }
+
   if (g_thread_pool) {
 // The destructor will wait for all the threads to complete.
 delete g_thread_pool;
@@ -679,10 +685,18 @@
   return debugger_sp;
 }
 
+void Debugger::HandleDestroyCallback() {
+  if (m_destroy_callback) {
+m_destroy_callback(GetID(), m_destroy_callback_baton);
+m_destroy_callback = nullptr;
+  }
+}
+
 void Debugger::Destroy(DebuggerSP &debugger_sp) {
   if (!debugger_sp)
 return;
 
+  debugger_sp->HandleDestroyCallback();
   CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
 
   if (cmd_interpreter.GetSaveSessionOnQuit()) {
@@ -1285,6 +1299,12 @@
   std::make_shared(log_callback, baton);
 }
 
+void Debugger::SetDestroyCallback(
+lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
+  m_destroy_callback = destroy_callback;
+  m_destroy_callback_baton = baton;
+}
+
 static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
   std::string title, std::string details,
   uint64_t completed, uint64_t total,
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1684,6 +1684,15 @@
   }
 }
 
+void SBDebugger::SetDestroyCallback(
+lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) {
+  LLDB_INSTRUMENT_VA(this, destroy_callback, baton);
+  if (m_opaque_sp) {
+return m_opaque_sp->SetDestroyCallback(
+destroy_callback, baton);
+  }
+}
+
 SBTrace
 SBDebugger::LoadTraceFromFile(SBError &error,
   const SBFileSpec &trace_description_file) {
Index: lldb/include/lldb/lldb-private-types.h
===
--- lldb/include/lldb/lldb-private-types.h
+++ lldb/include/lldb/lldb-private-types.h
@@ -116,6 +116,8 @@
 using ValueObjectProviderTy =
 std::function;
 
+typedef void (*DebuggerDestroyCallback)(lldb::user_id_t debugger_id,
+void *baton);
 } // namespace lldb_private
 
 #endif // #if defined(__cplusplus)
Index: lldb/include/lldb/Core/Debugger.h
===
--- lldb/include/lldb/Core/Debugger.h
+++ lldb/include/lldb/Core/Debugger.h
@@ -450,6 +450,10 @@
 
   static void ReportSymbolChange(const ModuleSpec &module_spec);
 
+  void
+  SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback,
+ void *baton);
+
 protected:
   friend class CommandInterpreter;
   friend class REPL;
@@ -494,6 +498,8 @@
std::optional debugger_id,

[Lldb-commits] [PATCH] D145462: [LLDB][ObjectFileELF] Support LoongArch64 in ApplyReloctions

2023-03-06 Thread Lu Weining via Phabricator via lldb-commits
SixWeining created this revision.
SixWeining added reviewers: labath, davide, DavidSpickett, xen0n, wangleiat, 
MaskRay.
Herald added subscribers: pengfei, emaste.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Currently ApplyReloctions() deals with different archs' relocation types
together (in a single `switch() {..}`). I think it is incorrect because
different relocation types of different archs may have same enum values.
For example:
`R_LARCH_32` and `R_X86_64_64` are both `1`;
`R_LARCH_64` and `R_X86_64_PC32` are both `2`.

This patch handles each arch in seperate `switch()` to solve the enum
values conflict issue.

And a new test is added for LoongArch64.

Change-Id: I96aef784bd6ca9387067ef67ffa9f0fd9a7cf18b


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145462

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/loongarch64-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/loongarch64-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/loongarch64-relocations.yaml
@@ -0,0 +1,93 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+# CHECK-NEXT: : 4700 0400 0801  0C002D00  3700 
+# CHECK-NEXT: 0020:  0800 0200  0008 0001 6F49 00010243
+# CHECK-NEXT: 0040: 0003 4B00 050400
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_LOONGARCH
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+AddressAlign:0x0004
+Content: E0031B32C0035FD6
+  - Name:.debug_str
+Type:SHT_PROGBITS
+Flags:   [ SHF_MERGE, SHF_STRINGS ]
+AddressAlign:0x0001
+Size:0x50
+  - Name:.debug_abbrev
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Size:0x10
+  - Name:.debug_info
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Content: 4700040008010C000800020800016F0102430003050400
+  - Name:.rela.debug_info
+Type:SHT_RELA
+Link:.symtab
+AddressAlign:0x0008
+Info:.debug_info
+Relocations:
+  - Offset:  0x0006
+Symbol:  .debug_abbrev
+Type:R_LARCH_32
+  - Offset:  0x000C
+Symbol:  .debug_str
+Type:R_LARCH_32
+  - Offset:  0x0012
+Symbol:  .debug_str
+Type:R_LARCH_32
+Addend:  45
+  - Offset:  0x0016
+Symbol:  .debug_line
+Type:R_LARCH_32
+  - Offset:  0x001A
+Symbol:  .debug_str
+Type:R_LARCH_32
+Addend:  55
+  - Offset:  0x001E
+Symbol:  .text
+Type:R_LARCH_64
+  - Offset:  0x002B
+Symbol:  .text
+Type:R_LARCH_64
+  - Offset:  0x0039
+Symbol:  .debug_str
+Type:R_LARCH_32
+Addend:  73
+  - Offset:  0x0044
+Symbol:  .debug_str
+Type:R_LARCH_32
+Addend:  75
+  - Name:.debug_line
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Size:0x20
+Symbols:
+  - Name:.text
+Type:STT_SECTION
+Section: .text
+  - Name:.debug_str
+Type:STT_SECTION
+Section: .debug_str
+  - Name:.debug_abbrev
+Type:STT_SECTION
+Section: .debug_abbrev
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:.debug_line
+Type:STT_SECTION
+Section: .debug_line
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2593,6 +2593,50 @@
  rel_data, symtab_data, strtab_data);
 }
 
+static void Apply