aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test/lldbutil.py
AgeCommit message (Collapse)AuthorFilesLines
2025-08-18Decent to Descent (#154040)LauraElanorJones1-4/+3
[lldb] Rename RecursiveDecentFormatter to RecursiveDescentFormatter (NFC)
2025-06-25[lldb] Fix FindProcessImpl() for iOS simulators (#139174)royitaqi1-0/+87
# Benefit This patch fixes: 1. After `platform select ios-simulator`, `platform process list` will now print processes which are running in the iOS simulator. Previously, no process will be listed. 2. After `platform select ios-simulator`, `platform attach --name <name>` will succeed. Previously, it will error out saying no process is found. # Several bugs that is being fixed 1. During the process listing, add `aarch64` to the list of CPU types for which iOS simulators are checked for. 2. Given a candidate process, when checking for simulators, the original code will find the desired environment variable (`SIMULATOR_UDID`) and set the OS to iOS, but then the immediate next environment variable will set it back to macOS. 3. For processes running on simulator, set the triple's `Environment` to `Simulator`, so that such processes can pass the filtering [in this line](https://fburl.com/8nivnrjx). The original code leave it as the default `UnknownEnvironment`. # Manual test **With this patch:** ``` royshi-mac-home ~/public_llvm/build % bin/lldb (lldb) platform select ios-simulator (lldb) platform process list 240 matching processes were found on "ios-simulator" PID PARENT USER TRIPLE NAME ====== ====== ========== ============================== ============================ 40511 28844 royshi arm64-apple-ios-simulator FocusPlayground // my toy iOS app running on simulator ... // omit 28844 1 royshi arm64-apple-ios-simulator launchd_sim (lldb) process attach --name FocusPlayground Process 40511 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x0000000104e3cb70 libsystem_kernel.dylib`mach_msg2_trap + 8 libsystem_kernel.dylib`mach_msg2_trap: -> 0x104e3cb70 <+8>: ret ... // omit ``` **Without this patch:** ``` $ bin/lldb (lldb) platform select ios-simulator (lldb) platform process list error: no processes were found on the "ios-simulator" platform (lldb) process attach --name FocusPlayground error: attach failed: could not find a process named FocusPlayground ``` # Unittest See PR.
2025-01-25[lldb] Delete lldbutil.PrintableRegex (NFC)Dave Lee1-15/+0
Use of this class wasn't making use of the original regex string. Note that `re.Pattern` has a `pattern` property to access the original regex.
2025-01-25[lldb] Delete unused lldbutil.print_registers (NFC)Dave Lee1-27/+0
2024-11-24[lldb] Remove lldbutil.get_stack_frames (NFC) (#117505)Dave Lee1-11/+0
`SBThread.frames` can be used instead of `get_stack_frames`.
2024-09-12[lldb][testing] Check all stop reasons in ↵Felipe de Azevedo Piovezan1-3/+10
get_threads_stopped_at_breakpoint_id (#108281) If multiple breakpoints are hit at the same time, multiple stop reasons are reported, one per breakpoint. Currently, `get_threads_stopped_at_breakpoint_id` only checks the first such reason.
2024-06-26[lldb] fix(lldb/**.py): fix comparison to None (#94017)Eisuke Kawashima1-3/+3
from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations): > Comparisons to singletons like None should always be done with is or is not, never the equality operators. Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2024-05-15[lldb][test][FreeBSD] Fix some concurrent event tests (#84155)David Spickett1-1/+1
A lot of `TestConcurrent*.py` expect one of the threads to crash, but we weren't checking for it properly. Possibly because signal reporting got better on FreeBSD at some point, and it now shows the same info as Linux does. ``` lldb-api :: functionalities/inferior-changed/TestInferiorChanged.py lldb-api :: functionalities/inferior-crashing/TestInferiorCrashing.py lldb-api :: functionalities/inferior-crashing/TestInferiorCrashingStep.py lldb-api :: functionalities/inferior-crashing/recursive-inferior/TestRecursiveInferior.py lldb-api :: functionalities/inferior-crashing/recursive-inferior/TestRecursiveInferiorStep.py lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithBreak.py lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithSignal.py lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpoint.py lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpointBreakpointSignal.py ``` Fixes #48777 `TestConcurrentTwoBreakpointsOneSignal.py` no longer fails, at least on an AWS instance, so I've removed the xfail there.
2024-05-14[lldb] Add lldbutil.install_to_target() helper (#91944)Dmitry Vasilyev1-0/+16
It can be used in tests #91918, #91931 and such.
2024-02-16[lldb] Replace assertEquals with assertEqual (NFC) (#82073)Jonas Devlieghere1-6/+6
assertEquals is a deprecated alias for assertEqual and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite.
2023-08-14[lldb] Remove use of __future__ in pythonAlex Langford1-3/+0
These were useful primarily for the Python 2 to 3 transition. Python 2 is no longer supported so these are no longer necessary. Differential Revision: https://reviews.llvm.org/D157759
2023-05-25[NFC][Py Reformat] Reformat python files in lldbJonas Devlieghere1-361/+473
This is an ongoing series of commits that are reformatting our Python code. Reformatting is done with `black` (23.1.0). If you end up having problems merging this commit because you have made changes to a python file, the best way to handle that is to run `git checkout --ours <yourfile>` and then reformat it with black. RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Differential revision: https://reviews.llvm.org/D151460
2023-04-25[lldb/test] Update lldbutil.fetch_next_event to match broadcaster classMed Ismail Bennani1-4/+11
This patch updates the `lldbutil.fetch_next_event` helper function to either match a specific broadcaster or match a whole broadcaster class. This is very handy when testing process events for interactive scripted process debugging. This also fixes a bug in the failing case, where `SBEvent.GetDescription` expects a `SBStream` argument. We never took that code path in the original implementation so we didn't hit that bug. Differential Revision: https://reviews.llvm.org/D149175 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-04-04Simplify test.Adrian Prantl1-3/+1
This test doesn't actually depend on being able to launch the process. This may or may not explain why this test behaves oddly on some of our bots.
2022-08-24[LLDB] Add data formatter for std::coroutine_handleAdrian Vogelsgesang1-0/+15
This patch adds a formatter for `std::coroutine_handle`, both for libc++ and libstdc++. For the type-erased `coroutine_handle<>`, it shows the `resume` and `destroy` function pointers. For a non-type-erased `coroutine_handle<promise_type>` it also shows the `promise` value. With this change, executing the `v t` command on the example from https://clang.llvm.org/docs/DebuggingCoroutines.html now outputs ``` (task) t = { handle = coro frame = 0x55555555b2a0 { resume = 0x0000555555555a10 (a.out`coro_task(int, int) at llvm-example.cpp:36) destroy = 0x0000555555556090 (a.out`coro_task(int, int) at llvm-example.cpp:36) } } ``` instead of just ``` (task) t = { handle = { __handle_ = 0x55555555b2a0 } } ``` Note, how the symbols for the `resume` and `destroy` function pointer reveal which coroutine is stored inside the `std::coroutine_handle`. A follow-up commit will use this fact to infer the coroutine's promise type and the representation of its internal coroutine state based on the `resume` and `destroy` pointers. The same formatter is used for both libc++ and libstdc++. It would also work for MSVC's standard library, however it is not registered for MSVC, given that lldb does not provide pretty printers for other MSVC types, either. The formatter is in a newly added `Coroutines.{h,cpp}` file because there does not seem to be an already existing place where we could share formatters across libc++ and libstdc++. Also, I expect this code to grow as we improve debugging experience for coroutines further. **Testing** * Added API test Differential Revision: https://reviews.llvm.org/D132415
2022-08-11[lldb] Remove uses of six module (NFC)Dave Lee1-12/+9
With lldb (& llvm) requiring Python 3.6+, use of the `six` module can be removed. Differential Revision: https://reviews.llvm.org/D131304
2022-08-07[lldb] Dynamically generate enum names in lldbutilDave Lee1-130/+41
Change the `<enum>_to_str` functions in lldbutil to be dynamic. Instead of a manually maintained if/elif switch, the functions now perform lookup in a dynamically generated dict. The names are determined by stripping the enum's prefix, and then lowercasing the remaining suffix, ex: eStateRunning -> "running" Differential Revision: https://reviews.llvm.org/D131138
2022-08-03[lldb] Add assertStopReason helper functionJonas Devlieghere1-0/+4
Add a function to make it easier to debug a test failure caused by an unexpected stop reason. This is similar to the assertState helper that was added in ce825e46743b. Before: self.assertEqual(stop_reason, lldb.eStopReasonInstrumentation) AssertionError: 5 != 10 After: self.assertStopReason(stop_reason, lldb.eStopReasonInstrumentation) AssertionError: signal (5) != instrumentation (10) Differential revision: https://reviews.llvm.org/D131083
2022-07-07[lldb] Improve the error message in run_to_breakpoint_do_runJonas Devlieghere1-2/+17
Improve the error message when we fail to hit the initial breakpoint in run_to_breakpoint_do_run. In addition to the process state, we now also report the exit code and reason (if the process exited) as well as the inferior's output. Differential revision: https://reviews.llvm.org/D111978
2022-06-29[lldb] Use assertState in even more tests (NFC)Jonas Devlieghere1-1/+1
Followup to D127355 and D127378, converting more instances of assertEqual to assertState.
2022-05-26Store a by name list of signals with their actions in the TargetJim Ingham1-0/+36
so that they can be used to prime new Process runs. "process handle" was also changed to populate the dummy target if there's no selected target, so that the settings will get copied into new targets. Differential Revision: https://reviews.llvm.org/D126259
2022-03-23[lldb/test] Add events listener helper function to lldbtestMed Ismail Bennani1-0/+23
This patch introduces 2 new lldb utility functions: - lldbutil.start_listening_from: This can be called in the test setup to create a listener and set it up for a specific event mask and add it to the user-provided broadcaster's list. - lldbutil.fetch_next_event: This will use fetch a single event from the provided istener and return it if it matches the provided broadcaster. The motivation behind this is to easily test new kinds of events (i.e. Swift type-system progress events). However, this patch also updates `TestProgressReporting.py` and `TestDiagnosticReporting.py` to make use of these new helper functions. Differential Revision: https://reviews.llvm.org/D122193 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-11-24 [LLDB/test] lldbutil check_breakpoint() - check target instanceSYNOPSYS\georgiev1-2/+7
Check test.target instance type before we attempt to get the breakpoint. This fix is suggested by 'clayborg'. Ref: https://reviews.llvm.org/D111899#inline-1090156
2021-11-17[lldb/test] Added lldbutil function to test a breakpointSYNOPSYS\georgiev1-0/+51
Testing the breakpoint itself rather than the lldb string. Differential Revision: https://reviews.llvm.org/D111899
2021-10-18Add tests for the other variants of BreakpointCreateBySourceRegex.Jim Ingham1-4/+6
I added some tests for the case where the breakpoints take immediately to the extant test case, and made a new test case for when the source regex breakpoint will be set in a dlopen-ed library. I also noticed when doing this that "lldbutil.run_to_source_breakpoint can't handle the case where the breakpoint will be in a dlopen-ed library, since it requires the breakpoint to have at least 1 location before run. I fixed that by adding a parameter to say whether a before run location is expected. Differential Revision: https://reviews.llvm.org/D111920
2021-04-24[lldb] [gdb-remote server] Introduce new stop reasons for fork and vforkMichał Górny1-0/+6
Introduce three new stop reasons for fork, vfork and vforkdone events. This includes server support for serializing fork/vfork events into gdb-remote protocol. The stop infos for the two base events take a pair of PID and TID for the newly forked process. Differential Revision: https://reviews.llvm.org/D100196
2021-04-21[lldb] Use the compiler from the SDK in simulator testsJonas Devlieghere1-0/+5
Use the clang compiler from the SDK to build the simulator test programs to ensure we pick up the correct libc++.
2021-04-01[lldb/test] Respect --apple-sdk path when querying SDK infoVedant Kumar1-0/+6
Respect --apple-sdk <path> if it's specified. If the SDK is simply mounted from some disk image, and not actually installed, this is the only way to use it. Differential Revision: https://reviews.llvm.org/D99746
2020-08-19[lldb] Move Xcode SDK helper functions into lldbutilJonas Devlieghere1-1/+36
This allows the logic to be reused by both the builders and the tests.
2020-08-14[lldb] Make packetlog_get_dylib_info returns the last full responseRaphael Isemann1-2/+3
In sanitized builds the last packet this function finds for the TestMacCatalyst and TestPlatformSimulator tests is for the asan runtime. ``` < 69> send packet: $jGetLoadedDynamicLibrariesInfos:{"solib_addresses":[4296048640]}]#3a < 715> read packet: ${"images":[{"load_address":4296048640,"mod_date":0,"pathname": "/Users/buildslave/jenkins/workspace/lldb-cmake-sanitized/host-compiler/lib/clang/12.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib", "uuid":"8E38A2CD-753F-3E0F-8EB0-F4BD5788A5CA", "min_version_os_name":"macosx","min_version_os_sdk":"10.9", "mach_header":{"magic":4277009103,"cputype":16777223,"cpusubtype":3,"filetype":6, "flags":43090053}],"segments":[{"name":"__TEXT","vmaddr":0,"vmsize":565248,"fileoff":0, "filesize":565248,"maxprot":5}],{"name":"__DATA","vmaddr":565248,"vmsize":13152256,"fileoff":565248, "filesize":20480,"maxprot":3}],{"name":"__LINKEDIT","vmaddr":13717504,"vmsize":438272,"fileoff":585728, "filesize":435008,"maxprot":1}]]}]]}]#00 ``` This just fetches the last package which has fetch_all_solibs and we know it will contain the image of our test executable to get the tests running again.
2020-08-07lldbutil: add a retry mechanism for the ios simulatorAdrian Prantl1-2/+15
We've been seeing this failure on green dragon when the system is under high load. Unfortunately this is outside of LLDB's control. Differential Revision: https://reviews.llvm.org/D85542
2020-08-04Fix debugserver's qProcessInfo reporting of maccatalyst binariesAdrian Prantl1-0/+37
This patch is similar in spirit to https://reviews.llvm.org/D84480, but does the maccatalyst/macosx disambiguation. I also took the opportunity to factor out the gdb-remote packet log scanning used by several testcases into lldbutil functions. rdar://problem/66059257 Differential Revision: https://reviews.llvm.org/D84576
2020-07-20Add an option (-y) to "break set" and "source list" that uses the sameJim Ingham1-0/+36
file:line:column form that we use to print out locations. Since we print them this way it makes sense we also accept that form. Differential Revision: https://reviews.llvm.org/D83975
2020-07-07[lldb/test] Fix lldbutil.run_to_***_breakpoint for shared librariesPavel Labath1-1/+3
Even non-remote targets may need to set the launch environment ((DY)LD_LIBRARY_PATH, specifically) to run successfully. Also, add an assertion to better detect the case when launching a target fails and the breakpoint is never hit.
2020-03-18[lldb/Target] Support more than 2 symbols in StackFrameRecognizerMed Ismail Bennani1-1/+1
This patch changes the way the StackFrame Recognizers match a certain frame. Until now, recognizers could be registered with a function name but also an alternate symbol. This change is motivated by a test failure for the Assert frame recognizer on Linux. Depending the version of the libc, the abort function (triggered by an assertion), could have more than two signatures (i.e. `raise`, `__GI_raise` and `gsignal`). Instead of only checking the default symbol name and the alternate one, lldb will iterate over a list of symbols to match against. rdar://60386577 Differential Revision: https://reviews.llvm.org/D76188 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-03-06Increase default timeout in lldbutil.expect_state_changes()Adrian Prantl1-1/+1
2020-01-10lldbutil: Forward ASan launch info to test inferiorsVedant Kumar1-1/+8
This allows an unsanitized test process which loads a sanitized DSO (the motivating example is a Swift runtime dylib) to launch on Darwin. rdar://57290132 Differential Revision: https://reviews.llvm.org/D71379
2019-12-10Assert launch success in run_to_breakpoint_do_runVedant Kumar1-0/+2
2019-11-15dotest: Add a way for the run_to_* helpers to register dylibsFred Riss1-7/+18
Summary: To run the testsuite remotely the executable needs to be uploaded to the target system. The Target takes care of this by default. When the test uses additional shared libraries, those won't be handled by default and need to be registered with the target using test.registerSharedLibrariesWithTarget(target, dylib). Calling this API requires a target, so it doesn't mesh well with the run_to_* helpers that we've been advertising as the right way to write tests. This patch adds an extra_images argument to all the helpers and does the registration automatically when running a remote testsuite. TestWeakSymbols.py was converted to use this new scheme. Reviewers: jingham Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D70134
2019-10-28Modernize TestThreadStepOut.pyJim Ingham1-8/+21
This test was timing out on the swift CI bots. I didn't see any obvious reason for that, and the test hasn't had problems on greendragon. OTOH, it was a bit oddly written, and needed modernizing, so I did that. Differential Revision: https://reviews.llvm.org/D69453
2019-08-02[lldb][NFC] Remove unused imports in python testsRaphael Isemann1-2/+0
llvm-svn: 367663
2019-04-29[Windows] Dump more information about access violation exceptionAleksandr Urakov1-1/+1
Summary: Dump more information about "access violation" and "in page error" exceptions to description. Description now contains data about read/write violation type and actual address as described at https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_exception_record Reviewers: asmith, stella.stamenova Reviewed By: stella.stamenova Subscribers: teemperor, amccarth, abidh, lldb-commits, aleksandr.urakov Tags: #lldb Differential Revision: https://reviews.llvm.org/D60519 llvm-svn: 359420
2018-12-03[PDB] Support PDB-backed expressions evaluation (+ fix stuck test)Aleksandr Urakov1-0/+2
Summary: This patch contains several small fixes, which makes it possible to evaluate expressions on Windows using information from PDB. The changes are: - several sanitize checks; - make IRExecutionUnit::MemoryManager::getSymbolAddress to not return a magic value on a failure, because callers wait 0 in this case; - entry point required to be a file address, not RVA, in the ObjectFilePECOFF; - do not crash on a debuggee second chance exception - it may be an expression evaluation crash. Also fix detection of "crushed" threads in tests; - create parameter declarations for functions in AST to make it possible to call debugee functions from expressions; - relax name searching rules for variables, functions, namespaces and types. Now it works just like in the DWARF plugin; - fix endless recursion in SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc. Reviewers: zturner, asmith, stella.stamenova Reviewed By: stella.stamenova, asmith Tags: #lldb Differential Revision: https://reviews.llvm.org/D53759 llvm-svn: 348136
2018-09-13Add a "scripted" breakpoint type to lldb.Jim Ingham1-2/+16
This change allows you to write a new breakpoint type where the logic for setting breakpoints is determined by a Python callback written using the SB API's. Differential Revision: https://reviews.llvm.org/D51830 llvm-svn: 342185
2018-08-30Support setting a breakpoint by FileSpec+Line+Column in the SBAPI.Adrian Prantl1-2/+24
This patch extends the SBAPI to allow for setting a breakpoint not only at a specific line, but also at a specific (minimum) column. When a column is specified, it will try to find an exact match or the closest match on the same line that comes after the specified location. Differential Revision: https://reviews.llvm.org/D51461 llvm-svn: 341078
2018-07-27Fix whitespace in the python test suite.Raphael Isemann1-5/+5
Summary: The test suite has often unnecessary trailing whitespace, and sometimes unnecessary trailing lines or a missing final new line. This patch just strips trailing whitespace/lines and adds missing newlines at the end. Subscribers: ki.stfu, JDevlieghere, christof, lldb-commits Differential Revision: https://reviews.llvm.org/D49943 llvm-svn: 338171
2018-04-13Allow relative file paths when settings source breakpointsGreg Clayton1-1/+1
Many IDEs set breakpoints using absolute paths and this causes problems when the full path of the source file path doesn't match what is in the debug info. This can be due to different build systems and do or do not resolve symlinks. This patch allows relative breakpoint to be set correctly without needing to do any target.source-map tricks. If IDEs want to, they can send down relative paths like: ./main.c ./src/main.c src/main.c foo/bar/src/main.c I used the breakpoint resolver to match on the file basename and then we weed out anything whose relative paths don't match. This will be a huge improvement for IDEs as they can specify as much of a relative path as desired to uniquely identify a source file in the current project. Differential Revision: https://reviews.llvm.org/D45592 llvm-svn: 330028
2018-03-15Next batch of test-tree-cleaning changesPavel Labath1-6/+16
Summary: The changes here fall into several categories. - some tests were redirecting inferior stdout/err to a file. For these I make sure we use an absolute path for the file. I also create a lldbutil.read_file_on_target helper function to encapsulate the differences between reading a file locally and remotely. - some tests were redirecting the pexpect I/O into a file. For these I use a python StringIO object to avoid creating a file altogether. - the TestSettings inferior was creating a file. Here, I make sure the inferior is launched with pwd=build-dir so that the files end up created there. - lldb-mi --log (used by some tests) creates a log file in PWD without the ability say differently. To make this work I make sure to run lldb-mi with PWD=build_dir. This in turn necessitated a couple of changes in other lldb-mi tests, which were using relative paths to access the source tree. Reviewers: aprantl Subscribers: ki.stfu, mehdi_amini, lldb-commits Differential Revision: https://reviews.llvm.org/D44159 llvm-svn: 327625
2018-02-21Fix TestBreakpointInGlobalConstructor for WindowsAdrian McCarthy1-2/+3
Summary: This test was failing on Windows because it expected the breakpoint in the dynamic library to be resolved before the process is launched. Since the DLL isn't loaded until the process is launched this didn't work. The fix creates a special value (-2) for num_expected_locations that ignores the actual number of breakpoint locations found. Reviewers: jasonmolenda Subscribers: sanjoy, lldb-commits Differential Revision: https://reviews.llvm.org/D43419 llvm-svn: 325704
2018-02-21Fix a couple of more tests to not create files in the source treePavel Labath1-2/+2
Summary: These were not being flaky, but they're still making the tree dirty. These tests were using lldbutil.append_to_process_working_directory to derive the file path so I fix them by modifying the function to return the build directory for local tests. Technically, now the path returned by this function does not point to the process working directory for local tests, but I think it makes sense to keep the function name, as I think we should move towards launching the process in the build directory (and I intend to change this for the handful of inferiors that actually care about their PWD, for example because they need to create files there). Reviewers: davide, aprantl Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D43506 llvm-svn: 325690