[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)
slydiman wrote: `lldb-shell::ProcessMachCoreArch.test` is flake. But the following tests are broken by this commit (segmentation fault): 1. `lldb-api::TestMiniDump.py`: ``` 2 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c11a3cd14 3 libc.so.6 0x751c18845330 4 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c11459af7 5 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1145f215 6 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1145f9b3 7 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1143e18d 8 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1143ea75 9 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c113ac4cb 10 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c113ad37f 11 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c113ad487 12 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c113aed4e 13 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1140addf 14 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1180e278 15 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1138ba28 16 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1138bea3 17 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1138c3e3 18 _lldb.cpython-312-x86_64-linux-gnu.so 0x751c1125c17c 19 libc.so.6 0x751c1889caa4 20 libc.so.6 0x751c18929c3c Fatal Python error: Segmentation fault Thread 0x751c18b68080 (most recent call first): File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/local/lib/python3.12/dist-packages/lldb/__init__.py", line 11494 in LoadCore File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/functionalities/postmortem/minidump/TestMiniDump.py", line 43 in test_modules_in_mini_dump File "/usr/lib/python3.12/unittest/case.py", line 589 in _callTestMethod File "/usr/lib/python3.12/unittest/case.py", line 634 in run File "/usr/lib/python3.12/unittest/case.py", line 690 in __call__ File "/usr/lib/python3.12/unittest/suite.py", line 122 in run File "/usr/lib/python3.12/unittest/suite.py", line 84 in __call__ File "/usr/lib/python3.12/unittest/suite.py", line 122 in run File "/usr/lib/python3.12/unittest/suite.py", line 84 in __call__ File "/usr/lib/python3.12/unittest/runner.py", line 240 in run File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/dotest.py", line 1108 in run_suite File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py", line 8 in Extension modules: lldb._lldb (total: 1) ``` 2. `lldb-shell::broken-unwind.test`: ``` Program arguments: /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/lldb -O "platform select remote-linux" -O "platform connect connect://jetson-agx-2198.lab.llvm.org:1234" -O "platform shell mkdir -p /home/ubuntu/lldb-tests/shell/home/ubuntu/lldb-tests/shell/Minidump/Windows/broken-unwind.test" -O "platform settings -w /home/ubuntu/lldb-tests/shell/home/ubuntu/lldb-tests/shell/Minidump/Windows/broken-unwind.test" --no-lldbinit -S /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/lit-lldb-init-quiet -O "settings set target.exec-search-paths /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Minidump/Windows/Output" -c /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Minidump/Windows/Output/broken-unwind.dmp -o "image show-unwind -a 0xb1000" -o exit #0 0x63ebd3da85c2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/lldb+0x395c2) #1 0x63ebd3da5d5f llvm::sys::RunSignalHandlers() (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/lldb+0x36d5f) #2 0x63ebd3da5ea4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #3 0x7cb82ca45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330) #4 0x7cb82ca9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c) #5 0x7cb82ca4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e) #6 0x7cb82e43a553 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #7 0x7cb82ca45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330) #8 0x7cb82de575b7 lldb_private::RegisterContextUnwind::ReadFrameAddress(lldb::RegisterKind, lldb_private::UnwindPlan::Row::FAValue const&, unsigned long&) (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lib/liblldb.so.21.0git+0xc575b7) #9 0x7cb82de5ccd5 lldb_private::RegisterContextUnwind::InitializeZerothFrame() (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lib/liblldb.so.21.0git+0xc5ccd5) #10 0x7cb82de5d473 lldb_private::RegisterContextUnwind::RegisterContextUnwind(lldb_private::Thread&, std::shared_ptr const&, lldb_private::SymbolContext&, unsigned int, lldb_private::UnwindLLDB&) (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubun
[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)
DhruvSrivastavaX wrote: Sure, Thanks. I have modified my test case for this one. https://github.com/llvm/llvm-project/pull/131304 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][debugserver] Save and restore the SVE/SME register state (PR #134184)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/134184 >From 7cc45f1a300b1b0f2cbb529f11a0f9e56c41ffea Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 2 Apr 2025 18:05:29 -0700 Subject: [PATCH 1/2] [lldb][debugserver] Save and restore the SVE/SME register state debugserver isn't saving and restoring the SVE/SME register state around inferior function calls. Making arbitrary function calls while in Streaming SVE mode is generally a poor idea because a NEON instruction can be hit and crash the expression execution, which is how I missed this, but they should be handled correctly if the user knows it is safe to do. rdar://146886210 --- .../source/MacOSX/arm64/DNBArchImplARM64.cpp | 30 ++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp index 34a4ee21f8502..fb23744393d43 100644 --- a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp +++ b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp @@ -2953,7 +2953,14 @@ kern_return_t DNBArchMachARM64::SetRegisterState(int set) { switch (set) { case e_regSetALL: -return SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); + { +kern_return_t ret = SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); +if (CPUHasSME()) { + ret |= SetSVEState(); + ret |= SetSMEState(); +} +return ret; + } case e_regSetGPR: return SetGPRState(); case e_regSetVFP: @@ -3122,6 +3129,15 @@ uint32_t DNBArchMachARM64::SaveRegisterState() { DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::SaveRegisterState () " "error: %s regs failed to read: %u", "VFP", kret); + } else if (CPUHasSME() && (kret = SetSVEState() != KERN_SUCCESS)) { +DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::SaveRegisterState () " + "error: %s regs failed to read: %u", + "SVE", kret); + } + else if (CPUHasSME() && (kret = SetSMEState() != KERN_SUCCESS)) { +DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::SaveRegisterState () " + "error: %s regs failed to read: %u", + "SME", kret); } else { const uint32_t save_id = GetNextRegisterStateSaveID(); m_saved_register_states[save_id] = m_state.context; @@ -3149,6 +3165,18 @@ bool DNBArchMachARM64::RestoreRegisterState(uint32_t save_id) { "write: %u", save_id, "VFP", kret); success = false; +} else if ((kret = SetSVEState()) != KERN_SUCCESS) { + DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::RestoreRegisterState " + "(save_id = %u) error: %s regs failed to " + "write: %u", + save_id, "SVE", kret); + success = false; +} else if ((kret = SetSMEState()) != KERN_SUCCESS) { + DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::RestoreRegisterState " + "(save_id = %u) error: %s regs failed to " + "write: %u", + save_id, "SME", kret); + success = false; } m_saved_register_states.erase(pos); return success; >From 432a68d8a85b46b7cacd6b64802a394562bc1566 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 2 Apr 2025 18:28:07 -0700 Subject: [PATCH 2/2] reformat --- .../source/MacOSX/arm64/DNBArchImplARM64.cpp | 42 +++ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp index fb23744393d43..bafcb47503dec 100644 --- a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp +++ b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp @@ -2954,7 +2954,8 @@ kern_return_t DNBArchMachARM64::SetRegisterState(int set) { switch (set) { case e_regSetALL: { -kern_return_t ret = SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); +kern_return_t ret = +SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); if (CPUHasSME()) { ret |= SetSVEState(); ret |= SetSMEState(); @@ -3126,17 +3127,19 @@ uint32_t DNBArchMachARM64::SaveRegisterState() { "error: GPR regs failed to read: %u ", kret); } else if ((kret = GetVFPState(force)) != KERN_SUCCESS) { -DNBLogThreadedIf(LOG_THREAD, "DNBArchMachARM64::SaveRegisterState () " - "error: %s regs failed to read: %u", +DNBLogThreadedIf(LOG_THREAD, + "DNBArchMachARM64::SaveRegisterState () " + "error: %s
[Lldb-commits] [lldb] [lldb] Update examples in docs/use/python-reference.rst to work with Python 3 (PR #134204)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The examples on this page were using the Python 2-style print. I ran the updated code examples under Python 3 to confirm they are still up-to-date. --- Full diff: https://github.com/llvm/llvm-project/pull/134204.diff 1 Files Affected: - (modified) lldb/docs/use/python-reference.rst (+36-32) ``diff diff --git a/lldb/docs/use/python-reference.rst b/lldb/docs/use/python-reference.rst index 02e09e10c0f6a..4bf0cb075064b 100644 --- a/lldb/docs/use/python-reference.rst +++ b/lldb/docs/use/python-reference.rst @@ -153,16 +153,16 @@ pass them to the Python print function: (lldb) script Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. - >>> print lldb.debugger + >>> print(lldb.debugger) Debugger (instance: "debugger_1", id: 1) - >>> print lldb.target + >>> print(lldb.target) a.out - >>> print lldb.process - SBProcess: pid = 59289, state = stopped, threads = 1, executable = a.out - >>> print lldb.thread - SBThread: tid = 0x1f03 - >>> print lldb.frame - frame #0: 0x00010bb6 a.out main + 54 at main.c:16 + >>> print(lldb.process) + SBProcess: pid = 58842, state = stopped, threads = 1, executable = a.out + >>> print(lldb.thread) + thread #1: tid = 0x2265ce3, 0x00010334 a.out`main at t.c:2:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 + >>> print(lldb.frame) + frame #0: 0x00010334 a.out`main at t.c:2:3 Running a python script when a breakpoint gets hit @@ -252,7 +252,7 @@ Here is the code: > # Get the name of the function > name = frame.GetFunctionName() > # Print the order and the function name - > print '[%i] %s' % (counter, name) + > print('[%i] %s' % (counter, name)) > # Disable the current breakpoint location so it doesn't get hit again > bp_loc.SetEnabled(False) > # No need to stop here @@ -588,7 +588,7 @@ say .. code-block:: python - print >>result, "my command does lots of cool stuff" + print("my command does lots of cool stuff", file=result) SBCommandReturnObject and SBStream both support this file-like behavior by providing write() and flush() calls at the Python layer. @@ -712,7 +712,7 @@ your lldb.ParsedCommand subclass should implement: """ And to handle the completion of arguments: - + .. code-block:: python def handle_argument_completion(self, args, arg_pos, cursor_pos): @@ -826,7 +826,7 @@ a function that can be used by LLDB's python command code: # And the initialization code to add your commands def __lldb_init_module(debugger, internal_dict): debugger.HandleCommand('command script add -f ls.ls ls') - print 'The "ls" python command has been installed and is ready for use.' + print('The "ls" python command has been installed and is ready for use.') Now we can load the module into LLDB and use it @@ -964,16 +964,18 @@ script that will launch a program from the current working directory called "a.out", set a breakpoint at "main", and then run and hit the breakpoint, and print the process, thread and frame objects if the process stopped: -:: +.. code-block:: python - #!/usr/bin/env python + #!/usr/bin/env python3 import lldb import os + def disassemble_instructions(insts): for i in insts: - print i + print(i) + # Set the path to the executable to debug exe = "./a.out" @@ -983,54 +985,56 @@ print the process, thread and frame objects if the process stopped: # When we step or continue, don't return from the function until the process # stops. Otherwise we would have to handle the process events ourselves which, while doable is - #a little tricky. We do this by setting the async mode to false. - debugger.SetAsync (False) + # a little tricky. We do this by setting the async mode to false. + debugger.SetAsync(False) # Create a target from a file and arch - print "Creating a target for '%s'" % exe + print("Creating a target for '%s'" % exe) - target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT) + target = debugger.CreateTargetWithFileAndArch(exe, lldb.LLDB_ARCH_DEFAULT) if target: # If the target is valid set a breakpoint at main - main_bp = target.BreakpointCreateByName ("main", target.GetExecutable().GetFilename()); + main_bp = target.BreakpointCreateByName( + "main", target.GetExecutable().GetFilename() + ) - print main_bp + print(main_bp) # Launch the process. Since we specified synchronous mode, we won't return # from this function until we hit the breakpoint at main - process = target.LaunchSimple (None, None, os.getcwd()) + process = target.LaunchSimple(None, None, os.getcwd()) # Make sure the launch went ok if process: # Print some simple process info - state = process.G
[Lldb-commits] [lldb] 0949043 - Revert "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders (#133247)"
Author: Vladislav Dzhidzhoev Date: 2025-04-03T11:33:11+02:00 New Revision: 094904303d50e0ab14bc5f2586a602f79af95953 URL: https://github.com/llvm/llvm-project/commit/094904303d50e0ab14bc5f2586a602f79af95953 DIFF: https://github.com/llvm/llvm-project/commit/094904303d50e0ab14bc5f2586a602f79af95953.diff LOG: Revert "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders (#133247)" This reverts commit d7afafdbc464e65c56a0a1d77bad426aa7538306. Caused remote Linux to Linux buildbot failure https://lab.llvm.org/buildbot/#/builders/195/builds/7046. Added: Modified: lldb/include/lldb/Symbol/FuncUnwinders.h lldb/include/lldb/Symbol/UnwindPlan.h lldb/include/lldb/Target/RegisterContextUnwind.h lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Symbol/FuncUnwinders.cpp lldb/source/Symbol/UnwindPlan.cpp lldb/source/Target/RegisterContextUnwind.cpp Removed: diff --git a/lldb/include/lldb/Symbol/FuncUnwinders.h b/lldb/include/lldb/Symbol/FuncUnwinders.h index 479ccf87b6e2c..1d4c28324e90f 100644 --- a/lldb/include/lldb/Symbol/FuncUnwinders.h +++ b/lldb/include/lldb/Symbol/FuncUnwinders.h @@ -36,19 +36,18 @@ class FuncUnwinders { ~FuncUnwinders(); - std::shared_ptr GetUnwindPlanAtCallSite(Target &target, -Thread &thread); + lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread); - std::shared_ptr - GetUnwindPlanAtNonCallSite(Target &target, lldb_private::Thread &thread); + lldb::UnwindPlanSP GetUnwindPlanAtNonCallSite(Target &target, +lldb_private::Thread &thread); - std::shared_ptr - GetUnwindPlanFastUnwind(Target &target, lldb_private::Thread &thread); + lldb::UnwindPlanSP GetUnwindPlanFastUnwind(Target &target, + lldb_private::Thread &thread); - std::shared_ptr + lldb::UnwindPlanSP GetUnwindPlanArchitectureDefault(lldb_private::Thread &thread); - std::shared_ptr + lldb::UnwindPlanSP GetUnwindPlanArchitectureDefaultAtFunctionEntry(lldb_private::Thread &thread); Address &GetFirstNonPrologueInsn(Target &target); @@ -78,34 +77,32 @@ class FuncUnwinders { // used. Instead, clients should ask for the *behavior* they are looking for, // using one of the above UnwindPlan retrieval methods. - std::shared_ptr GetAssemblyUnwindPlan(Target &target, - Thread &thread); + lldb::UnwindPlanSP GetAssemblyUnwindPlan(Target &target, Thread &thread); - std::shared_ptr GetObjectFileUnwindPlan(Target &target); + lldb::UnwindPlanSP GetObjectFileUnwindPlan(Target &target); - std::shared_ptr - GetObjectFileAugmentedUnwindPlan(Target &target, Thread &thread); + lldb::UnwindPlanSP GetObjectFileAugmentedUnwindPlan(Target &target, + Thread &thread); - std::shared_ptr GetEHFrameUnwindPlan(Target &target); + lldb::UnwindPlanSP GetEHFrameUnwindPlan(Target &target); - std::shared_ptr - GetEHFrameAugmentedUnwindPlan(Target &target, Thread &thread); + lldb::UnwindPlanSP GetEHFrameAugmentedUnwindPlan(Target &target, + Thread &thread); - std::shared_ptr GetDebugFrameUnwindPlan(Target &target); + lldb::UnwindPlanSP GetDebugFrameUnwindPlan(Target &target); - std::shared_ptr - GetDebugFrameAugmentedUnwindPlan(Target &target, Thread &thread); + lldb::UnwindPlanSP GetDebugFrameAugmentedUnwindPlan(Target &target, + Thread &thread); - std::shared_ptr GetCompactUnwindUnwindPlan(Target &target); + lldb::UnwindPlanSP GetCompactUnwindUnwindPlan(Target &target); - std::shared_ptr GetArmUnwindUnwindPlan(Target &target); + lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target); - std::shared_ptr GetSymbolFileUnwindPlan(Thread &thread); + lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread); - std::shared_ptr GetArchDefaultUnwindPlan(Thread &thread); + lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread); - std::shared_ptr - GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread); + lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread); private: lldb::UnwindAssemblySP GetUnwindAssemblyProfiler(Target &target); @@ -116,8 +113,7 @@ class FuncUnwinders { // unwind rule for the pc, and LazyBoolCalculate if it was unable to // determine this for some reason. lldb_private::LazyBool CompareUnwindPlansForIdenticalInitialPCLocation( - Thread &thread, const std::shared_ptr &a, - const std::shared_ptr &b); + Thread &thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP &b); UnwindTable &m_unwind_table; @@ -133,22 +129,22 @@ class FuncUnwinders { std::recursive_mutex m_mutex; - std::
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
https://github.com/kusmour updated https://github.com/llvm/llvm-project/pull/134339 >From 18e4af1c5798b620e96a4447cb8cdab272775909 Mon Sep 17 00:00:00 2001 From: Wanyi Ye Date: Thu, 3 Apr 2025 21:02:04 -0400 Subject: [PATCH] [lldb-dap] Always stop on enrty for attaching Recently upon debugging a program with thousands of threads, lldb-dap would hang at a `threads` request sent right after receiving the `configurationDone` response. Soon after it will end the debug session with "Process ex ited with status = -1 (0x) lost connection". This is because LLDB is still in the middle of resuming all the threads. And requesting threads will require stopp ing the process. From the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid` and just exit with s tatus -1. I don't think it's reasonable to allow getting threads from a running process. The alternative will be reject the `threads` request if the process is not stopped. --- lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py | 8 +++- .../API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py | 3 +++ lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp | 8 +--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py index 9df44cc454d5d..85990776cce57 100644 --- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py +++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py @@ -1,5 +1,5 @@ """ -Test lldb-dap setBreakpoints request +Test lldb-dap attach request """ @@ -35,6 +35,9 @@ def set_and_hit_breakpoint(self, continueToExit=True): self.assertEqual( len(breakpoint_ids), len(lines), "expect correct number of breakpoints" ) +# Send a configurationDone request when process is ready to continue +self.dap_server.request_configurationDone() +self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP")) self.continue_to_breakpoints(breakpoint_ids) if continueToExit: self.continue_to_exit() @@ -175,6 +178,9 @@ def test_commands(self): functions = ["main"] breakpoint_ids = self.set_function_breakpoints(functions) self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint") +# Execute the configurationDone even if this is not real attaching +self.dap_server.request_configurationDone() +self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP")) self.continue_to_breakpoints(breakpoint_ids) output = self.collect_console(timeout_secs=10, pattern=stopCommands[-1]) self.verify_commands("stopCommands", output, stopCommands) diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py index 9024120c868fd..0256e3a49938e 100644 --- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py +++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py @@ -32,6 +32,9 @@ def set_and_hit_breakpoint(self, continueToExit=True): self.assertEqual( len(breakpoint_ids), len(lines), "expect correct number of breakpoints" ) +# Send a configurationDone request when process is ready to continue +self.dap_server.request_configurationDone() +self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP")) self.continue_to_breakpoints(breakpoint_ids) if continueToExit: self.continue_to_exit() diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 5e622f3d3dcd4..aa7f3c0d57f9d 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -73,9 +73,11 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { llvm::StringRef core_file = GetString(arguments, "coreFile").value_or(""); const uint64_t timeout_seconds = GetInteger(arguments, "timeout").value_or(30); - dap.stop_at_entry = core_file.empty() - ? GetBoolean(arguments, "stopOnEntry").value_or(false) - : true; + // Clients like VS Code sends threads request right after receiving + // configurationDone reponse where the process might be resuming. + // Getting threads list on a running process is not supported by LLDB. + // Always stop the process after attaching. + dap.stop_at_entry = true; dap.configuration.postRunCommands = GetStrings(arguments, "postRunCommands"); const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot").value_or(""); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
https://github.com/kusmour edited https://github.com/llvm/llvm-project/pull/134339 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reapply "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders " (PR #134246)
https://github.com/dzhidzhoev approved this pull request. I wasn't able to reproduce the problem locally either, but I've got the same failing tests with the same stack traces by setting ``` const UnwindPlan::Row *active_row = (const UnwindPlan::Row *) 0x1; ``` I think it should work. https://github.com/llvm/llvm-project/pull/134246 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Creating a common configuration structure for launch and attach requests. (PR #133960)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/133960 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)
z2oh wrote: Cherrypick is up: https://github.com/swiftlang/llvm-project/pull/10415. Thanks @JDevlieghere! @ktraunmueller, ah I should've checked for an issue first, you had already done the investigation! I'm in favor of the documentation change you propose. I'd _also_ be in favor of just removing the assertion, but it's very possible I'm overlooking some reason why it's there in the first place (and it has been there for 12 years now). https://github.com/llvm/llvm-project/pull/134150 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
yuvald-sweet-security wrote: Should be good now https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use the "reverse video" effect when colors are disabled. (PR #134203)
https://github.com/jimingham approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/134203 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [clang-tools-extra] [flang] [lldb] [llvm] [mlir] Fix typos: paramter, parametr, parametere (PR #134092)
jayfoad wrote: > Please try not to create big PRs that are crossing subproject boundaries, > you'll have a hard time finding a reviewer will to sign off of a patch that > Rouches other parts of the project. 10 small/trivial PRs are less work for > the reviewers than one big one. Fair enough. https://github.com/llvm/llvm-project/pull/134092 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/130169 >From c183231db80d6c97bdd5e9bd0b21d041189146e8 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Tue, 18 Mar 2025 14:05:38 -0700 Subject: [PATCH 01/15] [lldb-dap] Adding support for cancelling a request. Adding support for cancelling requests. There are two forms of request cancellation. * Preemptively cancelling a request that is in the queue. * Actively cancelling the in progress request as a best effort attempt using `SBDebugger.RequestInterrupt()`. --- lldb/test/API/tools/lldb-dap/cancel/Makefile | 3 + .../tools/lldb-dap/cancel/TestDAP_cancel.py | 101 lldb/test/API/tools/lldb-dap/cancel/main.c| 6 + .../tools/lldb-dap/launch/TestDAP_launch.py | 1 + lldb/tools/lldb-dap/CMakeLists.txt| 1 + lldb/tools/lldb-dap/DAP.cpp | 145 -- lldb/tools/lldb-dap/DAP.h | 3 + .../lldb-dap/Handler/CancelRequestHandler.cpp | 55 +++ lldb/tools/lldb-dap/Handler/RequestHandler.h | 10 ++ .../lldb-dap/Protocol/ProtocolRequests.cpp| 7 + .../lldb-dap/Protocol/ProtocolRequests.h | 20 +++ lldb/tools/lldb-dap/Transport.cpp | 37 +++-- lldb/tools/lldb-dap/Transport.h | 3 +- lldb/tools/lldb-dap/lldb-dap.cpp | 5 +- 14 files changed, 377 insertions(+), 20 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/cancel/Makefile create mode 100644 lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py create mode 100644 lldb/test/API/tools/lldb-dap/cancel/main.c create mode 100644 lldb/tools/lldb-dap/Handler/CancelRequestHandler.cpp diff --git a/lldb/test/API/tools/lldb-dap/cancel/Makefile b/lldb/test/API/tools/lldb-dap/cancel/Makefile new file mode 100644 index 0..10495940055b6 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/cancel/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py new file mode 100644 index 0..f3b2f9fcb7a92 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py @@ -0,0 +1,101 @@ +""" +Test lldb-dap cancel request +""" + +import time + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +import lldbdap_testcase + + +class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase): +def send_async_req(self, command: str, arguments={}) -> int: +seq = self.dap_server.sequence +self.dap_server.send_packet( +{ +"type": "request", +"command": command, +"arguments": arguments, +} +) +return seq + +def async_blocking_request(self, duration: float) -> int: +""" +Sends an evaluate request that will sleep for the specified duration to +block the request handling thread. +""" +return self.send_async_req( +command="evaluate", +arguments={ +"expression": '`script import time; print("starting sleep", file=lldb.debugger.GetOutputFileHandle()); time.sleep({})'.format( +duration +), +"context": "repl", +}, +) + +def async_cancel(self, requestId: int) -> int: +return self.send_async_req(command="cancel", arguments={"requestId": requestId}) + +def test_pending_request(self): +""" +Tests cancelling a pending request. +""" +program = self.getBuildArtifact("a.out") +self.build_and_launch(program, stopOnEntry=True) +self.continue_to_next_stop() + +# Use a relatively short timeout since this is only to ensure the +# following request is queued. +blocking_seq = self.async_blocking_request(duration=1.0) +# Use a longer timeout to ensure we catch if the request was interrupted +# properly. +pending_seq = self.async_blocking_request(duration=self.timeoutval) +cancel_seq = self.async_cancel(requestId=pending_seq) + +blocking_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(blocking_resp["request_seq"], blocking_seq) +self.assertEqual(blocking_resp["command"], "evaluate") +self.assertEqual(blocking_resp["success"], True) + +pending_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(pending_resp["request_seq"], pending_seq) +self.assertEqual(pending_resp["command"], "evaluate") +self.assertEqual(pending_resp["success"], False) +self.assertEqual(pending_resp["message"], "cancelled") + +cancel_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(cancel_resp["request_seq"], cancel_seq) +self.assertEqual(cancel_resp["command"], "
[Lldb-commits] [lldb] [lldb-dap] Protect SetBreakpoint with the API mutex (PR #134030)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/134030 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
https://github.com/labath approved this pull request. Okay, I think we're ready now. Thank you for your patience. Just a couple of last minute cosmetic tweaks here. I've added a some include statements to make the headers more self contained, but I'm sure I've missed some. https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP] [ItaniumDemangle] Add infrastructure to track location information of parts of a demangled function name (PR #133249)
@@ -6176,6 +6180,10 @@ struct ManglingParser : AbstractManglingParser, Alloc> { Alloc>::AbstractManglingParser; }; +inline void OutputBuffer::printLeft(const Node &N) { N.printLeft(*this); } zygoloid wrote: Thanks, yes. I agree that the duplication is not ideal, and I think it'd be fine to add a few more virtual function calls if it reduces the duplication, but this extension to the demangler looks nice and clean now. https://github.com/llvm/llvm-project/pull/133249 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use the "reverse video" effect when colors are disabled. (PR #134203)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/134203 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)
z2oh wrote: I captured one above: ``` # Child-SP RetAddr Call Site 00 00d2`44b8ea48 7ff8`beefc12e ntdll!NtTerminateProcess+0x14 01 00d2`44b8ea50 7ff8`bcf518ab ntdll!RtlExitUserProcess+0x11e 02 00d2`44b8ea80 7ff8`bc0e0143 KERNEL32!ExitProcessImplementation+0xb 03 00d2`44b8eab0 7ff8`bc0e4c49 ucrtbase!common_exit+0xc7 04 00d2`44b8eb10 7ff8`bc102ae6 ucrtbase!abort+0x69 05 00d2`44b8eb40 7ff8`bc102cc1 ucrtbase!common_assert_to_stderr+0x6e 06 00d2`44b8eb80 7fff`b8e27a80 ucrtbase!wassert+0x71 07 00d2`44b8ebb0 7fff`b8b821e1 liblldb!llvm::convertUTF16ToUTF8String+0x30 [D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\llvm\lib\Support\ConvertUTFWrapper.cpp @ 88] 08 00d2`44b8ec30 7fff`b83e9aa2 liblldb!lldb_private::TargetThreadWindows::GetName+0x1b1 [D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\lldb\source\Plugins\Process\Windows\Common\TargetThreadWindows.cpp @ 198] 09 00d2`44b8eca0 7ff7`2a3c3c14 liblldb!lldb::SBThread::GetName+0x102 [D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\lldb\source\API\SBThread.cpp @ 432] 0a 00d2`44b8ed70 7ff7`2a3a5ac6 lldb_dap!lldb_dap::CreateThread+0x1f4 [S:\SourceCache\llvm-project\lldb\tools\lldb-dap\JSONUtils.cpp @ 877] 0b 00d2`44b8ef10 7ff7`2a3b0ab5 lldb_dap!`anonymous namespace'::request_threads+0xa6 [S:\SourceCache\llvm-project\lldb\tools\lldb-dap\lldb-dap.cpp @ 3906] 0c 00d2`44b8f010 7ff7`2a3b0fe8 lldb_dap!lldb_dap::DAP::HandleObject+0x1c5 [S:\SourceCache\llvm-project\lldb\tools\lldb-dap\DAP.cpp @ 796] 0d 00d2`44b8f130 7ff7`2a3a8b96 lldb_dap!lldb_dap::DAP::Loop+0x78 [S:\SourceCache\llvm-project\lldb\tools\lldb-dap\DAP.cpp @ 812] 0e 00d2`44b8f1d0 7ff7`2a4b5fbc lldb_dap!main+0x1096 [S:\SourceCache\llvm-project\lldb\tools\lldb-dap\lldb-dap.cpp @ 5319] 0f (Inline Function) ` lldb_dap!invoke_main+0x22 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 78] 10 00d2`44b8fb80 7ff8`bcf3e8d7 lldb_dap!__scrt_common_main_seh+0x10c [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 11 00d2`44b8fbc0 7ff8`beefbf6c KERNEL32!BaseThreadInitThunk+0x17 12 00d2`44b8fbf0 ` ntdll!RtlUserThreadStart+0x2c ``` We are reusing the `TargetThreadWindows` objects, so the second time that `TargetThreadWindows::GetName` is called, `m_name` has already been set, which triggers the assertion (without first clearing the string that is). `convertUTF16ToUTF8String` calls `Out.resize` so clearly expects to be able to freely mutate the string, but this is a different precondition than requiring the string be explicitly empty. The only thing I can think of is that `convertUTF16ToUTF8String` would be trying to prevent accidental reuse of strings, but IMO it should not the responsibility of that function to care. https://github.com/llvm/llvm-project/pull/134150 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)
@@ -778,28 +817,121 @@ llvm::Error DAP::Disconnect(bool terminateDebuggee) { return ToError(error); } +bool DAP::IsCancelled(const protocol::Request &req) { + std::lock_guard lock(m_cancelled_requests_mutex); + return m_cancelled_requests.contains(req.seq); +} + +void DAP::ClearCancelRequest(const CancelArguments &args) { + std::lock_guard cancalled_requests_lock( + m_cancelled_requests_mutex); + if (args.requestId) +m_cancelled_requests.erase(*args.requestId); +} + +template +static std::optional getArgumentsIfRequest(const Message &pm, + llvm::StringLiteral command) { + auto *const req = std::get_if(&pm); + if (!req || req->command != command) +return std::nullopt; + + T args; + llvm::json::Path::Root root; + if (!fromJSON(req->arguments, args, root)) { +return std::nullopt; + } + + return std::move(args); +} + llvm::Error DAP::Loop() { - auto cleanup = llvm::make_scope_exit([this]() { + std::future queue_reader = std::async([&]() -> llvm::Error { ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)
@@ -778,28 +817,121 @@ llvm::Error DAP::Disconnect(bool terminateDebuggee) { return ToError(error); } +bool DAP::IsCancelled(const protocol::Request &req) { + std::lock_guard lock(m_cancelled_requests_mutex); + return m_cancelled_requests.contains(req.seq); +} + +void DAP::ClearCancelRequest(const CancelArguments &args) { + std::lock_guard cancalled_requests_lock( ashgti wrote: I noticed in a few different places the naming was 'guard' for the lock_guard variable. Swapped all my variables to 'guard' instead. https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)
compnerd wrote: I think that a fully symbolicated stack trace would be very helpful. It might explain the reason for the precondition. https://github.com/llvm/llvm-project/pull/134150 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Move CPlusPlusLanguage methods used in Core/Module.cpp to a separated module to break lldb-server dependencies (PR #132274)
https://github.com/slydiman updated https://github.com/llvm/llvm-project/pull/132274 >From ba94c683a3d652a14a13313653bc70d5430e7b83 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev Date: Thu, 20 Mar 2025 21:50:51 +0400 Subject: [PATCH] [LLDB] Refactor Module::LookupInfo constructor and move out CPlusPlusLanguage::MethodName to break lldb-server dependencies This patch addresses the issue #129543. After this patch the size of lldb-server is reduced by 9MB. Based on https://github.com/swiftlang/llvm-project/pull/3240 by @bulbazord Alex Langford --- lldb/include/lldb/Target/Language.h | 5 + lldb/source/Core/CMakeLists.txt | 1 - lldb/source/Core/Module.cpp | 130 lldb/source/Core/RichManglingContext.cpp | 2 +- .../Clang/ClangExpressionDeclMap.cpp | 11 +- lldb/source/Plugins/Language/CMakeLists.txt | 2 + .../Plugins/Language/CPlusPlus/CMakeLists.txt | 1 + .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 294 ++ .../Language/CPlusPlus/CPlusPlusLanguage.h| 91 +- .../CPlusPlus/CPlusPlusLanguageMethod.cpp | 279 + .../CPlusPlus/CPlusPlusLanguageMethod.h | 106 +++ .../Plugins/Language/ObjC/ObjCLanguage.cpp| 15 + .../Plugins/Language/ObjC/ObjCLanguage.h | 3 + .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 6 +- .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 4 +- 15 files changed, 510 insertions(+), 440 deletions(-) create mode 100644 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.cpp create mode 100644 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.h diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h index b699a90aff8e4..d095499bd596e 100644 --- a/lldb/include/lldb/Target/Language.h +++ b/lldb/include/lldb/Target/Language.h @@ -214,6 +214,11 @@ class Language : public PluginInterface { return std::vector(); }; + virtual std::pair + GetFunctionNameInfo(ConstString name) const { +return std::pair{lldb::eFunctionNameTypeNone, llvm::StringRef()}; + }; + /// Returns true iff the given symbol name is compatible with the mangling /// scheme of this language. /// diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 0a08da0fec230..62390104cd588 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -72,7 +72,6 @@ add_lldb_library(lldbCore lldbValueObject lldbVersion lldbPluginCPlusPlusLanguage -lldbPluginObjCLanguage ${LLDB_CURSES_LIBS} CLANG_LIBS diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 53dc6fcde0381..43635b7e31ca4 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -52,8 +52,7 @@ #include "lldb/Host/windows/PosixApi.h" #endif -#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" -#include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Compiler.h" @@ -641,98 +640,75 @@ void Module::FindCompileUnits(const FileSpec &path, Module::LookupInfo::LookupInfo(ConstString name, FunctionNameType name_type_mask, LanguageType language) -: m_name(name), m_lookup_name(), m_language(language) { - const char *name_cstr = name.GetCString(); +: m_name(name), m_lookup_name(name), m_language(language) { llvm::StringRef basename; - llvm::StringRef context; + + std::vector languages; + auto collect_language_plugins = [&languages](Language *lang) { +languages.push_back(lang); +return true; + }; if (name_type_mask & eFunctionNameTypeAuto) { -if (CPlusPlusLanguage::IsCPPMangledName(name_cstr)) - m_name_type_mask = eFunctionNameTypeFull; -else if ((language == eLanguageTypeUnknown || - Language::LanguageIsObjC(language)) && - ObjCLanguage::IsPossibleObjCMethodName(name_cstr)) - m_name_type_mask = eFunctionNameTypeFull; -else if (Language::LanguageIsC(language)) { - m_name_type_mask = eFunctionNameTypeFull; +if (language == eLanguageTypeUnknown) { + Language::ForEach(collect_language_plugins); + for (Language *lang : languages) { +auto info = lang->GetFunctionNameInfo(name); +if (info.first != eFunctionNameTypeNone) { + m_name_type_mask |= info.first; + basename = info.second; + break; +} + } } else { - if ((language == eLanguageTypeUnknown || - Language::LanguageIsObjC(language)) && - ObjCLanguage::IsPossibleObjCSelector(name_cstr)) -m_name_type_mask |= eFunctionNameTypeSelector; - - CPlusPlusLanguage::MethodName cpp_method(name); - basename = cpp_method.GetBasename(); - if (basename.empty()) { -if (CPlusPlusLanguage::ExtractContextAndIdentifie
[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)
SuibianP wrote: Pinging @ashgti and @walter-erquinigo for review before I forget again https://github.com/llvm/llvm-project/pull/121269 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5f99e0d - [lldb] Use the "reverse video" effect when colors are disabled. (#134203)
Author: Jonas Devlieghere Date: 2025-04-03T13:51:17-07:00 New Revision: 5f99e0d4b9ea071e29a9cba75619d26811ff76c2 URL: https://github.com/llvm/llvm-project/commit/5f99e0d4b9ea071e29a9cba75619d26811ff76c2 DIFF: https://github.com/llvm/llvm-project/commit/5f99e0d4b9ea071e29a9cba75619d26811ff76c2.diff LOG: [lldb] Use the "reverse video" effect when colors are disabled. (#134203) When you run lldb without colors (`-X`), the status line looks weird because it doesn't have a background. You end up with what appears to be floating text at the bottom of your terminal. This patch changes the statusline to use the reverse video effect, even when colors are off. The effect doesn't introduce any new colors and just inverts the foreground and background color. I considered an alternative approach which changes the behavior of the `-X` option, so that turning off colors doesn't prevent emitting non-color related control characters such as bold, underline, and reverse video. I decided to go with this more targeted fix as (1) nobody is asking for this more general change and (2) it introduces significant complexity to plumb this through using a setting and driver flag so that it can be disabled when running the tests. Fixes #134112. Added: Modified: lldb/source/Core/Statusline.cpp lldb/test/API/functionalities/statusline/TestStatusline.py Removed: diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index c18fbb6c5561e..b7650503e16bc 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -27,6 +27,7 @@ #define ANSI_CLEAR_LINE ESCAPE "[2K" #define ANSI_SET_SCROLL_ROWS ESCAPE "[0;%ur" #define ANSI_TO_START_OF_ROW ESCAPE "[%u;0f" +#define ANSI_REVERSE_VIDEO ESCAPE "[7m" #define ANSI_UP_ROWS ESCAPE "[%dA" using namespace lldb; @@ -74,6 +75,12 @@ void Statusline::Draw(std::string str) { locked_stream << ANSI_SAVE_CURSOR; locked_stream.Printf(ANSI_TO_START_OF_ROW, static_cast(m_terminal_height)); + + // Use "reverse video" to make sure the statusline has a background. Only do + // this when colors are disabled, and rely on the statusline format otherwise. + if (!m_debugger.GetUseColor()) +locked_stream << ANSI_REVERSE_VIDEO; + locked_stream << str; locked_stream << ANSI_NORMAL; locked_stream << ANSI_RESTORE_CURSOR; diff --git a/lldb/test/API/functionalities/statusline/TestStatusline.py b/lldb/test/API/functionalities/statusline/TestStatusline.py index a58dc5470ed6d..747a7a14e0629 100644 --- a/lldb/test/API/functionalities/statusline/TestStatusline.py +++ b/lldb/test/API/functionalities/statusline/TestStatusline.py @@ -55,3 +55,25 @@ def test(self): self.expect( "set set show-statusline false", ["\x1b[0;{}r".format(terminal_height)] ) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +def test_no_color(self): +"""Basic test for the statusline with colors disabled.""" +self.build() +self.launch(use_colors=False) +self.do_setup() + +# Change the terminal dimensions. +terminal_height = 10 +terminal_width = 60 +self.child.setwinsize(terminal_height, terminal_width) + +# Enable the statusline and check for the "reverse video" control character. +self.expect( +"set set show-statusline true", +[ +"\x1b[7m", +], +) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] bec5cfd - [lldb-dap] Protect SetBreakpoint with the API mutex (#134030)
Author: Jonas Devlieghere Date: 2025-04-03T09:08:23-07:00 New Revision: bec5cfd970c5882c54a9e8d9f3da430dc39d0dd0 URL: https://github.com/llvm/llvm-project/commit/bec5cfd970c5882c54a9e8d9f3da430dc39d0dd0 DIFF: https://github.com/llvm/llvm-project/commit/bec5cfd970c5882c54a9e8d9f3da430dc39d0dd0.diff LOG: [lldb-dap] Protect SetBreakpoint with the API mutex (#134030) Protect the various SetBreakpoint functions with the API mutex. This fixes a race condition between the breakpoint being created and the DAP label getting added. This was causing `TestDAP_breakpointEvents.py` to be flaky. Fixes #131242. Added: Modified: lldb/tools/lldb-dap/Breakpoint.cpp lldb/tools/lldb-dap/DAP.h lldb/tools/lldb-dap/ExceptionBreakpoint.cpp lldb/tools/lldb-dap/FunctionBreakpoint.cpp lldb/tools/lldb-dap/SourceBreakpoint.cpp Removed: diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index e02f62076f935..5679fd545d53f 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -7,14 +7,17 @@ //===--===// #include "Breakpoint.h" +#include "DAP.h" #include "JSONUtils.h" #include "lldb/API/SBAddress.h" #include "lldb/API/SBBreakpointLocation.h" #include "lldb/API/SBLineEntry.h" +#include "lldb/API/SBMutex.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/JSON.h" #include #include +#include #include using namespace lldb_dap; @@ -74,6 +77,9 @@ bool Breakpoint::MatchesName(const char *name) { } void Breakpoint::SetBreakpoint() { + lldb::SBMutex lock = m_dap.GetAPIMutex(); + std::lock_guard guard(lock); + m_bp.AddName(kDAPBreakpointLabel); if (!m_condition.empty()) SetCondition(); diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index 4357bdd5cc80f..3ce6498632479 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -27,6 +27,7 @@ #include "lldb/API/SBFile.h" #include "lldb/API/SBFormat.h" #include "lldb/API/SBFrame.h" +#include "lldb/API/SBMutex.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBValue.h" @@ -404,6 +405,8 @@ struct DAP { InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread); + + lldb::SBMutex GetAPIMutex() const { return target.GetAPIMutex(); } }; } // namespace lldb_dap diff --git a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp index d8109daf89129..9772e7344ced6 100644 --- a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp +++ b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp @@ -9,11 +9,16 @@ #include "ExceptionBreakpoint.h" #include "BreakpointBase.h" #include "DAP.h" +#include "lldb/API/SBMutex.h" #include "lldb/API/SBTarget.h" +#include namespace lldb_dap { void ExceptionBreakpoint::SetBreakpoint() { + lldb::SBMutex lock = m_dap.GetAPIMutex(); + std::lock_guard guard(lock); + if (m_bp.IsValid()) return; bool catch_value = m_filter.find("_catch") != std::string::npos; diff --git a/lldb/tools/lldb-dap/FunctionBreakpoint.cpp b/lldb/tools/lldb-dap/FunctionBreakpoint.cpp index 2fb6e8fafc2fa..d87723f7557bd 100644 --- a/lldb/tools/lldb-dap/FunctionBreakpoint.cpp +++ b/lldb/tools/lldb-dap/FunctionBreakpoint.cpp @@ -9,6 +9,8 @@ #include "FunctionBreakpoint.h" #include "DAP.h" #include "JSONUtils.h" +#include "lldb/API/SBMutex.h" +#include namespace lldb_dap { @@ -17,6 +19,9 @@ FunctionBreakpoint::FunctionBreakpoint(DAP &d, const llvm::json::Object &obj) m_function_name(std::string(GetString(obj, "name").value_or(""))) {} void FunctionBreakpoint::SetBreakpoint() { + lldb::SBMutex lock = m_dap.GetAPIMutex(); + std::lock_guard guard(lock); + if (m_function_name.empty()) return; m_bp = m_dap.target.BreakpointCreateByName(m_function_name.c_str()); diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.cpp b/lldb/tools/lldb-dap/SourceBreakpoint.cpp index 150fa6af44d3a..6d8d3470668c8 100644 --- a/lldb/tools/lldb-dap/SourceBreakpoint.cpp +++ b/lldb/tools/lldb-dap/SourceBreakpoint.cpp @@ -13,6 +13,7 @@ #include "lldb/API/SBBreakpoint.h" #include "lldb/API/SBFileSpecList.h" #include "lldb/API/SBFrame.h" +#include "lldb/API/SBMutex.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBValue.h" @@ -20,6 +21,7 @@ #include #include #include +#include #include namespace lldb_dap { @@ -33,6 +35,9 @@ SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj) .value_or(LLDB_INVALID_COLUMN_NUMBER)) {} void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) { + lldb::SBMutex lock = m_dap.GetAPIMutex(); + std::lock_guard guard(lock); + lldb::SB
[Lldb-commits] [lldb] f1c6612 - [lldb][debugserver] Save and restore the SVE/SME register state (#134184)
Author: Jason Molenda Date: 2025-04-03T15:48:54-07:00 New Revision: f1c6612202d88cbde224387621327a31609f2177 URL: https://github.com/llvm/llvm-project/commit/f1c6612202d88cbde224387621327a31609f2177 DIFF: https://github.com/llvm/llvm-project/commit/f1c6612202d88cbde224387621327a31609f2177.diff LOG: [lldb][debugserver] Save and restore the SVE/SME register state (#134184) debugserver isn't saving and restoring the SVE/SME register state around inferior function calls. Making arbitrary function calls while in Streaming SVE mode is generally a poor idea because a NEON instruction can be hit and crash the expression execution, which is how I missed this, but they should be handled correctly if the user knows it is safe to do. Re-landing this change after fixing an incorrect behavior on systems without SME support. rdar://146886210 Added: Modified: lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp Removed: diff --git a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp index 34a4ee21f8502..6ee1466612ee1 100644 --- a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp +++ b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp @@ -2952,8 +2952,15 @@ kern_return_t DNBArchMachARM64::SetRegisterState(int set) { return err; switch (set) { - case e_regSetALL: -return SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); + case e_regSetALL: { +kern_return_t ret = +SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false); +if (CPUHasSME()) { + SetSVEState(); + SetSMEState(); +} +return ret; + } case e_regSetGPR: return SetGPRState(); case e_regSetVFP: @@ -3123,6 +3130,12 @@ uint32_t DNBArchMachARM64::SaveRegisterState() { "error: %s regs failed to read: %u", "VFP", kret); } else { +if (CPUHasSME()) { + // These can fail when processor is not in streaming SVE mode, + // and that failure should be ignored. + GetSVEState(force); + GetSMEState(force); +} const uint32_t save_id = GetNextRegisterStateSaveID(); m_saved_register_states[save_id] = m_state.context; return save_id; @@ -3150,6 +3163,12 @@ bool DNBArchMachARM64::RestoreRegisterState(uint32_t save_id) { save_id, "VFP", kret); success = false; } +if (CPUHasSME()) { + // These can fail when processor is not in streaming SVE mode, + // and that failure should be ignored. + SetSVEState(); + SetSMEState(); +} m_saved_register_states.erase(pos); return success; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][debugserver] Fix an off-by-one error in watchpoint identification (PR #134314)
https://github.com/jasonmolenda edited https://github.com/llvm/llvm-project/pull/134314 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)
ktraunmueller wrote: @compnerd weighed in that assertions [are always there for a reason](https://github.com/swiftlang/llvm-project/issues/10269#issuecomment-2772945096), and I would generally agree on that 100%, but this precondition just doesn't seem to make sense, so I would agree that removing it would seem preferrable in this particular case. I can't see how that would create harm. https://github.com/llvm/llvm-project/pull/134150 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Wanyi (kusmour) Changes Recently upon debugging a program with thousands of threads in VS Code, lldb-dap would hang at a `threads` request sent right after receiving the `configurationDone` response. Soon after it will end the debug session with the following error ``` Processexited with status = -1 (0x) lost connection ``` This is because LLDB is still in the middle of resuming all the threads. And requesting threads will require stopping the process. From the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid` and just exit with status -1. I don't think it's reasonable to allow getting threads from a running process. The alternative will be reject the `threads` request if the process is not stopped. --- Full diff: https://github.com/llvm/llvm-project/pull/134339.diff 2 Files Affected: - (added) lldb/test/API/tools/lldb-dap/attach/multithreading.cpp (+102) - (modified) lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp (+5-3) ``diff diff --git a/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp new file mode 100644 index 0..0e9c340916ece --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include +#include + +int plus_one(int n) { + std::cout << "In plus_one" << std::endl; + return n + 1; +} + +class ThreadPool { + public: + ThreadPool(size_t num_threads = std::thread::hardware_concurrency()) { +for (uint32_t i = 0; i < num_threads; ++i) { + threads.emplace_back(std::thread(&ThreadPool::ThreadLoop, this)); +} + } + ~ThreadPool() { +{ + std::unique_lock lock(queue_mutex); + terminated = true; +} +condition.notify_all(); +for (std::thread& thread : threads) { + thread.join(); +} + } + void enqueue(const std::function& job) { +{ + std::unique_lock lock(queue_mutex); + if (terminated) +throw std::runtime_error("enqueue on stopped ThreadPool"); + jobs.push(job); +} +condition.notify_one(); + } + + private: + void ThreadLoop() { +while (true) { + std::function job; + { +std::unique_lock lock(queue_mutex); +condition.wait(lock, [this] { return !jobs.empty() || terminated; }); +if (terminated && jobs.empty()) + return; +job = jobs.front(); +jobs.pop(); + } + job(); +} + } + + bool terminated = false; + std::mutex queue_mutex; + std::condition_variable condition; + std::vector threads; + std::queue> jobs; +}; + +void thread_func(int job_index) { + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") running on thread " << std::this_thread::get_id() << "\n"; + std::cout << "Calling function plus_one(int)\nResult = " +<< plus_one(job_index) << "\n"; +} + +void thread_sleep(int job_index, int sleep_sec) { + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") starting on thread " << std::this_thread::get_id() << "\n"; + std::this_thread::sleep_for(std::chrono::seconds(sleep_sec)); + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") finished on thread " << std::this_thread::get_id() << "\n"; +} + +int main() { + ThreadPool tp1(2000); + ThreadPool tp2; + std::cout << "main() running on thread " << std::this_thread::get_id() +<< "\n"; + std::cout + << "Program is expecting stdin. Please attach debugger and hit enter to continue\n"; + std::cin.get(); + // At least one of the thread in tp1 will be sceduled with a task twice or + // more if num_jobs is larger than #threads in tp1. + int num_jobs = 3000; + for (int i = 0; i < num_jobs; ++i) { +tp1.enqueue(std::bind(thread_func, i)); + } + // We may or may not hit the breakpoint thread_sleep here, as the tread pool + // might finish executing before debugger release the bp for tp1. + // To make sure we hit the bp, we can increase the sleep time in the call. + for (int i = 0; i < num_jobs; ++i) { +tp2.enqueue([i] { thread_sleep(i, 1); }); + } + for (int i = 0; i < num_jobs; ++i) { +tp1.enqueue(std::bind(thread_sleep, i, 1)); +return 0; + } +} diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 5e622f3d3dcd4..aa7f3c0d57f9d 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -73,9 +73,11 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { llvm::StringRef core_file = GetString(arguments, "coreFile").value_or(""); const uint64_t timeout_seconds = GetInteger(arguments, "timeout").value_or(30); - dap.stop_at_entry = core_file.empty() - ? GetBoolean(arguments, "stopOnEntr
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
https://github.com/kusmour created https://github.com/llvm/llvm-project/pull/134339 Recently upon debugging a program with thousands of threads in VS Code, lldb-dap would hang at a `threads` request sent right after receiving the `configurationDone` response. Soon after it will end the debug session with the following error ``` Process exited with status = -1 (0x) lost connection ``` This is because LLDB is still in the middle of resuming all the threads. And requesting threads will require stopping the process. From the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid` and just exit with status -1. I don't think it's reasonable to allow getting threads from a running process. The alternative will be reject the `threads` request if the process is not stopped. >From ba228574dac4facebf8efed2b624ed744e4f6e91 Mon Sep 17 00:00:00 2001 From: Wanyi Ye Date: Thu, 3 Apr 2025 21:02:04 -0400 Subject: [PATCH] [lldb-dap] Always stop on enrty for attaching Recently upon debugging a program with thousands of threads, lldb-dap would hang at a `threads` request sent right after receiving the `configurationDone` response. Soon after it will end the debug session with "Process ex ited with status = -1 (0x) lost connection". This is because LLDB is still in the middle of resuming all the threads. And requesting threads will require stopp ing the process. From the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid` and just exit with s tatus -1. I don't think it's reasonable to allow getting threads from a running process. The alternative will be reject the `threads` request if the process is not stopped. --- .../tools/lldb-dap/attach/multithreading.cpp | 102 ++ .../lldb-dap/Handler/AttachRequestHandler.cpp | 8 +- 2 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/attach/multithreading.cpp diff --git a/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp new file mode 100644 index 0..0e9c340916ece --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include +#include + +int plus_one(int n) { + std::cout << "In plus_one" << std::endl; + return n + 1; +} + +class ThreadPool { + public: + ThreadPool(size_t num_threads = std::thread::hardware_concurrency()) { +for (uint32_t i = 0; i < num_threads; ++i) { + threads.emplace_back(std::thread(&ThreadPool::ThreadLoop, this)); +} + } + ~ThreadPool() { +{ + std::unique_lock lock(queue_mutex); + terminated = true; +} +condition.notify_all(); +for (std::thread& thread : threads) { + thread.join(); +} + } + void enqueue(const std::function& job) { +{ + std::unique_lock lock(queue_mutex); + if (terminated) +throw std::runtime_error("enqueue on stopped ThreadPool"); + jobs.push(job); +} +condition.notify_one(); + } + + private: + void ThreadLoop() { +while (true) { + std::function job; + { +std::unique_lock lock(queue_mutex); +condition.wait(lock, [this] { return !jobs.empty() || terminated; }); +if (terminated && jobs.empty()) + return; +job = jobs.front(); +jobs.pop(); + } + job(); +} + } + + bool terminated = false; + std::mutex queue_mutex; + std::condition_variable condition; + std::vector threads; + std::queue> jobs; +}; + +void thread_func(int job_index) { + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") running on thread " << std::this_thread::get_id() << "\n"; + std::cout << "Calling function plus_one(int)\nResult = " +<< plus_one(job_index) << "\n"; +} + +void thread_sleep(int job_index, int sleep_sec) { + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") starting on thread " << std::this_thread::get_id() << "\n"; + std::this_thread::sleep_for(std::chrono::seconds(sleep_sec)); + std::cout << __FUNCTION__ << " (job index = " << job_index +<< ") finished on thread " << std::this_thread::get_id() << "\n"; +} + +int main() { + ThreadPool tp1(2000); + ThreadPool tp2; + std::cout << "main() running on thread " << std::this_thread::get_id() +<< "\n"; + std::cout + << "Program is expecting stdin. Please attach debugger and hit enter to continue\n"; + std::cin.get(); + // At least one of the thread in tp1 will be sceduled with a task twice or + // more if num_jobs is larger than #threads in tp1. + int num_jobs = 3000; + for (int i = 0; i < num_jobs; ++i) { +tp1.enqueue(std::bind(thread_func, i)); + } + // We may or may not hit the breakpoint thread_sleep here, as the tread pool + // might finish executing before debugger release the bp for tp1. + // To make sure we hit the bp, we can increase the s
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp -- lldb/test/API/tools/lldb-dap/attach/multithreading.cpp lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp index 0e9c34091..ae75c503c 100644 --- a/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp +++ b/lldb/test/API/tools/lldb-dap/attach/multithreading.cpp @@ -11,7 +11,7 @@ int plus_one(int n) { } class ThreadPool { - public: +public: ThreadPool(size_t num_threads = std::thread::hardware_concurrency()) { for (uint32_t i = 0; i < num_threads; ++i) { threads.emplace_back(std::thread(&ThreadPool::ThreadLoop, this)); @@ -23,11 +23,11 @@ class ThreadPool { terminated = true; } condition.notify_all(); -for (std::thread& thread : threads) { +for (std::thread &thread : threads) { thread.join(); } } - void enqueue(const std::function& job) { + void enqueue(const std::function &job) { { std::unique_lock lock(queue_mutex); if (terminated) @@ -37,7 +37,7 @@ class ThreadPool { condition.notify_one(); } - private: +private: void ThreadLoop() { while (true) { std::function job; @@ -80,8 +80,8 @@ int main() { ThreadPool tp2; std::cout << "main() running on thread " << std::this_thread::get_id() << "\n"; - std::cout - << "Program is expecting stdin. Please attach debugger and hit enter to continue\n"; + std::cout << "Program is expecting stdin. Please attach debugger and hit " + "enter to continue\n"; std::cin.get(); // At least one of the thread in tp1 will be sceduled with a task twice or // more if num_jobs is larger than #threads in tp1. `` https://github.com/llvm/llvm-project/pull/134339 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (PR #127505)
dlav-sc wrote: > It matches only one of many possible lr.[wd]/sc.[wd] sequences. I was confused too when I saw this for the first time. I expected to see a processing a sequence of integer instructions between lr and sc. This patch was enough to fix my issue, so I decided to bring it here as is. However, I'm now thinking I could try to do something more comprehensive and support any possible sequence of instructions. > Why isn't there a a call to m_emu.WriteMem in the implementation? >From what I understand, it's not a real simulator. This is used in lldb for >software stepping to determine where to set a breakpoint. lldb needs to >emulate the instruction to obtain next PC. https://github.com/llvm/llvm-project/pull/127505 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Expose checking if the symbol file exists/is loaded via SBModule (PR #134163)
clayborg wrote: Just a quick comment here for this: ``` /// Get if the symbol file for this module is loaded. bool IsDebugInfoLoaded() const; ``` This isn't clear what it is returning. What it seems like it should be returning from the name is "are there debug symbols in this module. But what is actually exposed should be more like: ``` /// Return true if the debug symbols are fully enabled. /// /// Symbols on demand might end up disabling debug info until /// a query is made that requires debug information from this module /// and this function will return false if debug information has been /// disabled in this way. bool IsDebugInfoEnabled() const; ``` The new API added as is seems like we are saying "is there some debug info in the symbol file". But this will always return true unless symbols on demand is restricting debug info access. If we have a "a.out" binary that has no debug info, it will have a "SymbolFileSymtab" and with no debug info and it will return true because it has a symbol file and it isn't restricted by symbols on demand. Can we revert this and switch to my above suggestion if everyone agrees? https://github.com/llvm/llvm-project/pull/134163 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap 'launch' request to use typed RequestHandler<>. (PR #133624)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/133624 >From 3240fe49515e5f59c5b9ff9c02423b77504d8a43 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 28 Mar 2025 14:02:53 -0700 Subject: [PATCH 1/4] [lldb-dap] Refactoring lldb-dap 'launch' request to use typed RequestHandler<>. This converts a number of json::Value's into well defined types that are used throughout lldb-dap and updates the 'launch' command to use the new well defined types. --- .../test/tools/lldb-dap/dap_server.py | 3 +- .../test/tools/lldb-dap/lldbdap_testcase.py | 2 +- .../tools/lldb-dap/launch/TestDAP_launch.py | 6 +- .../restart/TestDAP_restart_runInTerminal.py | 4 +- .../runInTerminal/TestDAP_runInTerminal.py| 16 +- lldb/tools/lldb-dap/DAP.cpp | 82 +--- lldb/tools/lldb-dap/DAP.h | 44 +++-- .../lldb-dap/Handler/AttachRequestHandler.cpp | 33 ++-- .../lldb-dap/Handler/CompletionsHandler.cpp | 7 +- .../Handler/EvaluateRequestHandler.cpp| 3 +- .../lldb-dap/Handler/LaunchRequestHandler.cpp | 118 +++- .../tools/lldb-dap/Handler/RequestHandler.cpp | 96 +- lldb/tools/lldb-dap/Handler/RequestHandler.h | 19 +- .../Handler/RestartRequestHandler.cpp | 54 -- .../Handler/SetVariableRequestHandler.cpp | 3 +- .../Handler/StackTraceRequestHandler.cpp | 2 +- .../Handler/VariablesRequestHandler.cpp | 20 +- lldb/tools/lldb-dap/JSONUtils.cpp | 48 ++--- lldb/tools/lldb-dap/JSONUtils.h | 11 +- .../lldb-dap/Protocol/ProtocolRequests.cpp| 175 +- .../lldb-dap/Protocol/ProtocolRequests.h | 150 +++ lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 +- 22 files changed, 616 insertions(+), 286 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 01ef4b68f2653..6e13fcddcc933 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -862,7 +862,8 @@ def request_launch( args_dict["enableAutoVariableSummaries"] = enableAutoVariableSummaries args_dict["enableSyntheticChildDebugging"] = enableSyntheticChildDebugging args_dict["displayExtendedBacktrace"] = displayExtendedBacktrace -args_dict["commandEscapePrefix"] = commandEscapePrefix +if commandEscapePrefix: +args_dict["commandEscapePrefix"] = commandEscapePrefix command_dict = {"command": "launch", "type": "request", "arguments": args_dict} response = self.send_recv(command_dict) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 70b04b051e0ec..9ab8a905a79dd 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -443,7 +443,7 @@ def cleanup(): if not (response and response["success"]): self.assertTrue( -response["success"], "launch failed (%s)" % (response["message"]) +response["success"], "launch failed (%s)" % (response["body"]["error"]["format"]) ) return response diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 64c99019a1c9b..c6a3e9cc879a4 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -41,7 +41,9 @@ def test_termination(self): self.dap_server.request_disconnect() # Wait until the underlying lldb-dap process dies. - self.dap_server.process.wait(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval) +self.dap_server.process.wait( +timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval +) # Check the return code self.assertEqual(self.dap_server.process.poll(), 0) @@ -459,7 +461,7 @@ def test_failing_launch_commands(self): self.assertFalse(response["success"]) self.assertRegex( -response["message"], +response["body"]["error"]["format"], r"Failed to run launch commands\. See the Debug Console for more details", ) diff --git a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py index 5a9938c25c2c8..a94c9860c1508 100644 --- a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py +++ b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py @@ -21,7 +21,7 @@ def isTestSupported(self): return False @skipIfWindows -@skipIf(archs=["arm"]) #
[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap 'launch' request to use typed RequestHandler<>. (PR #133624)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/133624 >From 3240fe49515e5f59c5b9ff9c02423b77504d8a43 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 28 Mar 2025 14:02:53 -0700 Subject: [PATCH 1/3] [lldb-dap] Refactoring lldb-dap 'launch' request to use typed RequestHandler<>. This converts a number of json::Value's into well defined types that are used throughout lldb-dap and updates the 'launch' command to use the new well defined types. --- .../test/tools/lldb-dap/dap_server.py | 3 +- .../test/tools/lldb-dap/lldbdap_testcase.py | 2 +- .../tools/lldb-dap/launch/TestDAP_launch.py | 6 +- .../restart/TestDAP_restart_runInTerminal.py | 4 +- .../runInTerminal/TestDAP_runInTerminal.py| 16 +- lldb/tools/lldb-dap/DAP.cpp | 82 +--- lldb/tools/lldb-dap/DAP.h | 44 +++-- .../lldb-dap/Handler/AttachRequestHandler.cpp | 33 ++-- .../lldb-dap/Handler/CompletionsHandler.cpp | 7 +- .../Handler/EvaluateRequestHandler.cpp| 3 +- .../lldb-dap/Handler/LaunchRequestHandler.cpp | 118 +++- .../tools/lldb-dap/Handler/RequestHandler.cpp | 96 +- lldb/tools/lldb-dap/Handler/RequestHandler.h | 19 +- .../Handler/RestartRequestHandler.cpp | 54 -- .../Handler/SetVariableRequestHandler.cpp | 3 +- .../Handler/StackTraceRequestHandler.cpp | 2 +- .../Handler/VariablesRequestHandler.cpp | 20 +- lldb/tools/lldb-dap/JSONUtils.cpp | 48 ++--- lldb/tools/lldb-dap/JSONUtils.h | 11 +- .../lldb-dap/Protocol/ProtocolRequests.cpp| 175 +- .../lldb-dap/Protocol/ProtocolRequests.h | 150 +++ lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 +- 22 files changed, 616 insertions(+), 286 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 01ef4b68f2653..6e13fcddcc933 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -862,7 +862,8 @@ def request_launch( args_dict["enableAutoVariableSummaries"] = enableAutoVariableSummaries args_dict["enableSyntheticChildDebugging"] = enableSyntheticChildDebugging args_dict["displayExtendedBacktrace"] = displayExtendedBacktrace -args_dict["commandEscapePrefix"] = commandEscapePrefix +if commandEscapePrefix: +args_dict["commandEscapePrefix"] = commandEscapePrefix command_dict = {"command": "launch", "type": "request", "arguments": args_dict} response = self.send_recv(command_dict) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 70b04b051e0ec..9ab8a905a79dd 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -443,7 +443,7 @@ def cleanup(): if not (response and response["success"]): self.assertTrue( -response["success"], "launch failed (%s)" % (response["message"]) +response["success"], "launch failed (%s)" % (response["body"]["error"]["format"]) ) return response diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 64c99019a1c9b..c6a3e9cc879a4 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -41,7 +41,9 @@ def test_termination(self): self.dap_server.request_disconnect() # Wait until the underlying lldb-dap process dies. - self.dap_server.process.wait(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval) +self.dap_server.process.wait( +timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval +) # Check the return code self.assertEqual(self.dap_server.process.poll(), 0) @@ -459,7 +461,7 @@ def test_failing_launch_commands(self): self.assertFalse(response["success"]) self.assertRegex( -response["message"], +response["body"]["error"]["format"], r"Failed to run launch commands\. See the Debug Console for more details", ) diff --git a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py index 5a9938c25c2c8..a94c9860c1508 100644 --- a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py +++ b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py @@ -21,7 +21,7 @@ def isTestSupported(self): return False @skipIfWindows -@skipIf(archs=["arm"]) #
[Lldb-commits] [lldb] [LLDB][NFC]Fix stack-use-after free bug. (PR #134296)
https://github.com/oontvoo created https://github.com/llvm/llvm-project/pull/134296 Details: detailed_command_telemetry (bool) and command_id (int) could already be freed when the dispatcher's dtor runs. So we should just copy them into the lambda since they are cheap. >From 96025fd1183f257c52ed889e882c808dd44e129a Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Thu, 3 Apr 2025 15:28:22 -0400 Subject: [PATCH] [LLDB][NFC]Fix stack-use-after free bug. Details: detailed_command_telemetry (bool) and command_id (int) could already be freed when the dispatcher's dtor runs. So we should just copy them into the lambda since they are cheap. --- lldb/source/Interpreter/CommandInterpreter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 949b1191c28f0..112d2f20fda41 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1918,7 +1918,9 @@ bool CommandInterpreter::HandleCommand(const char *command_line, // Those will be collected by the on-exit-callback. }); - helper.DispatchOnExit([&](lldb_private::telemetry::CommandInfo *info) { + helper.DispatchOnExit([&cmd_obj, &parsed_command_args, &result, + detailed_command_telemetry, command_id]( +lldb_private::telemetry::CommandInfo *info) { // TODO: this is logging the time the command-handler finishes. // But we may want a finer-grain durations too? // (ie., the execute_time recorded below?) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC]Fix stack-use-after free bug. (PR #134296)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Vy Nguyen (oontvoo) Changes Details: detailed_command_telemetry (bool) and command_id (int) could already be freed when the dispatcher's dtor runs. So we should just copy them into the lambda since they are cheap. --- Full diff: https://github.com/llvm/llvm-project/pull/134296.diff 1 Files Affected: - (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+3-1) ``diff diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 949b1191c28f0..112d2f20fda41 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1918,7 +1918,9 @@ bool CommandInterpreter::HandleCommand(const char *command_line, // Those will be collected by the on-exit-callback. }); - helper.DispatchOnExit([&](lldb_private::telemetry::CommandInfo *info) { + helper.DispatchOnExit([&cmd_obj, &parsed_command_args, &result, + detailed_command_telemetry, command_id]( +lldb_private::telemetry::CommandInfo *info) { // TODO: this is logging the time the command-handler finishes. // But we may want a finer-grain durations too? // (ie., the execute_time recorded below?) `` https://github.com/llvm/llvm-project/pull/134296 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
https://github.com/yln created https://github.com/llvm/llvm-project/pull/134323 Add integration test for libsanitizers trace collection (`SanitizersAllocationTraces=all`). rdar://144244084 >From 8aa5e0e7f97df7627187bbd8ad4b3df51c798f4f Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Thu, 3 Apr 2025 14:47:53 -0700 Subject: [PATCH 1/2] [LLDB] Update reason for why tests are disabled --- lldb/test/API/functionalities/asan/TestMemoryHistory.py | 6 ++ lldb/test/API/functionalities/asan/TestReportData.py| 6 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py b/lldb/test/API/functionalities/asan/TestMemoryHistory.py index b04182a543719..c3f15aefb1d49 100644 --- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py +++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py @@ -19,7 +19,7 @@ def test(self): self.asan_tests() @skipIf(oslist=no_match(["macosx"])) -@skipIf(bugnumber="rdar://144997976") +@skipIf(bugnumber="rdar://109913184&143590169") def test_libsanitizers_asan(self): try: self.build(make_targets=["libsanitizers"]) @@ -39,9 +39,7 @@ def setUp(self): def libsanitizer_tests(self): target = self.createTestTarget() -self.runCmd( -"env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0" -) +self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1") self.runCmd("run") diff --git a/lldb/test/API/functionalities/asan/TestReportData.py b/lldb/test/API/functionalities/asan/TestReportData.py index fabc985d0ed44..52ae199378f3b 100644 --- a/lldb/test/API/functionalities/asan/TestReportData.py +++ b/lldb/test/API/functionalities/asan/TestReportData.py @@ -20,7 +20,7 @@ def test(self): self.asan_tests() @skipIf(oslist=no_match(["macosx"])) -@skipIf(bugnumber="rdar://144997976") +@skipIf(bugnumber="rdar://109913184&143590169") def test_libsanitizers_asan(self): try: self.build(make_targets=["libsanitizers"]) @@ -42,9 +42,7 @@ def asan_tests(self, libsanitizers=False): target = self.createTestTarget() if libsanitizers: -self.runCmd( -"env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0" -) +self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1") else: self.registerSanitizerLibrariesWithTarget(target) >From 803214e7ccb5c45a58c90951481af3570bb4be9d Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Thu, 3 Apr 2025 16:07:04 -0700 Subject: [PATCH 2/2] [LLDB] Add integration test for libsanitizers trace collection Add integration test for libsanitizers trace collection (`SanitizersAllocationTraces=all`). rdar://144244084 --- lldb/test/API/functionalities/asan/Makefile | 11 ++- .../functionalities/asan/TestMemoryHistory.py | 88 --- .../functionalities/asan/TestReportData.py| 6 +- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/lldb/test/API/functionalities/asan/Makefile b/lldb/test/API/functionalities/asan/Makefile index d66696fed7078..eae5ca3e4626c 100644 --- a/lldb/test/API/functionalities/asan/Makefile +++ b/lldb/test/API/functionalities/asan/Makefile @@ -1,8 +1,11 @@ C_SOURCES := main.c -asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info -asan: all +compiler_rt-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info +compiler_rt-asan: all -libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info -libsanitizers: all +libsanitizers-asan: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info +libsanitizers-asan: all + +libsanitizers-traces: CFLAGS_EXTRAS := -g -gcolumn-info +libsanitizers-traces: all include Makefile.rules diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py b/lldb/test/API/functionalities/asan/TestMemoryHistory.py index c3f15aefb1d49..894235481c440 100644 --- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py +++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py @@ -15,17 +15,23 @@ class AsanTestCase(TestBase): @expectedFailureNetBSD @skipUnlessAddressSanitizer def test(self): -self.build(make_targets=["asan"]) +self.build(make_targets=["compiler_rt-asan"]) self.asan_tests() -@skipIf(oslist=no_match(["macosx"])) +@skipUnlessDarwin @skipIf(bugnumber="rdar://109913184&143590169") def test_libsanitizers_asan(self): try: -self.build(make_targets=["libsanitizers"]) +self.build(make_targets=["libsanitizers-asan"]) except BuildError as e: self.skipTest("failed to build with libsanitizers") -self.libsanitizer_tests() +self.libsanitizers_asan_tests() + +@skipUnlessDarwin +@skipIf(macos_version=["<", "15.5"]) +def t
[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Julian Lettner (yln) Changes Add integration test for libsanitizers trace collection (`SanitizersAllocationTraces=all`). rdar://144244084 --- Full diff: https://github.com/llvm/llvm-project/pull/134323.diff 3 Files Affected: - (modified) lldb/test/API/functionalities/asan/Makefile (+7-4) - (modified) lldb/test/API/functionalities/asan/TestMemoryHistory.py (+58-34) - (modified) lldb/test/API/functionalities/asan/TestReportData.py (+5-7) ``diff diff --git a/lldb/test/API/functionalities/asan/Makefile b/lldb/test/API/functionalities/asan/Makefile index d66696fed7078..eae5ca3e4626c 100644 --- a/lldb/test/API/functionalities/asan/Makefile +++ b/lldb/test/API/functionalities/asan/Makefile @@ -1,8 +1,11 @@ C_SOURCES := main.c -asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info -asan: all +compiler_rt-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info +compiler_rt-asan: all -libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info -libsanitizers: all +libsanitizers-asan: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g -gcolumn-info +libsanitizers-asan: all + +libsanitizers-traces: CFLAGS_EXTRAS := -g -gcolumn-info +libsanitizers-traces: all include Makefile.rules diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py b/lldb/test/API/functionalities/asan/TestMemoryHistory.py index b04182a543719..894235481c440 100644 --- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py +++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py @@ -15,17 +15,23 @@ class AsanTestCase(TestBase): @expectedFailureNetBSD @skipUnlessAddressSanitizer def test(self): -self.build(make_targets=["asan"]) +self.build(make_targets=["compiler_rt-asan"]) self.asan_tests() -@skipIf(oslist=no_match(["macosx"])) -@skipIf(bugnumber="rdar://144997976") +@skipUnlessDarwin +@skipIf(bugnumber="rdar://109913184&143590169") def test_libsanitizers_asan(self): try: -self.build(make_targets=["libsanitizers"]) +self.build(make_targets=["libsanitizers-asan"]) except BuildError as e: self.skipTest("failed to build with libsanitizers") -self.libsanitizer_tests() +self.libsanitizers_asan_tests() + +@skipUnlessDarwin +@skipIf(macos_version=["<", "15.5"]) +def test_libsanitizers_traces(self): +self.build(make_targets=["libsanitizers-traces"]) +self.libsanitizers_traces_tests() def setUp(self): # Call super's setUp(). @@ -36,34 +42,61 @@ def setUp(self): self.line_breakpoint = line_number("main.c", "// break line") # Test line numbers: rdar://126237493 -def libsanitizer_tests(self): -target = self.createTestTarget() +# for libsanitizers and remove `skip_line_numbers` parameter +def check_traces(self, skip_line_numbers): +self.expect( +"memory history 'pointer'", +substrs=[ +"Memory deallocated by Thread", +"a.out`f2", +"main.c" if skip_line_numbers else f"main.c:{self.line_free}", +"Memory allocated by Thread", +"a.out`f1", +"main.c" if skip_line_numbers else f"main.c:{self.line_malloc}", +], +) + +def libsanitizers_traces_tests(self): +self.createTestTarget() + +self.runCmd("env SanitizersAllocationTraces=all") -self.runCmd( -"env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0" +self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint) +self.runCmd("run") + +# Stop on breakpoint, before report +self.expect( +"thread list", +STOPPED_DUE_TO_BREAKPOINT, +substrs=["stopped", "stop reason = breakpoint"], ) +self.check_traces(skip_line_numbers=True) + +def libsanitizers_asan_tests(self): +self.createTestTarget() + +self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1") +self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint) self.runCmd("run") -# In libsanitizers, memory history is not supported until a report has been generated +# Stop on breakpoint, before report self.expect( "thread list", -"Process should be stopped due to ASan report", -substrs=["stopped", "stop reason = Use of deallocated memory"], +STOPPED_DUE_TO_BREAKPOINT, +substrs=["stopped", "stop reason = breakpoint"], ) +self.check_traces(skip_line_numbers=True) + +self.runCmd("continue") -# test the 'memory history' command +# Stop on report self.expect( -"memory history 'pointer'", -substrs=[ -
[Lldb-commits] [lldb] [LLDB][NFC] Move CPlusPlusLanguage methods used in Core/Module.cpp to a separated module to break lldb-server dependencies (PR #132274)
https://github.com/slydiman updated https://github.com/llvm/llvm-project/pull/132274 >From a4d62ca1dfaca8eb29ce7d2809c28137d22416b9 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev Date: Thu, 20 Mar 2025 21:50:51 +0400 Subject: [PATCH] [LLDB] Refactor Module::LookupInfo constructor and move out CPlusPlusLanguage::MethodName to break lldb-server dependencies This patch addresses the issue #129543. After this patch the size of lldb-server is reduced by 9MB. Based on https://github.com/swiftlang/llvm-project/pull/3240 by @bulbazord Alex Langford --- lldb/include/lldb/Target/Language.h | 5 + lldb/source/Core/CMakeLists.txt | 1 - lldb/source/Core/Module.cpp | 130 lldb/source/Core/RichManglingContext.cpp | 2 +- .../Clang/ClangExpressionDeclMap.cpp | 11 +- lldb/source/Plugins/Language/CMakeLists.txt | 2 + .../Plugins/Language/CPlusPlus/CMakeLists.txt | 1 + .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 294 ++ .../Language/CPlusPlus/CPlusPlusLanguage.h| 91 +- .../CPlusPlus/CPlusPlusLanguageMethod.cpp | 279 + .../CPlusPlus/CPlusPlusLanguageMethod.h | 106 +++ .../Plugins/Language/ObjC/ObjCLanguage.cpp| 15 + .../Plugins/Language/ObjC/ObjCLanguage.h | 3 + .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 6 +- .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 4 +- .../CPlusPlus/CPlusPlusLanguageTest.cpp | 27 +- 16 files changed, 524 insertions(+), 453 deletions(-) create mode 100644 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.cpp create mode 100644 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.h diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h index b699a90aff8e4..d095499bd596e 100644 --- a/lldb/include/lldb/Target/Language.h +++ b/lldb/include/lldb/Target/Language.h @@ -214,6 +214,11 @@ class Language : public PluginInterface { return std::vector(); }; + virtual std::pair + GetFunctionNameInfo(ConstString name) const { +return std::pair{lldb::eFunctionNameTypeNone, llvm::StringRef()}; + }; + /// Returns true iff the given symbol name is compatible with the mangling /// scheme of this language. /// diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 0a08da0fec230..62390104cd588 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -72,7 +72,6 @@ add_lldb_library(lldbCore lldbValueObject lldbVersion lldbPluginCPlusPlusLanguage -lldbPluginObjCLanguage ${LLDB_CURSES_LIBS} CLANG_LIBS diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 53dc6fcde0381..43635b7e31ca4 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -52,8 +52,7 @@ #include "lldb/Host/windows/PosixApi.h" #endif -#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" -#include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Compiler.h" @@ -641,98 +640,75 @@ void Module::FindCompileUnits(const FileSpec &path, Module::LookupInfo::LookupInfo(ConstString name, FunctionNameType name_type_mask, LanguageType language) -: m_name(name), m_lookup_name(), m_language(language) { - const char *name_cstr = name.GetCString(); +: m_name(name), m_lookup_name(name), m_language(language) { llvm::StringRef basename; - llvm::StringRef context; + + std::vector languages; + auto collect_language_plugins = [&languages](Language *lang) { +languages.push_back(lang); +return true; + }; if (name_type_mask & eFunctionNameTypeAuto) { -if (CPlusPlusLanguage::IsCPPMangledName(name_cstr)) - m_name_type_mask = eFunctionNameTypeFull; -else if ((language == eLanguageTypeUnknown || - Language::LanguageIsObjC(language)) && - ObjCLanguage::IsPossibleObjCMethodName(name_cstr)) - m_name_type_mask = eFunctionNameTypeFull; -else if (Language::LanguageIsC(language)) { - m_name_type_mask = eFunctionNameTypeFull; +if (language == eLanguageTypeUnknown) { + Language::ForEach(collect_language_plugins); + for (Language *lang : languages) { +auto info = lang->GetFunctionNameInfo(name); +if (info.first != eFunctionNameTypeNone) { + m_name_type_mask |= info.first; + basename = info.second; + break; +} + } } else { - if ((language == eLanguageTypeUnknown || - Language::LanguageIsObjC(language)) && - ObjCLanguage::IsPossibleObjCSelector(name_cstr)) -m_name_type_mask |= eFunctionNameTypeSelector; - - CPlusPlusLanguage::MethodName cpp_method(name); - basename = cpp_method.GetBasename(); - if (basename.empty()) { -
[Lldb-commits] [lldb] Add DAP tests for initialized event to be sure stats are present (PR #134266)
https://github.com/youngd007 created https://github.com/llvm/llvm-project/pull/134266 As the DAP JSON was recently modified to move the statistics from one key to another, it was revealed there was no test for the initialized event that also emits this information. https://github.com/llvm/llvm-project/pull/130454/files So adding a test to make sure the keys stay in sync between DAP initialized and terminated. >From 80fafd267a19e4e0dd4f35e3807ae4a69b47c86e Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 3 Apr 2025 08:55:10 -0700 Subject: [PATCH] Add DAP tests for initialized event to be sure stats are present --- .../test/tools/lldb-dap/dap_server.py | 130 +- .../API/tools/lldb-dap/initialized/Makefile | 17 +++ .../initialized/TestDAP_initializedEvent.py | 47 +++ .../API/tools/lldb-dap/initialized/foo.cpp| 1 + .../test/API/tools/lldb-dap/initialized/foo.h | 1 + .../API/tools/lldb-dap/initialized/main.cpp | 8 ++ 6 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/initialized/Makefile create mode 100644 lldb/test/API/tools/lldb-dap/initialized/TestDAP_initializedEvent.py create mode 100644 lldb/test/API/tools/lldb-dap/initialized/foo.cpp create mode 100644 lldb/test/API/tools/lldb-dap/initialized/foo.h create mode 100644 lldb/test/API/tools/lldb-dap/initialized/main.cpp diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 45403e9df8525..3471770e807f0 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type): def dump_dap_log(log_file): -print("= DEBUG ADAPTER PROTOCOL LOGS =", file=sys.stderr) +print("= DEBUG ADAPTER PROTOCOL LOGS =") if log_file is None: -print("no log file available", file=sys.stderr) +print("no log file available") else: with open(log_file, "r") as file: -print(file.read(), file=sys.stderr) -print("= END =", file=sys.stderr) +print(file.read()) +print("= END =") def read_packet_thread(vs_comm, log_file): @@ -107,43 +107,46 @@ def read_packet_thread(vs_comm, log_file): # termination of lldb-dap and stop waiting for new packets. done = not vs_comm.handle_recv_packet(packet) finally: -# Wait for the process to fully exit before dumping the log file to -# ensure we have the entire log contents. -if vs_comm.process is not None: -try: -# Do not wait forever, some logs are better than none. -vs_comm.process.wait(timeout=20) -except subprocess.TimeoutExpired: -pass dump_dap_log(log_file) class DebugCommunication(object): -def __init__(self, recv, send, init_commands, log_file=None): +def __init__(self, recv, send, init_commands, log_file=None, keepAlive=False): self.trace_file = None self.send = send self.recv = recv self.recv_packets = [] self.recv_condition = threading.Condition() +self.sequence = 1 self.recv_thread = threading.Thread( target=read_packet_thread, args=(self, log_file) ) +self.recv_thread.start() +self.output_condition = threading.Condition() +self.reset(init_commands, keepAlive) + +# This will be called to re-initialize DebugCommunication object during +# reusing lldb-dap. +def reset(self, init_commands, keepAlive=False): +self.trace_file = None +self.recv_packets = [] self.process_event_body = None self.exit_status = None self.initialize_body = None self.thread_stop_reasons = {} self.breakpoint_events = [] +self.thread_events_body = [] self.progress_events = [] self.reverse_requests = [] -self.sequence = 1 +self.startup_events = [] self.threads = None -self.recv_thread.start() -self.output_condition = threading.Condition() self.output = {} self.configuration_done_sent = False self.frame_scopes = {} self.init_commands = init_commands self.disassembled_instructions = {} +self.initialized_event = None +self.keepAlive = keepAlive @classmethod def encode_content(cls, s): @@ -243,6 +246,8 @@ def handle_recv_packet(self, packet): self._process_stopped() tid = body["threadId"] self.thread_stop_reasons[tid] = body +elif event == "initialized": +self.initialized_event = packet elif event == "breakpoint": #
[Lldb-commits] [lldb] [lldb][debugserver] Fix an off-by-one error in watchpoint identification (PR #134314)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/134314 >From 780fc8f5081f97234749c70a139ad6034f48f3ae Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Thu, 3 Apr 2025 15:38:23 -0700 Subject: [PATCH 1/2] [lldb][debugserver] Fix an off-by-one error in watchpoint identification debugserver takes the address of a watchpoint exception and calculates which watchpoint was responsible for it. There was an off-by-one error in the range calculation which causes two watchpoints on consecutive ranges to not correctly identify hits to the second watchpoint. rdar://145107575 --- .../consecutive-watchpoints/Makefile | 3 + .../TestConsecutiveWatchpoints.py | 74 +++ .../watchpoint/consecutive-watchpoints/main.c | 22 ++ .../debugserver/source/DNBBreakpoint.cpp | 2 +- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/Makefile create mode 100644 lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/TestConsecutiveWatchpoints.py create mode 100644 lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/main.c diff --git a/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/Makefile b/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/Makefile new file mode 100644 index 0..10495940055b6 --- /dev/null +++ b/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/TestConsecutiveWatchpoints.py b/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/TestConsecutiveWatchpoints.py new file mode 100644 index 0..63b41e32ad4f7 --- /dev/null +++ b/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/TestConsecutiveWatchpoints.py @@ -0,0 +1,74 @@ +""" +Watch larger-than-8-bytes regions of memory, confirm that +writes to those regions are detected. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ConsecutiveWatchpointsTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def continue_and_report_stop_reason(self, process, iter_str): +process.Continue() +self.assertIn( +process.GetState(), [lldb.eStateStopped, lldb.eStateExited], iter_str +) +thread = process.GetSelectedThread() +return thread.GetStopReason() + +# debugserver only gained the ability to watch larger regions +# with this patch. +def test_large_watchpoint(self): +"""Test watchpoint that covers a large region of memory.""" +self.build() +self.main_source_file = lldb.SBFileSpec("main.c") +(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( +self, "break here", self.main_source_file +) + +frame = thread.GetFrameAtIndex(0) + +field2_wp = ( +frame.locals["var"][0] +.GetChildMemberWithName("field2") +.Watch(True, False, True) +) +field3_wp = ( +frame.locals["var"][0] +.GetChildMemberWithName("field3") +.Watch(True, False, True) +) +field4_wp = ( +frame.locals["var"][0] +.GetChildMemberWithName("field4") +.Watch(True, False, True) +) + +self.assertTrue(field2_wp.IsValid()) +self.assertTrue(field3_wp.IsValid()) +self.assertTrue(field4_wp.IsValid()) + +reason = self.continue_and_report_stop_reason(process, "continue to field2 wp") +self.assertEqual(reason, lldb.eStopReasonWatchpoint) +stop_reason_watchpoint_id = ( +process.GetSelectedThread().GetStopReasonDataAtIndex(0) +) +self.assertEqual(stop_reason_watchpoint_id, field2_wp.GetID()) + +reason = self.continue_and_report_stop_reason(process, "continue to field3 wp") +self.assertEqual(reason, lldb.eStopReasonWatchpoint) +stop_reason_watchpoint_id = ( +process.GetSelectedThread().GetStopReasonDataAtIndex(0) +) +self.assertEqual(stop_reason_watchpoint_id, field3_wp.GetID()) + +reason = self.continue_and_report_stop_reason(process, "continue to field4 wp") +self.assertEqual(reason, lldb.eStopReasonWatchpoint) +stop_reason_watchpoint_id = ( +process.GetSelectedThread().GetStopReasonDataAtIndex(0) +) +self.assertEqual(stop_reason_watchpoint_id, field4_wp.GetID()) diff --git a/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/main.c b/lldb/test/API/functionalities/watchpoint/consecutive-watchpoints/main.c new file mode 100644 index 0..c0a3530be9f5e --- /dev/null +++ b/lldb/test/API/functionalities/wa
[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
@@ -36,34 +42,61 @@ def setUp(self): self.line_breakpoint = line_number("main.c", "// break line") # Test line numbers: rdar://126237493 -def libsanitizer_tests(self): -target = self.createTestTarget() +# for libsanitizers and remove `skip_line_numbers` parameter +def check_traces(self, skip_line_numbers): +self.expect( +"memory history 'pointer'", +substrs=[ +"Memory deallocated by Thread", +"a.out`f2", +"main.c" if skip_line_numbers else f"main.c:{self.line_free}", +"Memory allocated by Thread", +"a.out`f1", +"main.c" if skip_line_numbers else f"main.c:{self.line_malloc}", +], +) + +def libsanitizers_traces_tests(self): +self.createTestTarget() + +self.runCmd("env SanitizersAllocationTraces=all") -self.runCmd( -"env SanitizersAddress=1 MallocSanitizerZone=1 MallocSecureAllocator=0" +self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint) +self.runCmd("run") + +# Stop on breakpoint, before report +self.expect( +"thread list", +STOPPED_DUE_TO_BREAKPOINT, +substrs=["stopped", "stop reason = breakpoint"], ) +self.check_traces(skip_line_numbers=True) + +def libsanitizers_asan_tests(self): +self.createTestTarget() + +self.runCmd("env SanitizersAddress=1 MallocSanitizerZone=1") +self.runCmd("breakpoint set -f main.c -l %d" % self.line_breakpoint) self.runCmd("run") -# In libsanitizers, memory history is not supported until a report has been generated jimingham wrote: Cool! I had to puzzle out why it was legit to call check_traces before and after the result. The point is you are stopping "before the report but after the allocation and deallocation" so the pointer history is the same. Might leave a comment to that effect to prevent some head scratching in the next person who comes through this. https://github.com/llvm/llvm-project/pull/134323 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
@@ -15,17 +15,23 @@ class AsanTestCase(TestBase): @expectedFailureNetBSD @skipUnlessAddressSanitizer def test(self): -self.build(make_targets=["asan"]) +self.build(make_targets=["compiler_rt-asan"]) self.asan_tests() wrotki wrote: Maybe this method should be renamed to self.compiler_rt_asan_tests , (self.libsanitizers_asan_tests test same functionality, different way) https://github.com/llvm/llvm-project/pull/134323 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add integration test for libsanitizers trace collection (PR #134323)
@@ -15,17 +15,23 @@ class AsanTestCase(TestBase): @expectedFailureNetBSD @skipUnlessAddressSanitizer def test(self): -self.build(make_targets=["asan"]) +self.build(make_targets=["compiler_rt-asan"]) self.asan_tests() -@skipIf(oslist=no_match(["macosx"])) -@skipIf(bugnumber="rdar://144997976") +@skipUnlessDarwin +@skipIf(bugnumber="rdar://109913184&143590169") def test_libsanitizers_asan(self): try: -self.build(make_targets=["libsanitizers"]) +self.build(make_targets=["libsanitizers-asan"]) except BuildError as e: self.skipTest("failed to build with libsanitizers") -self.libsanitizer_tests() +self.libsanitizers_asan_tests() + +@skipUnlessDarwin +@skipIf(macos_version=["<", "15.5"]) +def test_libsanitizers_traces(self): +self.build(make_targets=["libsanitizers-traces"]) +self.libsanitizers_traces_tests() wrotki wrote: Same as above, although no 'asan' in the name https://github.com/llvm/llvm-project/pull/134323 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Revert "[LLDB] Expose checking if the symbol file exists/is loaded via SBModule" (PR #134341)
https://github.com/Jlalond closed https://github.com/llvm/llvm-project/pull/134341 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [RFC][lldb-dap] Always stop on enrty for attaching (PR #134339)
https://github.com/kusmour edited https://github.com/llvm/llvm-project/pull/134339 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Revert "[LLDB] Expose checking if the symbol file exists/is loaded via SBModule" (PR #134341)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jacob Lalonde (Jlalond) Changes Reverts llvm/llvm-project#134163 Reverting while @clayborg and I come up with a better API --- Full diff: https://github.com/llvm/llvm-project/pull/134341.diff 2 Files Affected: - (modified) lldb/include/lldb/API/SBModule.h (-3) - (modified) lldb/source/API/SBModule.cpp (-12) ``diff diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h index 651455bdb78d2..85332066ee687 100644 --- a/lldb/include/lldb/API/SBModule.h +++ b/lldb/include/lldb/API/SBModule.h @@ -290,9 +290,6 @@ class LLDB_API SBModule { lldb::SBAddress GetObjectFileHeaderAddress() const; lldb::SBAddress GetObjectFileEntryPointAddress() const; - /// Get if the symbol file for this module is loaded. - bool IsDebugInfoLoaded() const; - /// Get the number of global modules. static uint32_t GetNumberAllocatedModules(); diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index 4978a553f57c7..985107ec68efd 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -659,18 +659,6 @@ lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const { return sb_addr; } -bool SBModule::IsDebugInfoLoaded() const { - LLDB_INSTRUMENT_VA(this); - - ModuleSP module_sp(GetSP()); - if (module_sp) { -SymbolFile *sym_file = module_sp->GetSymbolFile(/*create=*/false); -return sym_file && sym_file->GetLoadDebugInfoEnabled(); - } - - return false; -} - uint32_t SBModule::GetNumberAllocatedModules() { LLDB_INSTRUMENT(); `` https://github.com/llvm/llvm-project/pull/134341 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Make lldbassert fire only once per instance (PR #134343)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The `lldbassert` macro in LLDB behaves like a regular `assert` when assertions are enabled, and otherwise prints a pretty backtrace and prompts the user to file a bug. By default, this is emitted as a diagnostic event, but vendors can provide their own behavior, for example pre-populating a bug report. Recently, we ran into an issue where an `lldbassert` (in the Swift language plugin) would fire excessively, to the point that it was interfering with the usability of the debugger. Once an `lldbasser` has fired, there's no point in bothering the user over and over again for the same problem. This PR solves the problem by introducing a static `std::once_flag` in the macro. This way, every `lldbasser` will fire at most once per lldb instance. rdar://148520448 --- Full diff: https://github.com/llvm/llvm-project/pull/134343.diff 2 Files Affected: - (modified) lldb/include/lldb/Utility/LLDBAssert.h (+8-3) - (modified) lldb/source/Utility/LLDBAssert.cpp (+21-16) ``diff diff --git a/lldb/include/lldb/Utility/LLDBAssert.h b/lldb/include/lldb/Utility/LLDBAssert.h index 21dbdb3b3202d..cee30b81402ca 100644 --- a/lldb/include/lldb/Utility/LLDBAssert.h +++ b/lldb/include/lldb/Utility/LLDBAssert.h @@ -10,6 +10,7 @@ #define LLDB_UTILITY_LLDBASSERT_H #include "llvm/ADT/StringRef.h" +#include #ifndef NDEBUG #define lldbassert(x) assert(x) @@ -19,8 +20,11 @@ // __FILE__ but only renders the last path component (the filename) instead of // an invocation dependent full path to that file. #define lldbassert(x) \ - lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, \ - __FILE_NAME__, __LINE__) + do { \ +static std::once_flag _once_flag; \ +lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, \ + __FILE_NAME__, __LINE__, _once_flag) \ + } while (0) #else #define lldbassert(x) \ lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, __FILE__, \ @@ -33,7 +37,8 @@ namespace lldb_private { /// Don't use _lldb_assert directly. Use the lldbassert macro instead so that /// LLDB asserts become regular asserts in NDEBUG builds. void _lldb_assert(bool expression, const char *expr_text, const char *func, - const char *file, unsigned int line); + const char *file, unsigned int line, + std::once_flag &once_flag); /// The default LLDB assert callback, which prints to stderr. typedef void (*LLDBAssertCallback)(llvm::StringRef message, diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index b84c581ccf822..611ad43cd071b 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" +#include #if LLVM_SUPPORT_XCODE_SIGNPOSTS #include @@ -33,29 +34,33 @@ static std::atomic g_lldb_assert_callback = &DefaultAssertCallback; void _lldb_assert(bool expression, const char *expr_text, const char *func, - const char *file, unsigned int line) { + const char *file, unsigned int line, + std::once_flag &once_flag) { if (LLVM_LIKELY(expression)) return; + std::call_once(once_flag, [&]() { #if LLVM_SUPPORT_XCODE_SIGNPOSTS - if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) { -os_log_fault(OS_LOG_DEFAULT, - "Assertion failed: (%s), function %s, file %s, line %u\n", - expr_text, func, file, line); - } +if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) { + os_log_fault(OS_LOG_DEFAULT, + "Assertion failed: (%s), function %s, file %s, line %u\n", + expr_text, func, file, line); +} #endif - std::string buffer; - llvm::raw_string_ostream backtrace(buffer); - llvm::sys::PrintStackTrace(backtrace); +std::string buffer; +llvm::raw_string_ostream backtrace(buffer); +llvm::sys::PrintStackTrace(backtrace); - (*g_lldb_assert_callback.load())( - llvm::formatv("Assertion failed: ({0}), function {1}, file {2}, line {3}", -expr_text, func, file, line) - .str(), - buffer, - "Please file a bug report against lldb and include the backtrace, the " - "version and as many details as possible."); +(*g_lldb_assert_callback.load())( +llvm::formatv( +"Assertion failed: ({0}), function {1}, file {2}, line {3}", +expr_text, func, file, line) +
[Lldb-commits] [lldb] [lldb] Make lldbassert fire only once per instance (PR #134343)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/134343 The `lldbassert` macro in LLDB behaves like a regular `assert` when assertions are enabled, and otherwise prints a pretty backtrace and prompts the user to file a bug. By default, this is emitted as a diagnostic event, but vendors can provide their own behavior, for example pre-populating a bug report. Recently, we ran into an issue where an `lldbassert` (in the Swift language plugin) would fire excessively, to the point that it was interfering with the usability of the debugger. Once an `lldbasser` has fired, there's no point in bothering the user over and over again for the same problem. This PR solves the problem by introducing a static `std::once_flag` in the macro. This way, every `lldbasser` will fire at most once per lldb instance. rdar://148520448 >From a19e0ce464b928ec55e6bf315626f3fb3f5c5a43 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 3 Apr 2025 21:08:25 -0700 Subject: [PATCH] [lldb] Make lldbassert fire only once per instance The `lldbassert` macro in LLDB behaves like a regular `assert` when assertions are enabled, and otherwise prints a pretty backtrace and prompts the user to file a bug. By default, this is emitted as a diagnostic event, but vendors can provide their own behavior, for example pre-populating a bug report. Recently, we ran into an issue where an `lldbassert` (in the Swift language plugin) would fire excessively, to the point that it was interfering with the usability of the debugger. Once an `lldbasser` has fired, there's no point in bothering the user over and over again for the same problem. This PR solves the problem by introducing a static `std::once_flag` in the macro. This way, every `lldbasser` will fire at most once per lldb instance. rdar://148520448 --- lldb/include/lldb/Utility/LLDBAssert.h | 11 +--- lldb/source/Utility/LLDBAssert.cpp | 37 +++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lldb/include/lldb/Utility/LLDBAssert.h b/lldb/include/lldb/Utility/LLDBAssert.h index 21dbdb3b3202d..cee30b81402ca 100644 --- a/lldb/include/lldb/Utility/LLDBAssert.h +++ b/lldb/include/lldb/Utility/LLDBAssert.h @@ -10,6 +10,7 @@ #define LLDB_UTILITY_LLDBASSERT_H #include "llvm/ADT/StringRef.h" +#include #ifndef NDEBUG #define lldbassert(x) assert(x) @@ -19,8 +20,11 @@ // __FILE__ but only renders the last path component (the filename) instead of // an invocation dependent full path to that file. #define lldbassert(x) \ - lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, \ - __FILE_NAME__, __LINE__) + do { \ +static std::once_flag _once_flag; \ +lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, \ + __FILE_NAME__, __LINE__, _once_flag) \ + } while (0) #else #define lldbassert(x) \ lldb_private::_lldb_assert(static_cast(x), #x, __FUNCTION__, __FILE__, \ @@ -33,7 +37,8 @@ namespace lldb_private { /// Don't use _lldb_assert directly. Use the lldbassert macro instead so that /// LLDB asserts become regular asserts in NDEBUG builds. void _lldb_assert(bool expression, const char *expr_text, const char *func, - const char *file, unsigned int line); + const char *file, unsigned int line, + std::once_flag &once_flag); /// The default LLDB assert callback, which prints to stderr. typedef void (*LLDBAssertCallback)(llvm::StringRef message, diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index b84c581ccf822..611ad43cd071b 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" +#include #if LLVM_SUPPORT_XCODE_SIGNPOSTS #include @@ -33,29 +34,33 @@ static std::atomic g_lldb_assert_callback = &DefaultAssertCallback; void _lldb_assert(bool expression, const char *expr_text, const char *func, - const char *file, unsigned int line) { + const char *file, unsigned int line, + std::once_flag &once_flag) { if (LLVM_LIKELY(expression)) return; + std::call_once(once_flag, [&]() { #if LLVM_SUPPORT_XCODE_SIGNPOSTS - if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) { -os_log_fault(OS_LOG_DEFAULT, - "Assertion failed: (%s), function %s, file %s, line %u\n", - expr_text, func, file, line); - } +if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) { + os_l
[Lldb-commits] [lldb] 46e2c07 - [LLDB] Add DIL code for handling plain variable names. (#120971)
Author: cmtice Date: 2025-04-03T21:39:30-07:00 New Revision: 46e2c07fa28bd42da8f8ca52e93603297114afa2 URL: https://github.com/llvm/llvm-project/commit/46e2c07fa28bd42da8f8ca52e93603297114afa2 DIFF: https://github.com/llvm/llvm-project/commit/46e2c07fa28bd42da8f8ca52e93603297114afa2.diff LOG: [LLDB] Add DIL code for handling plain variable names. (#120971) Add the Data Inspection Language (DIL) implementation pieces for handling plain local and global variable names. See https://discourse.llvm.org/t/rfc-data-inspection-language/69893 for information about DIL. This change includes the basic AST, Lexer, Parser and Evaluator pieces, as well as some tests. Added: lldb/docs/dil-expr-lang.ebnf lldb/include/lldb/ValueObject/DILAST.h lldb/include/lldb/ValueObject/DILEval.h lldb/include/lldb/ValueObject/DILParser.h lldb/source/ValueObject/DILAST.cpp lldb/source/ValueObject/DILEval.cpp lldb/source/ValueObject/DILParser.cpp lldb/test/API/commands/frame/var-dil/basics/GlobalVariableLookup/Makefile lldb/test/API/commands/frame/var-dil/basics/GlobalVariableLookup/TestFrameVarDILGlobalVariableLookup.py lldb/test/API/commands/frame/var-dil/basics/GlobalVariableLookup/main.cpp lldb/test/API/commands/frame/var-dil/basics/InstanceVariables/Makefile lldb/test/API/commands/frame/var-dil/basics/InstanceVariables/TestFrameVarDILInstanceVariables.py lldb/test/API/commands/frame/var-dil/basics/InstanceVariables/main.cpp lldb/test/API/commands/frame/var-dil/basics/LocalVars/Makefile lldb/test/API/commands/frame/var-dil/basics/LocalVars/TestFrameVarDILLocalVars.py lldb/test/API/commands/frame/var-dil/basics/LocalVars/main.cpp Modified: lldb/include/lldb/ValueObject/DILLexer.h lldb/source/Target/StackFrame.cpp lldb/source/ValueObject/CMakeLists.txt lldb/unittests/ValueObject/DILLexerTests.cpp Removed: diff --git a/lldb/docs/dil-expr-lang.ebnf b/lldb/docs/dil-expr-lang.ebnf new file mode 100644 index 0..0bbbecbdc78c1 --- /dev/null +++ b/lldb/docs/dil-expr-lang.ebnf @@ -0,0 +1,42 @@ +(* Data Inspection Language (DIL) definition - LLDB Debug Expressions *) + +(* This is currently a subset of the final DIL Language, matching the current + DIL implementation. *) + +expression = primary_expression ; + +primary_expression = id_expression + | "(" expression ")"; + +id_expression = unqualified_id + | qualified_id + | register ; + +unqualified_id = identifier ; + +qualified_id = ["::"] [nested_name_specifier] unqualified_id + | ["::"] identifier ; + +identifier = ? C99 Identifier ? ; + +register = "$" ? Register name ? ; + +nested_name_specifier = type_name "::" + | namespace_name '::' + | nested_name_specifier identifier "::" ; + +type_name = class_name + | enum_name + | typedef_name; + +class_name = identifier ; + +enum_name = identifier ; + +typedef_name = identifier ; + +namespace_name = identifier ; + + + + diff --git a/lldb/include/lldb/ValueObject/DILAST.h b/lldb/include/lldb/ValueObject/DILAST.h new file mode 100644 index 0..05d87e9cc4b6b --- /dev/null +++ b/lldb/include/lldb/ValueObject/DILAST.h @@ -0,0 +1,97 @@ +//===-- DILAST.h *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_VALUEOBJECT_DILAST_H +#define LLDB_VALUEOBJECT_DILAST_H + +#include "lldb/ValueObject/ValueObject.h" +#include "llvm/Support/Error.h" +#include +#include + +namespace lldb_private::dil { + +/// The various types DIL AST nodes (used by the DIL parser). +enum class NodeKind { + eErrorNode, + eIdentifierNode, +}; + +/// Forward declaration, for use in DIL AST nodes. Definition is at the very +/// end of this file. +class Visitor; + +/// The rest of the classes in this file, except for the Visitor class at the +/// very end, define all the types of AST nodes used by the DIL parser and +/// expression evaluator. The DIL parser parses the input string and creates +/// the AST parse tree from the AST nodes. The resulting AST node tree gets +/// passed to the DIL expression evaluator, which evaluates the DIL AST nodes +/// and creates/returns a ValueObjectSP containing the result. + +/// Base class for AST nodes used by the Data Inspection Language (DIL) parser. +/// All of the specialized types of AST nodes inherit from this (virtual) base +/// class. +class ASTNode { +public: + ASTNode(uint32_t location, NodeKind kind) + : m_location(location), m_kind(kind) {} + virtual ~ASTNode() = default; + + virtual llvm::E
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
https://github.com/cmtice closed https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running on `linaro-lldb-arm-ubuntu` while building `lldb` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/13991 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (1173 of 2950) PASS: lldb-api :: tools/lldb-dap/evaluate/TestDAP_evaluate.py (1174 of 2950) PASS: lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py (1175 of 2950) PASS: lldb-api :: tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py (1176 of 2950) UNSUPPORTED: lldb-api :: tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py (1177 of 2950) PASS: lldb-api :: tools/lldb-dap/module/TestDAP_module.py (1178 of 2950) UNSUPPORTED: lldb-api :: tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py (1179 of 2950) UNSUPPORTED: lldb-api :: tools/lldb-dap/save-core/TestDAP_save_core.py (1180 of 2950) PASS: lldb-api :: tools/lldb-dap/send-event/TestDAP_sendEvent.py (1181 of 2950) UNRESOLVED: lldb-api :: tools/lldb-dap/restart/TestDAP_restart.py (1182 of 2950) TEST 'lldb-api :: tools/lldb-dap/restart/TestDAP_restart.py' FAILED Script: -- /usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/restart -p TestDAP_restart.py -- Exit Code: 1 Command Output (stdout): -- lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 46e2c07fa28bd42da8f8ca52e93603297114afa2) clang revision 46e2c07fa28bd42da8f8ca52e93603297114afa2 llvm revision 46e2c07fa28bd42da8f8ca52e93603297114afa2 Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc'] -- Command Output (stderr): -- = DEBUG ADAPTER PROTOCOL LOGS = 1743742401.480223179 --> (stdin/stdout) {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1} 1743742401.484025955 <-- (stdin/stdout) {"body":{"$__lldb_version":"lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 46e2c07fa28bd42da8f8ca52e93603297114afa2)\n clang revision 46e2c07fa28bd42da8f8ca52e93603297114afa2\n llvm revision 46e2c07fa28bd42da8f8ca52e93603297114afa2","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++ Catch"},{"default":false,"filter":"cpp_throw","label":"C++ Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionInfoRequest":true,"supportsExceptionOptions":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsRestartRequest":true,"supportsSetVariable":true,"supportsStepInTargetsRequest":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"} 1743742401.484506369 -->
[Lldb-commits] [lldb] 662d385 - [lldb/telemetry] Report exit status only once (#134078)
Author: Pavel Labath Date: 2025-04-03T11:59:02+02:00 New Revision: 662d385c7b07fc6aba51e73a09c254f551ab93ab URL: https://github.com/llvm/llvm-project/commit/662d385c7b07fc6aba51e73a09c254f551ab93ab DIFF: https://github.com/llvm/llvm-project/commit/662d385c7b07fc6aba51e73a09c254f551ab93ab.diff LOG: [lldb/telemetry] Report exit status only once (#134078) SetExitStatus can be called the second time when we reap the debug server process. This shouldn't be interesting as at that point, we've already told everyone that the process has exited. I believe/hope this will also help with sporadic shutdown crashes that have cropped up recently. They happen because the debug server is monitored from a detached thread, so this code can be called after main returns (and starts destroying everything). This isn't a real fix for that though, as the situation can still happen (it's just that it usually happens after the exit status has already been set). I think the real fix for that is to make sure these threads terminate before we start shutting everything down. Added: Modified: lldb/source/Target/Process.cpp Removed: diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 369933234ccca..7936cf28467b2 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1067,6 +1067,20 @@ const char *Process::GetExitDescription() { bool Process::SetExitStatus(int status, llvm::StringRef exit_string) { // Use a mutex to protect setting the exit status. std::lock_guard guard(m_exit_status_mutex); + Log *log(GetLog(LLDBLog::State | LLDBLog::Process)); + LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")", + GetPluginName(), status, exit_string); + + // We were already in the exited state + if (m_private_state.GetValue() == eStateExited) { +LLDB_LOG( +log, +"(plugin = {0}) ignoring exit status because state was already set " +"to eStateExited", +GetPluginName()); +return false; + } + telemetry::ScopedDispatcher helper; UUID module_uuid; @@ -1089,20 +1103,6 @@ bool Process::SetExitStatus(int status, llvm::StringRef exit_string) { info->pid = m_pid; }); - Log *log(GetLog(LLDBLog::State | LLDBLog::Process)); - LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")", - GetPluginName(), status, exit_string); - - // We were already in the exited state - if (m_private_state.GetValue() == eStateExited) { -LLDB_LOG( -log, -"(plugin = {0}) ignoring exit status because state was already set " -"to eStateExited", -GetPluginName()); -return false; - } - m_exit_status = status; if (!exit_string.empty()) m_exit_string = exit_string.str(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/telemetry] Report exit status only once (PR #134078)
https://github.com/labath closed https://github.com/llvm/llvm-project/pull/134078 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Target] RunThreadPlan to save/restore the ExecutionContext's frame if one exists (PR #134097)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/134097 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131609 >From 6f2d070facaced221295a5b0c48ccb3a41a5048d Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Mon, 17 Mar 2025 14:37:26 +0200 Subject: [PATCH 1/2] [lldb] Use correct path for debugserver --- lldb/tools/lldb-server/SystemInitializerLLGS.h | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h index 4469a8ba5f60a..c6020b0dd37da 100644 --- a/lldb/tools/lldb-server/SystemInitializerLLGS.h +++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h @@ -11,10 +11,17 @@ #include "lldb/Initialization/SystemInitializer.h" #include "lldb/Initialization/SystemInitializerCommon.h" +#include "lldb/Utility/FileSpec.h" class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon { public: - SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {} + SystemInitializerLLGS() + : SystemInitializerCommon( +// Finding the shared libraries directory on lldb-server is broken +// since lldb-server isn't dynamically linked with liblldb.so. +// Clearing the filespec here causes GetShlibDir to fail and +// GetSupportExeDir to fall-back to using the binary path instead. +[](lldb_private::FileSpec &file) { file.Clear(); }) {} llvm::Error Initialize() override; void Terminate() override; >From bb041595c7f88b5d9742a21576550fdfcc7ade2a Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Thu, 3 Apr 2025 14:52:43 +0300 Subject: [PATCH 2/2] [lldb] Test running lldb-server through symlink --- .../TestPlatformLaunchGDBServer.py| 49 +++ 1 file changed, 49 insertions(+) diff --git a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py index c365bc993e338..3949cfa312986 100644 --- a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py +++ b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py @@ -58,3 +58,52 @@ def test_platform_process_launch_gdb_server(self): self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) self.expect("run", substrs=["unable to launch a GDB server on"], error=True) + +@skipIfRemote +@skipUnlessPlatform(["linux"]) +@add_test_categories(["lldb-server"]) +def test_lldb_server_weird_symlinks(self): +self.build() + +hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0] +listen_url = "[%s]:0" % hostname + +port_file = self.getBuildArtifact("port") +commandline_args = [ +"platform", +"--listen", +listen_url, +"--socket-file", +port_file, +"--", +self.getBuildArtifact("a.out"), +"foo", +] + +# Run lldb-server from a symlink without any binary called "lldb-server" in the directory. +llgs_hiding_directory = self.getBuildArtifact("hiding-directory") +new_lldb_server_link = self.getBuildArtifact( +"lldb-server-with-an-unconventional-name" +) +new_lldb_server = os.path.join(llgs_hiding_directory, "lldb-server") +os.makedirs(llgs_hiding_directory) +shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server) +os.symlink(new_lldb_server, new_lldb_server_link) + +self.spawnSubprocess(new_lldb_server_link, commandline_args) +socket_id = lldbutil.wait_for_file_on_target(self, port_file) + +new_platform = lldb.SBPlatform("remote-" + self.getPlatform()) +self.dbg.SetSelectedPlatform(new_platform) + +connect_url = "connect://[%s]:%s" % (hostname, socket_id) +self.runCmd("platform connect %s" % connect_url) + +# First connect to lldb-server which spawn a process to handle the connection. +# Then remove our new lldb-server so that when it tries to invoke itself as a +# gdbserver, it fails. +os.remove(new_lldb_server_link) +shutil.rmtree(llgs_hiding_directory) + +self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) +self.expect("run", substrs=["unable to launch a GDB server on"], error=True) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131609 >From 6f2d070facaced221295a5b0c48ccb3a41a5048d Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Mon, 17 Mar 2025 14:37:26 +0200 Subject: [PATCH 1/2] [lldb] Use correct path for debugserver --- lldb/tools/lldb-server/SystemInitializerLLGS.h | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h index 4469a8ba5f60a..c6020b0dd37da 100644 --- a/lldb/tools/lldb-server/SystemInitializerLLGS.h +++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h @@ -11,10 +11,17 @@ #include "lldb/Initialization/SystemInitializer.h" #include "lldb/Initialization/SystemInitializerCommon.h" +#include "lldb/Utility/FileSpec.h" class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon { public: - SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {} + SystemInitializerLLGS() + : SystemInitializerCommon( +// Finding the shared libraries directory on lldb-server is broken +// since lldb-server isn't dynamically linked with liblldb.so. +// Clearing the filespec here causes GetShlibDir to fail and +// GetSupportExeDir to fall-back to using the binary path instead. +[](lldb_private::FileSpec &file) { file.Clear(); }) {} llvm::Error Initialize() override; void Terminate() override; >From 1b04782c9db3647d1379346ce36009dc077dddfc Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Thu, 3 Apr 2025 14:52:43 +0300 Subject: [PATCH 2/2] [lldb] Test running lldb-server through symlink --- .../TestPlatformLaunchGDBServer.py| 51 +++ 1 file changed, 51 insertions(+) diff --git a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py index c365bc993e338..e332035d0c767 100644 --- a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py +++ b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py @@ -58,3 +58,54 @@ def test_platform_process_launch_gdb_server(self): self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) self.expect("run", substrs=["unable to launch a GDB server on"], error=True) + +@skipIfRemote +# Windows cannot delete the executable while it is running. +# On Darwin we may be using debugserver. +@skipUnlessPlatform(["linux"]) +@add_test_categories(["lldb-server"]) +def test_platform_process_launch_gdb_server(self): +self.build() + +hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0] +listen_url = "[%s]:0" % hostname + +port_file = self.getBuildArtifact("port") +commandline_args = [ +"platform", +"--listen", +listen_url, +"--socket-file", +port_file, +"--", +self.getBuildArtifact("a.out"), +"foo", +] + +# Run lldb-server from a symlink without any binary called "lldb-server" in the directory. +llgs_hiding_directory = self.getBuildArtifact("hiding-directory") +new_lldb_server_link = self.getBuildArtifact( +"lldb-server-with-an-unconventional-name" +) +new_lldb_server = os.path.join(llgs_hiding_directory, "lldb-server") +os.makedirs(llgs_hiding_directory) +shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server) +os.symlink(new_lldb_server, new_lldb_server_link) + +self.spawnSubprocess(new_lldb_server_link, commandline_args) +socket_id = lldbutil.wait_for_file_on_target(self, port_file) + +new_platform = lldb.SBPlatform("remote-" + self.getPlatform()) +self.dbg.SetSelectedPlatform(new_platform) + +connect_url = "connect://[%s]:%s" % (hostname, socket_id) +self.runCmd("platform connect %s" % connect_url) + +# First connect to lldb-server which spawn a process to handle the connection. +# Then remove our new lldb-server so that when it tries to invoke itself as a +# gdbserver, it fails. +os.remove(new_lldb_server_link) +shutil.rmtree(llgs_hiding_directory) + +self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) +self.expect("run", substrs=["unable to launch a GDB server on"], error=True) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
DavidSpickett wrote: Given how fiddly this all is, I would duplicate the test (meaning, add another test case to that file). Even if there is overlap, it's worth it for the added clarity. https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
yuvald-sweet-security wrote: Whoops, I copied that test and didn't read what it does at the end https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131609 >From 6f2d070facaced221295a5b0c48ccb3a41a5048d Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Mon, 17 Mar 2025 14:37:26 +0200 Subject: [PATCH 1/2] [lldb] Use correct path for debugserver --- lldb/tools/lldb-server/SystemInitializerLLGS.h | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h index 4469a8ba5f60a..c6020b0dd37da 100644 --- a/lldb/tools/lldb-server/SystemInitializerLLGS.h +++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h @@ -11,10 +11,17 @@ #include "lldb/Initialization/SystemInitializer.h" #include "lldb/Initialization/SystemInitializerCommon.h" +#include "lldb/Utility/FileSpec.h" class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon { public: - SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {} + SystemInitializerLLGS() + : SystemInitializerCommon( +// Finding the shared libraries directory on lldb-server is broken +// since lldb-server isn't dynamically linked with liblldb.so. +// Clearing the filespec here causes GetShlibDir to fail and +// GetSupportExeDir to fall-back to using the binary path instead. +[](lldb_private::FileSpec &file) { file.Clear(); }) {} llvm::Error Initialize() override; void Terminate() override; >From c2fb1da3e4be760177d03f346613285e75937359 Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Thu, 3 Apr 2025 14:52:43 +0300 Subject: [PATCH 2/2] [lldb] Test running lldb-server through symlink --- .../TestPlatformLaunchGDBServer.py| 42 +++ 1 file changed, 42 insertions(+) diff --git a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py index c365bc993e338..00c9732500be8 100644 --- a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py +++ b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py @@ -58,3 +58,45 @@ def test_platform_process_launch_gdb_server(self): self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) self.expect("run", substrs=["unable to launch a GDB server on"], error=True) + +@skipIfRemote +@skipUnlessPlatform(["linux"]) +@add_test_categories(["lldb-server"]) +def test_lldb_server_weird_symlinks(self): +self.build() + +hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0] +listen_url = "[%s]:0" % hostname + +port_file = self.getBuildArtifact("port") +commandline_args = [ +"platform", +"--listen", +listen_url, +"--socket-file", +port_file, +"--", +self.getBuildArtifact("a.out"), +"foo", +] + +# Run lldb-server from a symlink without any binary called "lldb-server" in the directory. +llgs_hiding_directory = self.getBuildArtifact("hiding-directory") +new_lldb_server_link = self.getBuildArtifact( +"lldb-server-with-an-unconventional-name" +) +new_lldb_server = os.path.join(llgs_hiding_directory, "lldb-server") +os.makedirs(llgs_hiding_directory) +shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server) +os.symlink(new_lldb_server, new_lldb_server_link) + +self.spawnSubprocess(new_lldb_server_link, commandline_args) +socket_id = lldbutil.wait_for_file_on_target(self, port_file) + +new_platform = lldb.SBPlatform("remote-" + self.getPlatform()) +self.dbg.SetSelectedPlatform(new_platform) + +connect_url = "connect://[%s]:%s" % (hostname, socket_id) +self.runCmd("platform connect %s" % connect_url) +self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) +self.expect("run", error=False) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP] [libcxxabi][ItaniumDemangle] Add infrastructure to track location information of parts of a demangled function name (PR #133249)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/133249 >From 0875195a7ed39c21e9b639bf66d56b48e9869e51 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 11 Mar 2025 08:57:13 + Subject: [PATCH 1/3] [llvm][ItaniumDemangle] Add function name location tracking --- libcxxabi/src/demangle/ItaniumDemangle.h | 21 libcxxabi/src/demangle/Utility.cpp| 112 ++ libcxxabi/src/demangle/Utility.h | 91 +++--- libcxxabi/src/demangle/cp-to-llvm.sh | 62 +++--- llvm/include/llvm/Demangle/ItaniumDemangle.h | 21 llvm/include/llvm/Demangle/Utility.h | 91 +++--- llvm/lib/Demangle/CMakeLists.txt | 1 + llvm/lib/Demangle/README.txt | 61 ++ llvm/lib/Demangle/Utility.cpp | 112 ++ .../Demangle/ItaniumDemangleTest.cpp | 112 ++ 10 files changed, 635 insertions(+), 49 deletions(-) create mode 100644 libcxxabi/src/demangle/Utility.cpp create mode 100644 llvm/lib/Demangle/README.txt create mode 100644 llvm/lib/Demangle/Utility.cpp diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index 3df41b5f4d7d0..b5a0a86b119f4 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -851,11 +851,13 @@ class FunctionType final : public Node { // by printing out the return types's left, then print our parameters, then // finally print right of the return type. void printLeft(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); Ret->printLeft(OB); OB += " "; } void printRight(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); OB.printOpen(); Params.printWithComma(OB); OB.printClose(); @@ -971,18 +973,32 @@ class FunctionEncoding final : public Node { const Node *getName() const { return Name; } void printLeft(OutputBuffer &OB) const override { +// Nested FunctionEncoding parsing can happen with following productions: +// * +// * +auto Scoped = OB.enterFunctionTypePrinting(); + if (Ret) { Ret->printLeft(OB); if (!Ret->hasRHSComponent(OB)) OB += " "; } + +OB.FunctionInfo.updateScopeStart(OB); + Name->print(OB); } void printRight(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); +OB.FunctionInfo.finalizeStart(OB); + OB.printOpen(); Params.printWithComma(OB); OB.printClose(); + +OB.FunctionInfo.finalizeArgumentEnd(OB); + if (Ret) Ret->printRight(OB); @@ -1005,6 +1021,8 @@ class FunctionEncoding final : public Node { OB += " requires "; Requires->print(OB); } + +OB.FunctionInfo.finalizeEnd(OB); } }; @@ -1072,7 +1090,9 @@ struct NestedName : Node { void printLeft(OutputBuffer &OB) const override { Qual->print(OB); OB += "::"; +OB.FunctionInfo.updateScopeEnd(OB); Name->print(OB); +OB.FunctionInfo.updateBasenameEnd(OB); } }; @@ -1633,6 +1653,7 @@ struct NameWithTemplateArgs : Node { void printLeft(OutputBuffer &OB) const override { Name->print(OB); +OB.FunctionInfo.updateBasenameEnd(OB); TemplateArgs->print(OB); } }; diff --git a/libcxxabi/src/demangle/Utility.cpp b/libcxxabi/src/demangle/Utility.cpp new file mode 100644 index 0..04516082b3443 --- /dev/null +++ b/libcxxabi/src/demangle/Utility.cpp @@ -0,0 +1,112 @@ +//===--- Utility.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Provide some utility classes for use in the demangler. +// There are two copies of this file in the source tree. The one in libcxxabi +// is the original and the one in llvm is the copy. Use cp-to-llvm.sh to update +// the copy. See README.txt for more details. +// +//===--===// + +#include "Utility.h" +#include "DemangleConfig.h" + +DEMANGLE_NAMESPACE_BEGIN + +bool FunctionNameInfo::startedPrintingArguments() const { + return ArgumentLocs.first > 0; +} + +bool FunctionNameInfo::shouldTrack(OutputBuffer &OB) const { + if (!OB.isPrintingTopLevelFunctionType()) +return false; + + if (OB.isGtInsideTemplateArgs()) +return false; + + if (startedPrintingArguments()) +return false; + + return true; +} + +bool FunctionNameInfo::canFinalize(OutputBuffer &OB) const { + if (!OB.isPrintingTopLevelFunctionType()) +return false; + + if (OB.isGtInsideTemplateArgs()) +return false; + + if (!started
[Lldb-commits] [lldb] 739fe98 - [lldb][test] TestExprFromNonZeroFrame.py: fix windows build
Author: Michael Buch Date: 2025-04-03T12:21:46+01:00 New Revision: 739fe980802e17e49ab9cc2e4c18a48c88e15ef5 URL: https://github.com/llvm/llvm-project/commit/739fe980802e17e49ab9cc2e4c18a48c88e15ef5 DIFF: https://github.com/llvm/llvm-project/commit/739fe980802e17e49ab9cc2e4c18a48c88e15ef5.diff LOG: [lldb][test] TestExprFromNonZeroFrame.py: fix windows build On Windows this test was failing to link with following error: ``` make: Entering directory 'C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.test' C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe -gdwarf -O0 -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make/../../../../..//include -IC:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb/include -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\commands\expression\expr-from-non-zero-frame -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make -include C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make/test_common.h -fno-limit-debug-info -MT main.o -MD -MP -MF main.d -c -o main.o C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\commands\expression\expr-from-non-zero-frame/main.c C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe main.o -gdwarf -O0 -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make/../../../../..//include -IC:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb/include -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\commands\expression\expr-from-non-zero-frame -IC:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make -include C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\make/test_common.h -fno-limit-debug-info -fuse-ld=lld --driver-mode=g++ -o "a.out" lld-link: error: undefined symbol: printf >>> referenced by main.o:(func) clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile.rules:530: a.out] Error 1 make: Leaving directory 'C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.test' ``` Added: Modified: lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c Removed: diff --git a/lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py b/lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py index 9b1bcfb177765..623c5b87f14c7 100644 --- a/lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py +++ b/lldb/test/API/commands/expression/expr-from-non-zero-frame/TestExprFromNonZeroFrame.py @@ -16,7 +16,7 @@ def test(self): self.build() (_, _, thread, _) = lldbutil.run_to_source_breakpoint( -self, "Break here", lldb.SBFileSpec("main.c") +self, "return 5", lldb.SBFileSpec("main.c") ) frame = thread.GetFrameAtIndex(1) diff --git a/lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c b/lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c index d1675525cf4f2..abd52aeeb5b0b 100644 --- a/lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c +++ b/lldb/test/API/commands/expression/expr-from-non-zero-frame/main.c @@ -1,6 +1,3 @@ -int func(void) { - __builtin_printf("Break here"); - return 5; -} +int func(void) { return 5; } int main(int argc, const char *argv[]) { return func(); } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)
@@ -190,8 +190,83 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} bool ObjectFileXCOFF::IsStripped() { return false; } -void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {} - +void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) { + + if (m_sections_up) +return; + m_sections_up = std::make_unique(); + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); + +ModuleSP module_sp(GetModule()); +for (auto sIdx = m_binary->section_begin(); sIdx != m_binary->section_end(); + ++sIdx) { + llvm::Expected name = + m_binary->getSectionName(sIdx->getRawDataRefImpl()); + if (!name) { +llvm::Error err = name.takeError(); + } labath wrote: This isn't the right way to handle an error. llvm::Errors must be checked, according to https://llvm.org/docs/ProgrammersManual.html#recoverable-errors At this point, the best way to "handle" the errors is probably to log them, with something like this: ```suggestion if (!name) LLDB_LOG_ERROR(log, name.takeError(), "Some text: {0}"); ``` https://github.com/llvm/llvm-project/pull/131304 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)
@@ -190,8 +190,83 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} bool ObjectFileXCOFF::IsStripped() { return false; } -void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {} - +void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) { + + if (m_sections_up) +return; + m_sections_up = std::make_unique(); + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); + +ModuleSP module_sp(GetModule()); +for (auto sIdx = m_binary->section_begin(); sIdx != m_binary->section_end(); + ++sIdx) { + llvm::Expected name = + m_binary->getSectionName(sIdx->getRawDataRefImpl()); + if (!name) { +llvm::Error err = name.takeError(); + } + llvm::StringRef sect_name = *name; + ConstString const_sect_name(sect_name); + int sect_index = sIdx->getIndex(), idx = 1; + llvm::Expected section = + m_binary->getSectionByNum(sect_index); + if (!section) { labath wrote: same here https://github.com/llvm/llvm-project/pull/131304 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 0509932 - [lldb] Initialize active_row pointer variable
Author: Pavel Labath Date: 2025-04-03T15:15:09+02:00 New Revision: 0509932bb6a291ba11253f30c465ab3ad164ae08 URL: https://github.com/llvm/llvm-project/commit/0509932bb6a291ba11253f30c465ab3ad164ae08 DIFF: https://github.com/llvm/llvm-project/commit/0509932bb6a291ba11253f30c465ab3ad164ae08.diff LOG: [lldb] Initialize active_row pointer variable It's value is not set on all control flow paths. I believe this should fix the failure on some buildbots after #133247. Added: Modified: lldb/source/Target/RegisterContextUnwind.cpp Removed: diff --git a/lldb/source/Target/RegisterContextUnwind.cpp b/lldb/source/Target/RegisterContextUnwind.cpp index cb3d7ee479890..4f8b8a281a020 100644 --- a/lldb/source/Target/RegisterContextUnwind.cpp +++ b/lldb/source/Target/RegisterContextUnwind.cpp @@ -208,7 +208,7 @@ void RegisterContextUnwind::InitializeZerothFrame() { m_fast_unwind_plan_sp = GetFastUnwindPlanForFrame(); m_full_unwind_plan_sp = GetFullUnwindPlanForFrame(); - const UnwindPlan::Row *active_row; + const UnwindPlan::Row *active_row = nullptr; lldb::RegisterKind row_register_kind = eRegisterKindGeneric; // If we have LanguageRuntime UnwindPlan for this unwind, use those ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reapply "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders " (PR #134246)
labath wrote: (I wasn't able to reproduce this on my end, but I'm fairly certain that 0509932bb6a291ba11253f30c465ab3ad164ae08 fixes at least one of the crashes) https://github.com/llvm/llvm-project/pull/134246 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
yuvald-sweet-security wrote: Wrote a test and it seems to pass CI, what do you say? https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Creating a common configuration structure for launch and attach requests. (PR #133960)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/133960 >From 11ff51134e0632d800806e2319ce14bbb914ec2f Mon Sep 17 00:00:00 2001 From: John Harrison Date: Tue, 1 Apr 2025 11:27:31 -0700 Subject: [PATCH 1/2] [lldb-dap] Creating a common configuration structure for launch and attach requests. This moves all the common settings of the launch and attach operations into the `lldb_dap::protocol::DAPConfiguration`. These common settings can be in both `launch` and `attach` requests and allows us to isolate the DAP configuration operations into a single common location. This is split out from #133624. --- lldb/tools/lldb-dap/DAP.cpp | 41 +- lldb/tools/lldb-dap/DAP.h | 23 ++ .../lldb-dap/Handler/AttachRequestHandler.cpp | 21 +++--- .../lldb-dap/Handler/CompletionsHandler.cpp | 7 +- .../Handler/EvaluateRequestHandler.cpp| 3 +- .../lldb-dap/Handler/LaunchRequestHandler.cpp | 21 +++--- .../tools/lldb-dap/Handler/RequestHandler.cpp | 2 +- .../Handler/SetVariableRequestHandler.cpp | 3 +- .../Handler/StackTraceRequestHandler.cpp | 2 +- .../Handler/VariablesRequestHandler.cpp | 20 ++--- lldb/tools/lldb-dap/JSONUtils.cpp | 3 +- lldb/tools/lldb-dap/JSONUtils.h | 5 -- .../lldb-dap/Protocol/ProtocolRequests.h | 75 +++ lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 +- lldb/tools/lldb-dap/lldb-dap.cpp | 15 ++-- 15 files changed, 156 insertions(+), 91 deletions(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 8951384212f11..9361ba968e9c2 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -69,20 +69,20 @@ const char DEV_NULL[] = "/dev/null"; namespace lldb_dap { -DAP::DAP(llvm::StringRef path, Log *log, const ReplMode default_repl_mode, +llvm::StringRef DAP::debug_adapter_path = ""; + +DAP::DAP(Log *log, const ReplMode default_repl_mode, std::vector pre_init_commands, Transport &transport) -: debug_adapter_path(path), log(log), transport(transport), - broadcaster("lldb-dap"), exception_breakpoints(), - pre_init_commands(std::move(pre_init_commands)), - focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false), - enable_auto_variable_summaries(false), - enable_synthetic_child_debugging(false), - display_extended_backtrace(false), +: log(log), transport(transport), broadcaster("lldb-dap"), + exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID), + stop_at_entry(false), is_attach(false), restarting_process_id(LLDB_INVALID_PROCESS_ID), configuration_done_sent(false), waiting_for_run_in_terminal(false), progress_event_reporter( [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }), - reverse_request_seq(0), repl_mode(default_repl_mode) {} + reverse_request_seq(0), repl_mode(default_repl_mode) { + configuration.preInitCommands = std::move(pre_init_commands); +} DAP::~DAP() = default; @@ -505,8 +505,9 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression, bool partial_expression) { // Check for the escape hatch prefix. if (!expression.empty() && - llvm::StringRef(expression).starts_with(command_escape_prefix)) { -expression = expression.substr(command_escape_prefix.size()); + llvm::StringRef(expression) + .starts_with(configuration.commandEscapePrefix)) { +expression = expression.substr(configuration.commandEscapePrefix.size()); return ReplMode::Command; } @@ -546,7 +547,7 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression, << "Warning: Expression '" << term << "' is both an LLDB command and variable. It will be evaluated as " "a variable. To evaluate the expression as an LLDB command, use '" - << command_escape_prefix << "' as a prefix.\n"; + << configuration.commandEscapePrefix << "' as a prefix.\n"; } // Variables take preference to commands in auto, since commands can always @@ -593,36 +594,38 @@ DAP::RunLaunchCommands(llvm::ArrayRef launch_commands) { } llvm::Error DAP::RunInitCommands() { - if (!RunLLDBCommands("Running initCommands:", init_commands)) + if (!RunLLDBCommands("Running initCommands:", configuration.initCommands)) return createRunLLDBCommandsErrorMessage("initCommands"); return llvm::Error::success(); } llvm::Error DAP::RunPreInitCommands() { - if (!RunLLDBCommands("Running preInitCommands:", pre_init_commands)) + if (!RunLLDBCommands("Running preInitCommands:", + configuration.preInitCommands)) return createRunLLDBCommandsErrorMessage("preInitCommands"); return llvm::Error::success(); } llvm::Error DAP::RunPreRunCommands() { - if (!RunLLDBCommands("Running preRunCommands:", pre_run_co
[Lldb-commits] [lldb] [lldb-dap] Creating a common configuration structure for launch and attach requests. (PR #133960)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: John Harrison (ashgti) Changes This moves all the common settings of the launch and attach operations into the `lldb_dap::protocol::DAPConfiguration`. These common settings can be in both `launch` and `attach` requests and allows us to isolate the DAP configuration operations into a single common location. This is split out from #133624. --- Patch is 29.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133960.diff 15 Files Affected: - (modified) lldb/tools/lldb-dap/DAP.cpp (+22-19) - (modified) lldb/tools/lldb-dap/DAP.h (+7-16) - (modified) lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp (+11-10) - (modified) lldb/tools/lldb-dap/Handler/CompletionsHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp (+11-10) - (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+1-1) - (modified) lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp (+1-1) - (modified) lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp (+10-10) - (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+1-2) - (modified) lldb/tools/lldb-dap/JSONUtils.h (-5) - (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.h (+75) - (modified) lldb/tools/lldb-dap/SourceBreakpoint.cpp (+3-3) - (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+6-9) ``diff diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 8951384212f11..9361ba968e9c2 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -69,20 +69,20 @@ const char DEV_NULL[] = "/dev/null"; namespace lldb_dap { -DAP::DAP(llvm::StringRef path, Log *log, const ReplMode default_repl_mode, +llvm::StringRef DAP::debug_adapter_path = ""; + +DAP::DAP(Log *log, const ReplMode default_repl_mode, std::vector pre_init_commands, Transport &transport) -: debug_adapter_path(path), log(log), transport(transport), - broadcaster("lldb-dap"), exception_breakpoints(), - pre_init_commands(std::move(pre_init_commands)), - focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false), - enable_auto_variable_summaries(false), - enable_synthetic_child_debugging(false), - display_extended_backtrace(false), +: log(log), transport(transport), broadcaster("lldb-dap"), + exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID), + stop_at_entry(false), is_attach(false), restarting_process_id(LLDB_INVALID_PROCESS_ID), configuration_done_sent(false), waiting_for_run_in_terminal(false), progress_event_reporter( [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }), - reverse_request_seq(0), repl_mode(default_repl_mode) {} + reverse_request_seq(0), repl_mode(default_repl_mode) { + configuration.preInitCommands = std::move(pre_init_commands); +} DAP::~DAP() = default; @@ -505,8 +505,9 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression, bool partial_expression) { // Check for the escape hatch prefix. if (!expression.empty() && - llvm::StringRef(expression).starts_with(command_escape_prefix)) { -expression = expression.substr(command_escape_prefix.size()); + llvm::StringRef(expression) + .starts_with(configuration.commandEscapePrefix)) { +expression = expression.substr(configuration.commandEscapePrefix.size()); return ReplMode::Command; } @@ -546,7 +547,7 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression, << "Warning: Expression '" << term << "' is both an LLDB command and variable. It will be evaluated as " "a variable. To evaluate the expression as an LLDB command, use '" - << command_escape_prefix << "' as a prefix.\n"; + << configuration.commandEscapePrefix << "' as a prefix.\n"; } // Variables take preference to commands in auto, since commands can always @@ -593,36 +594,38 @@ DAP::RunLaunchCommands(llvm::ArrayRef launch_commands) { } llvm::Error DAP::RunInitCommands() { - if (!RunLLDBCommands("Running initCommands:", init_commands)) + if (!RunLLDBCommands("Running initCommands:", configuration.initCommands)) return createRunLLDBCommandsErrorMessage("initCommands"); return llvm::Error::success(); } llvm::Error DAP::RunPreInitCommands() { - if (!RunLLDBCommands("Running preInitCommands:", pre_init_commands)) + if (!RunLLDBCommands("Running preInitCommands:", + configuration.preInitCommands)) return createRunLLDBCommandsErrorMessage("preInitCommands"); return llvm::Error::success(); } llvm::Error DAP::RunPreRunCommands() { - if (!RunLLDBCommands("Running preRunCommands:", pre_run_comman
[Lldb-commits] [lldb] [lldb-dap] Creating a common configuration structure for launch and attach requests. (PR #133960)
@@ -118,6 +118,81 @@ bool fromJSON(const llvm::json::Value &, InitializeRequestArguments &, /// Response to `initialize` request. The capabilities of this debug adapter. using InitializeResponseBody = std::optional; +/// DAP Launch and Attach common configurations. +struct DAPConfiguration { ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/133960 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP] [libcxxabi][ItaniumDemangle] Add infrastructure to track location information of parts of a demangled function name (PR #133249)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/133249 >From 0875195a7ed39c21e9b639bf66d56b48e9869e51 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 11 Mar 2025 08:57:13 + Subject: [PATCH 1/2] [llvm][ItaniumDemangle] Add function name location tracking --- libcxxabi/src/demangle/ItaniumDemangle.h | 21 libcxxabi/src/demangle/Utility.cpp| 112 ++ libcxxabi/src/demangle/Utility.h | 91 +++--- libcxxabi/src/demangle/cp-to-llvm.sh | 62 +++--- llvm/include/llvm/Demangle/ItaniumDemangle.h | 21 llvm/include/llvm/Demangle/Utility.h | 91 +++--- llvm/lib/Demangle/CMakeLists.txt | 1 + llvm/lib/Demangle/README.txt | 61 ++ llvm/lib/Demangle/Utility.cpp | 112 ++ .../Demangle/ItaniumDemangleTest.cpp | 112 ++ 10 files changed, 635 insertions(+), 49 deletions(-) create mode 100644 libcxxabi/src/demangle/Utility.cpp create mode 100644 llvm/lib/Demangle/README.txt create mode 100644 llvm/lib/Demangle/Utility.cpp diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index 3df41b5f4d7d0..b5a0a86b119f4 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -851,11 +851,13 @@ class FunctionType final : public Node { // by printing out the return types's left, then print our parameters, then // finally print right of the return type. void printLeft(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); Ret->printLeft(OB); OB += " "; } void printRight(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); OB.printOpen(); Params.printWithComma(OB); OB.printClose(); @@ -971,18 +973,32 @@ class FunctionEncoding final : public Node { const Node *getName() const { return Name; } void printLeft(OutputBuffer &OB) const override { +// Nested FunctionEncoding parsing can happen with following productions: +// * +// * +auto Scoped = OB.enterFunctionTypePrinting(); + if (Ret) { Ret->printLeft(OB); if (!Ret->hasRHSComponent(OB)) OB += " "; } + +OB.FunctionInfo.updateScopeStart(OB); + Name->print(OB); } void printRight(OutputBuffer &OB) const override { +auto Scoped = OB.enterFunctionTypePrinting(); +OB.FunctionInfo.finalizeStart(OB); + OB.printOpen(); Params.printWithComma(OB); OB.printClose(); + +OB.FunctionInfo.finalizeArgumentEnd(OB); + if (Ret) Ret->printRight(OB); @@ -1005,6 +1021,8 @@ class FunctionEncoding final : public Node { OB += " requires "; Requires->print(OB); } + +OB.FunctionInfo.finalizeEnd(OB); } }; @@ -1072,7 +1090,9 @@ struct NestedName : Node { void printLeft(OutputBuffer &OB) const override { Qual->print(OB); OB += "::"; +OB.FunctionInfo.updateScopeEnd(OB); Name->print(OB); +OB.FunctionInfo.updateBasenameEnd(OB); } }; @@ -1633,6 +1653,7 @@ struct NameWithTemplateArgs : Node { void printLeft(OutputBuffer &OB) const override { Name->print(OB); +OB.FunctionInfo.updateBasenameEnd(OB); TemplateArgs->print(OB); } }; diff --git a/libcxxabi/src/demangle/Utility.cpp b/libcxxabi/src/demangle/Utility.cpp new file mode 100644 index 0..04516082b3443 --- /dev/null +++ b/libcxxabi/src/demangle/Utility.cpp @@ -0,0 +1,112 @@ +//===--- Utility.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Provide some utility classes for use in the demangler. +// There are two copies of this file in the source tree. The one in libcxxabi +// is the original and the one in llvm is the copy. Use cp-to-llvm.sh to update +// the copy. See README.txt for more details. +// +//===--===// + +#include "Utility.h" +#include "DemangleConfig.h" + +DEMANGLE_NAMESPACE_BEGIN + +bool FunctionNameInfo::startedPrintingArguments() const { + return ArgumentLocs.first > 0; +} + +bool FunctionNameInfo::shouldTrack(OutputBuffer &OB) const { + if (!OB.isPrintingTopLevelFunctionType()) +return false; + + if (OB.isGtInsideTemplateArgs()) +return false; + + if (startedPrintingArguments()) +return false; + + return true; +} + +bool FunctionNameInfo::canFinalize(OutputBuffer &OB) const { + if (!OB.isPrintingTopLevelFunctionType()) +return false; + + if (OB.isGtInsideTemplateArgs()) +return false; + + if (!started
[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP] [libcxxabi][ItaniumDemangle] Add infrastructure to track location information of parts of a demangled function name (PR #133249)
@@ -6176,6 +6180,10 @@ struct ManglingParser : AbstractManglingParser, Alloc> { Alloc>::AbstractManglingParser; }; +inline void OutputBuffer::printLeft(const Node &N) { N.printLeft(*this); } Michael137 wrote: @zygoloid is this what you had in mind? I moved the `TrackingOutputBuffer` into LLDB now. That's where all the tracking logic would live. It's a bit unfortunate we have to duplicate some of the printing logic there (though at least we're only doing it for a couple of nodes) https://github.com/llvm/llvm-project/pull/133249 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/131304 >From 106e137fea7d4b420ce3d97a8df16c3a91400997 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 14 Mar 2025 02:51:21 -0500 Subject: [PATCH 1/3] Support for XCOFF Sections --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 153 +- 1 file changed, 114 insertions(+), 39 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index b54d43c5dd737..0dd9126468923 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -190,50 +190,125 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} bool ObjectFileXCOFF::IsStripped() { return false; } -void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {} - -void ObjectFileXCOFF::Dump(Stream *s) {} - -ArchSpec ObjectFileXCOFF::GetArchitecture() { - ArchSpec arch_spec = - ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE); - return arch_spec; +void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) { + + if (m_sections_up) +return; + m_sections_up = std::make_unique(); + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); + +ModuleSP module_sp(GetModule()); +for (auto sIdx = m_binary->section_begin(); sIdx != m_binary->section_end(); + ++sIdx) { + llvm::Expected name = + m_binary->getSectionName(sIdx->getRawDataRefImpl()); + if (!name) { +llvm::Error err = name.takeError(); + } + llvm::StringRef sect_name = *name; + ConstString const_sect_name(sect_name); + int sect_index = sIdx->getIndex(), idx = 1; + llvm::Expected section = + m_binary->getSectionByNum(sect_index); + if (!section) { +llvm::Error err = section.takeError(); + } + llvm::object::DataRefImpl dataref = section.get(); + const llvm::object::XCOFFSectionHeader64 *sectionPtr = + reinterpret_cast( + dataref.p); + + SectionType section_type = lldb::eSectionTypeOther; + if (sectionPtr->Flags & XCOFF::STYP_TEXT) +section_type = eSectionTypeCode; + if (sectionPtr->Flags & XCOFF::STYP_DATA) +section_type = eSectionTypeData; + if (sectionPtr->Flags & XCOFF::STYP_BSS) +section_type = eSectionTypeZeroFill; + if (sectionPtr->Flags & XCOFF::STYP_DWARF) { +SectionType section_type = +llvm::StringSwitch(sect_name) +.Case(".dwinfo", eSectionTypeDWARFDebugInfo) +.Case(".dwline", eSectionTypeDWARFDebugLine) +.Case(".dwabrev", eSectionTypeDWARFDebugAbbrev) +.Default(eSectionTypeInvalid); + +if (section_type == eSectionTypeInvalid) + section_type = lldb::eSectionTypeOther; + } + SectionSP section_sp(new Section( + module_sp, // Module to which this section belongs + this,// Object file to which this section belongs + idx++, // Section ID is the 1 based section index. + const_sect_name, // Name of this section + section_type, + sectionPtr->VirtualAddress, // File VM address == addresses as + // they are found in the object file + sectionPtr->SectionSize, // VM size in bytes of this section + sectionPtr->FileOffsetToRawData, // Offset to the data for this + // section in the file + sectionPtr->SectionSize, // Size in bytes of this section as found in + // the file + 0, // FIXME: alignment + sectionPtr->Flags)); // Flags for this section + + uint32_t permissions = 0; + permissions |= ePermissionsReadable; + if (sectionPtr->Flags & (XCOFF::STYP_DATA | XCOFF::STYP_BSS)) +permissions |= ePermissionsWritable; + if (sectionPtr->Flags & XCOFF::STYP_TEXT) +permissions |= ePermissionsExecutable; + section_sp->SetPermissions(permissions); + + m_sections_up->AddSection(section_sp); + unified_section_list.AddSection(section_sp); +} + } } + void ObjectFileXCOFF::Dump(Stream * s) {} -UUID ObjectFileXCOFF::GetUUID() { return UUID(); } + ArchSpec ObjectFileXCOFF::GetArchitecture() { +ArchSpec arch_spec = +ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE); +return arch_spec; + } -uint32_t ObjectFileXCOFF::GetDependentModules(FileSpecList &files) { return 0; } + UUID ObjectFileXCOFF::GetUUID() { return UUID(); } -ObjectFile::Type ObjectFileXCOFF::CalculateType() { - if (m_binary->fileHeader64()->Flags & XCOFF::F_EXEC) -return eTypeExecutable; - else if (m_binary->fileHeader
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,61 @@ +//===-- DILEval.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_VALUEOBJECT_DILEVAL_H +#define LLDB_VALUEOBJECT_DILEVAL_H + +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/DILParser.h" +#include +#include labath wrote: ```suggestion #include #include "llvm/Support/StringRef.h" #include "llvm/Support/Error.h" ``` https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,258 @@ +//===-- DILParser.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This implements the recursive descent parser for the Data Inspection +// Language (DIL), and its helper functions, which will eventually underlie the +// 'frame variable' command. The language that this parser recognizes is +// described in lldb/docs/dil-expr-lang.ebnf +// +//===--===// + +#include "lldb/ValueObject/DILParser.h" +#include "lldb/Target/ExecutionContextScope.h" +#include "lldb/Utility/DiagnosticsRendering.h" +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/DILEval.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/FormatAdapters.h" +#include +#include +#include +#include +#include + +namespace lldb_private::dil { + +DILDiagnosticError::DILDiagnosticError(llvm::StringRef expr, + const std::string &message, uint32_t loc, + uint16_t err_len) +: ErrorInfo(make_error_code(std::errc::invalid_argument)) { + DiagnosticDetail::SourceLocation sloc = { + FileSpec{}, /*line=*/1, static_cast(loc + 1), + err_len,false, /*in_user_input=*/true}; + std::string rendered_msg = + llvm::formatv(":1:{0}: {1}\n 1 | {2}\n | ^", +loc + 1, message, expr); + DiagnosticDetail detail; + detail.source_location = sloc; + detail.severity = lldb::eSeverityError; + detail.message = message; + detail.rendered = rendered_msg; + m_detail = std::move(detail); +} + +llvm::Expected +DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer, + std::shared_ptr frame_sp, + lldb::DynamicValueType use_dynamic, bool use_synthetic, + bool fragile_ivar, bool check_ptr_vs_member) { + llvm::Error error = llvm::Error::success(); + DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic, + fragile_ivar, check_ptr_vs_member, error); + + ASTNodeUP node_up = parser.Run(); + + if (error) +return error; + + return node_up; +} + +DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer, + std::shared_ptr frame_sp, + lldb::DynamicValueType use_dynamic, bool use_synthetic, + bool fragile_ivar, bool check_ptr_vs_member, + llvm::Error &error) +: m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), + m_dil_lexer(std::move(lexer)), m_error(error), m_use_dynamic(use_dynamic), + m_use_synthetic(use_synthetic), m_fragile_ivar(fragile_ivar), + m_check_ptr_vs_member(check_ptr_vs_member) {} + +ASTNodeUP DILParser::Run() { + ASTNodeUP expr = ParseExpression(); + + Expect(Token::Kind::eof); + + return expr; +} + +// Parse an expression. +// +// expression: +//primary_expression +// +ASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); } + +// Parse a primary_expression. +// +// primary_expression: +//id_expression +//"(" expression ")" +// +ASTNodeUP DILParser::ParsePrimaryExpression() { + if (CurToken().IsOneOf({Token::coloncolon, Token::identifier})) { +// Save the source location for the diagnostics message. +uint32_t loc = CurToken().GetLocation(); +auto identifier = ParseIdExpression(); + +return std::make_unique(loc, identifier); + } + + if (CurToken().Is(Token::l_paren)) { +m_dil_lexer.Advance(); +auto expr = ParseExpression(); +Expect(Token::r_paren); +m_dil_lexer.Advance(); +return expr; + } + + BailOut(llvm::formatv("Unexpected token: {0}", CurToken()), + CurToken().GetLocation(), CurToken().GetSpelling().length()); + return std::make_unique(); +} + +// Parse nested_name_specifier. +// +// nested_name_specifier: +//type_name "::" +//namespace_name "::" +//nested_name_specifier identifier "::" +// +std::string DILParser::ParseNestedNameSpecifier() { + // The first token in nested_name_specifier is always an identifier, or + // '(anonymous namespace)'. + if (CurToken().IsNot(Token::identifier) && CurToken().IsNot(Token::l_paren)) +return ""; + + // Anonymous namespaces need to be treated specially: They are represented + // the the string '(anonymous namespace)', which has a space in it (throwing + // off normal parsing) and is not actually proper C++> Check to see if we're + // looking at '(anonymous namespace)::...' + if (CurToken().Is(Token::l_paren)) { +// Look for all the pieces, in order: +// l_paren 'anonymous' 'namespace' r_paren coloncolon +if (m_dil_lexer.LookAhead(1).Is(Token::identifier) && +(m_dil_lexer.LookAhead(1).GetSpelling() == "anon
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,258 @@ +//===-- DILParser.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This implements the recursive descent parser for the Data Inspection +// Language (DIL), and its helper functions, which will eventually underlie the +// 'frame variable' command. The language that this parser recognizes is +// described in lldb/docs/dil-expr-lang.ebnf +// +//===--===// + +#include "lldb/ValueObject/DILParser.h" +#include "lldb/Target/ExecutionContextScope.h" +#include "lldb/Utility/DiagnosticsRendering.h" +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/DILEval.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/FormatAdapters.h" +#include +#include +#include +#include +#include + +namespace lldb_private::dil { + +DILDiagnosticError::DILDiagnosticError(llvm::StringRef expr, + const std::string &message, uint32_t loc, + uint16_t err_len) +: ErrorInfo(make_error_code(std::errc::invalid_argument)) { + DiagnosticDetail::SourceLocation sloc = { + FileSpec{}, /*line=*/1, static_cast(loc + 1), + err_len,false, /*in_user_input=*/true}; + std::string rendered_msg = + llvm::formatv(":1:{0}: {1}\n 1 | {2}\n | ^", +loc + 1, message, expr); + DiagnosticDetail detail; + detail.source_location = sloc; + detail.severity = lldb::eSeverityError; + detail.message = message; + detail.rendered = rendered_msg; + m_detail = std::move(detail); labath wrote: ```suggestion m_detail.source_location = sloc; m_detail.severity = lldb::eSeverityError; m_detail.message = message; m_detail.rendered = std::move(rendered_msg); ``` https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,95 @@ +//===-- DILAST.h *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_VALUEOBJECT_DILAST_H +#define LLDB_VALUEOBJECT_DILAST_H + +#include "lldb/ValueObject/ValueObject.h" +#include labath wrote: ```suggestion #include #include #include "llvm/Support/Error.h" ``` https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,236 @@ +//===-- DILEval.cpp ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/ValueObject/DILEval.h" +#include "lldb/Symbol/VariableList.h" +#include "lldb/Target/RegisterContext.h" +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/ValueObject.h" +#include "lldb/ValueObject/ValueObjectRegister.h" +#include "lldb/ValueObject/ValueObjectVariable.h" +#include "llvm/Support/FormatAdapters.h" +#include + +namespace lldb_private::dil { + +static lldb::ValueObjectSP LookupStaticIdentifier( +VariableList &variable_list, std::shared_ptr exe_scope, +llvm::StringRef name_ref, llvm::StringRef unqualified_name) { + // First look for an exact match to the (possibly) qualified name. + for (const lldb::VariableSP &var_sp : variable_list) { +lldb::ValueObjectSP valobj_sp( +ValueObjectVariable::Create(exe_scope.get(), var_sp)); +if (valobj_sp && valobj_sp->GetVariable() && +(valobj_sp->GetVariable()->NameMatches(ConstString(name_ref + return valobj_sp; + } + + // If the qualified name is the same as the unqualfied name, there's nothing + // more to be done. + if (name_ref == unqualified_name) +return nullptr; + + // We didn't match the qualified name; try to match the unqualified name. + for (const lldb::VariableSP &var_sp : variable_list) { +lldb::ValueObjectSP valobj_sp( +ValueObjectVariable::Create(exe_scope.get(), var_sp)); +if (valobj_sp && valobj_sp->GetVariable() && +(valobj_sp->GetVariable()->NameMatches(ConstString(unqualified_name + return valobj_sp; + } + + return nullptr; +} + +static lldb::VariableSP DILFindVariable(ConstString name, +lldb::VariableListSP variable_list) { + lldb::VariableSP exact_match; + std::vector possible_matches; + + for (lldb::VariableSP var_sp : *variable_list) { +llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef(); +// Check for global vars, which might start with '::'. +str_ref_name.consume_front("::"); + +if (str_ref_name == name.GetStringRef()) + possible_matches.push_back(var_sp); +else if (var_sp->NameMatches(name)) + possible_matches.push_back(var_sp); + } + + // Look for exact matches (favors local vars over global vars) + auto exact_match_it = + llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) { +return var_sp->GetName() == name; + }); + + if (exact_match_it != possible_matches.end()) +return *exact_match_it; + + // Look for a global var exact match. + for (auto var_sp : possible_matches) { +llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef(); +str_ref_name.consume_front("::"); +if (str_ref_name == name.GetStringRef()) + return var_sp; + } + + // If there's a single non-exact match, take it. + if (possible_matches.size() == 1) +return possible_matches[0]; + + return nullptr; +} + +lldb::ValueObjectSP LookupGlobalIdentifier( +llvm::StringRef name_ref, std::shared_ptr stack_frame, +lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic, +CompilerType *scope_ptr) { + // First look for match in "local" global variables. + lldb::VariableListSP variable_list(stack_frame->GetInScopeVariableList(true)); + name_ref.consume_front("::"); + + lldb::ValueObjectSP value_sp; + if (variable_list) { +lldb::VariableSP var_sp = +DILFindVariable(ConstString(name_ref), variable_list); +if (var_sp) + value_sp = + stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic); + } + + if (value_sp) +return value_sp; + + // Also check for static global vars. + if (variable_list) { +const char *type_name = ""; +if (scope_ptr) + type_name = scope_ptr->GetCanonicalType().GetTypeName().AsCString(); +std::string name_with_type_prefix = +llvm::formatv("{0}::{1}", type_name, name_ref).str(); +value_sp = LookupStaticIdentifier(*variable_list, stack_frame, + name_with_type_prefix, name_ref); +if (!value_sp) + value_sp = LookupStaticIdentifier(*variable_list, stack_frame, name_ref, +name_ref); + } + + if (value_sp) +return value_sp; + + // Check for match in modules global variables. + VariableList modules_var_list; + target_sp->GetImages().FindGlobalVariables( + ConstString(name_ref), std::numeric_limits::max(), + modules_var_list); + if (modules_var_list.Empty()) +return nullptr; + + for (const lldb::VariableSP &var_sp : modules_var_list) { +std::string qualified_name = llvm::formatv("::{0}", name
[Lldb-commits] [lldb] [LLDB][Telemetry] Collect telemetry from client when allowed. (PR #129728)
@@ -965,6 +965,22 @@ SBTarget SBDebugger::GetDummyTarget() { return sb_target; } +void SBDebugger::DispatchClientTelemetry(const lldb::SBStructuredData &entry) { + LLDB_INSTRUMENT_VA(this); + // Disable client-telemetry for SWIG. + // This prevent arbitrary python client (pretty printers, whatnot) from sending + // telemetry without vendors knowing. +#ifndef SWIG labath wrote: Soo, my reason for suggesting `ifndef SWIG` is because that hides the API from python (specifically from python data formatters). While I think it *might* be reasonable to provide data formatters a way to report their health metrics, I don't think that's a problem you're trying to solve here. I'm also aware that it's an imperfect solution as it makes no difference between "python code running in lldb" and "python code driving lldb". I think the "outside vs. inside" distinction is what we'd really want to capture here since in theory one should be able rewrite lldb-dap in python and have everything still work, but I don't know how to forbid one without the other. Bottom line: I'm not insisting on the `ifndef SWIG`, I'm just trying to make sure there's a reasonable story for who can call this API. If you can make your use case work without that, even better. https://github.com/llvm/llvm-project/pull/129728 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo (PR #134160)
https://github.com/felipepiovezan updated https://github.com/llvm/llvm-project/pull/134160 >From 48150d4bb0daf57b708f4fa86285f028eeff0da6 Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Wed, 2 Apr 2025 09:28:56 -0700 Subject: [PATCH 1/3] [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo This NFC patch simplifies the main loop in HandleProcessStateChanged event by moving duplicated code into the StopInfo class, also allowing StopInfo subclasses to override behavior. More specifically, two functions are created: * ShouldShow: should a Thread with such StopInfo should be printed when the debugger stops? Currently, no StopInfo subclasses override this, but a subsequent patch will fix a bug by making StopInfoBreakpoint check whether the breakpoint is internal. * ShouldSelect: should a Thread with such a StopInfo be selected? This is currently overridden by StopInfoUnixSignal but will, in the future, be overridden by StopInfoBreakpoint. --- lldb/include/lldb/Target/StopInfo.h | 13 + lldb/source/Target/Process.cpp | 78 ++--- lldb/source/Target/StopInfo.cpp | 16 +++--- 3 files changed, 37 insertions(+), 70 deletions(-) diff --git a/lldb/include/lldb/Target/StopInfo.h b/lldb/include/lldb/Target/StopInfo.h index 9a13371708be5..5fcd3784d6f1d 100644 --- a/lldb/include/lldb/Target/StopInfo.h +++ b/lldb/include/lldb/Target/StopInfo.h @@ -118,6 +118,19 @@ class StopInfo : public std::enable_shared_from_this { StructuredData::ObjectSP GetExtendedInfo() { return m_extended_info; } + /// Returns true if this is a stop reason that should be shown to a user when + /// stopping. + virtual bool ShouldShow() const { return IsValid(); } + + /// Returns true if this is a stop reason that should cause a thread to be + /// selected when stopping. + virtual bool ShouldSelect() const { +lldb::StopReason reason = GetStopReason(); +return reason != lldb::eStopReasonNone && + reason != lldb::eStopReasonHistoryBoundary && + reason != lldb::eStopReasonInvalid; + } + static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 369933234ccca..502f11b5628db 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -808,30 +808,11 @@ bool Process::HandleProcessStateChangedEvent( std::lock_guard guard(thread_list.GetMutex()); ThreadSP curr_thread(thread_list.GetSelectedThread()); -ThreadSP thread; -StopReason curr_thread_stop_reason = eStopReasonInvalid; -bool prefer_curr_thread = false; -if (curr_thread && curr_thread->IsValid()) { - curr_thread_stop_reason = curr_thread->GetStopReason(); - switch (curr_thread_stop_reason) { - case eStopReasonNone: - case eStopReasonInvalid: -// Don't prefer the current thread if it didn't stop for a reason. -break; - case eStopReasonSignal: { -// We need to do the same computation we do for other threads -// below in case the current thread happens to be the one that -// stopped for the no-stop signal. -uint64_t signo = curr_thread->GetStopInfo()->GetValue(); -if (process_sp->GetUnixSignals()->GetShouldStop(signo)) - prefer_curr_thread = true; - } break; - default: -prefer_curr_thread = true; -break; - } + +if (curr_thread && curr_thread->IsValid()) curr_thread_stop_info_sp = curr_thread->GetStopInfo(); -} +bool prefer_curr_thread = curr_thread_stop_info_sp && + curr_thread_stop_info_sp->ShouldSelect(); if (!prefer_curr_thread) { // Prefer a thread that has just completed its plan over another @@ -839,54 +820,23 @@ bool Process::HandleProcessStateChangedEvent( ThreadSP plan_thread; ThreadSP other_thread; - const size_t num_threads = thread_list.GetSize(); - size_t i; - for (i = 0; i < num_threads; ++i) { -thread = thread_list.GetThreadAtIndex(i); -StopReason thread_stop_reason = thread->GetStopReason(); -switch (thread_stop_reason) { -case eStopReasonInvalid: -case eStopReasonNone: -case eStopReasonHistoryBoundary: - break; - -case eStopReasonSignal: { - // Don't select a signal thread if we weren't going to stop at - // that signal. We have to have had another reason for stopping - // here, and the user doesn't want to see this thread. - uint64_t signo = thread->GetStopInfo()->GetValue(); - if (process_sp->GetUnixSignals()->GetShouldStop(signo))
[Lldb-commits] [lldb] [lldb] Update examples in docs/use/python-reference.rst to work with Python 3 (PR #134204)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/134204 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] c14b6e9 - [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo (#134160)
Author: Felipe de Azevedo Piovezan Date: 2025-04-03T07:41:29-07:00 New Revision: c14b6e90bd140c2290258fa9dbe0fc1ad8939111 URL: https://github.com/llvm/llvm-project/commit/c14b6e90bd140c2290258fa9dbe0fc1ad8939111 DIFF: https://github.com/llvm/llvm-project/commit/c14b6e90bd140c2290258fa9dbe0fc1ad8939111.diff LOG: [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo (#134160) This NFC patch simplifies the main loop in HandleProcessStateChanged event by moving duplicated code into the StopInfo class, also allowing StopInfo subclasses to override behavior. More specifically, two functions are created: * ShouldShow: should a Thread with such StopInfo should be printed when the debugger stops? Currently, no StopInfo subclasses override this, but a subsequent patch will fix a bug by making StopInfoBreakpoint check whether the breakpoint is internal. * ShouldSelect: should a Thread with such a StopInfo be selected? This is currently overridden by StopInfoUnixSignal but will, in the future, be overridden by StopInfoBreakpoint. Added: Modified: lldb/include/lldb/Target/StopInfo.h lldb/source/Target/Process.cpp lldb/source/Target/StopInfo.cpp Removed: diff --git a/lldb/include/lldb/Target/StopInfo.h b/lldb/include/lldb/Target/StopInfo.h index 9a13371708be5..368ec51d81891 100644 --- a/lldb/include/lldb/Target/StopInfo.h +++ b/lldb/include/lldb/Target/StopInfo.h @@ -118,6 +118,19 @@ class StopInfo : public std::enable_shared_from_this { StructuredData::ObjectSP GetExtendedInfo() { return m_extended_info; } + /// Returns true if this is a stop reason that should be shown to a user when + /// viewing the thread with this stop info. + virtual bool ShouldShow() const { return IsValid(); } + + /// Returns true if this is a stop reason that should cause a thread to be + /// selected when stopping. + virtual bool ShouldSelect() const { +lldb::StopReason reason = GetStopReason(); +return reason != lldb::eStopReasonNone && + reason != lldb::eStopReasonHistoryBoundary && + reason != lldb::eStopReasonInvalid; + } + static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 2adda309dea9c..0b7ba343c11f2 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -808,30 +808,11 @@ bool Process::HandleProcessStateChangedEvent( std::lock_guard guard(thread_list.GetMutex()); ThreadSP curr_thread(thread_list.GetSelectedThread()); -ThreadSP thread; -StopReason curr_thread_stop_reason = eStopReasonInvalid; -bool prefer_curr_thread = false; -if (curr_thread && curr_thread->IsValid()) { - curr_thread_stop_reason = curr_thread->GetStopReason(); - switch (curr_thread_stop_reason) { - case eStopReasonNone: - case eStopReasonInvalid: -// Don't prefer the current thread if it didn't stop for a reason. -break; - case eStopReasonSignal: { -// We need to do the same computation we do for other threads -// below in case the current thread happens to be the one that -// stopped for the no-stop signal. -uint64_t signo = curr_thread->GetStopInfo()->GetValue(); -if (process_sp->GetUnixSignals()->GetShouldStop(signo)) - prefer_curr_thread = true; - } break; - default: -prefer_curr_thread = true; -break; - } + +if (curr_thread && curr_thread->IsValid()) curr_thread_stop_info_sp = curr_thread->GetStopInfo(); -} +bool prefer_curr_thread = curr_thread_stop_info_sp && + curr_thread_stop_info_sp->ShouldSelect(); if (!prefer_curr_thread) { // Prefer a thread that has just completed its plan over another @@ -839,47 +820,16 @@ bool Process::HandleProcessStateChangedEvent( ThreadSP plan_thread; ThreadSP other_thread; - const size_t num_threads = thread_list.GetSize(); - size_t i; - for (i = 0; i < num_threads; ++i) { -thread = thread_list.GetThreadAtIndex(i); -StopReason thread_stop_reason = thread->GetStopReason(); -switch (thread_stop_reason) { -case eStopReasonInvalid: -case eStopReasonNone: -case eStopReasonHistoryBoundary: - break; - -case eStopReasonSignal: { - // Don't select a signal thread if we weren't going to stop at - // that signal. We have to have had another reason for stopping - // here, and the user doesn't want to see this thread. - uint64_t signo = thr
[Lldb-commits] [lldb] [lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo (PR #134160)
https://github.com/felipepiovezan closed https://github.com/llvm/llvm-project/pull/134160 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits