Commit Graph

26328 Commits

Author SHA1 Message Date
Zequan Wu 4b2af365b6 [LLDB][NativePDB] Minor fix on inline line table. 2022-03-31 14:57:26 -07:00
Jim Ingham 1f7b58f2a5 Add a setting to not require --overwrite to overwrite commands.
Protecting against accidental overwriting of commands is good, but
having to pass a flag to overwrite the command when developing your
commands is pretty annoying.  This adds a setting to defeat the protection
so you can do this once at the start of your session and not have to
worry about it again.

Differential Revision: https://reviews.llvm.org/D122680
2022-03-31 14:15:14 -07:00
Shafik Yaghmour 24f9a2f53d [LLDB] Applying clang-tidy modernize-use-equals-default over LLDB
Applied modernize-use-equals-default clang-tidy check over LLDB.

This check is already present in the lldb/.clang-tidy config.

Differential Revision: https://reviews.llvm.org/D121844
2022-03-31 13:21:49 -07:00
Shafik Yaghmour 14cad95d38 [LLDB] Fix NSIndexPathSyntheticFrontEnd::Impl::Clear() to only clear the active union member
NSIndexPathSyntheticFrontEnd::Impl::Clear() currently calls Clear() on both
unions members regardless of which one is active. I modified it to only call
Clear() on the active member.

Differential Revision: https://reviews.llvm.org/D122753
2022-03-30 18:00:37 -07:00
Jonas Devlieghere a114ec0c6d
[lldb] Change the way we pick a platform for fat binaries
Currently, when creating a target for a fat binary, we error out if more
than one platforms can support the different architectures in the
binary. There are situations where it makes sense for multiple platforms
to support the same architectures: for example the host and
remote-macosx platform on Darwin.

The only way to currently disambiguate between them is to specify the
architecture. This patch changes that to take into account the selected
and host platform. The new algorithm works a follows:

1. Pick the selected platform if it matches any of the architectures.
2. Pick the host platform if it matches any of the architectures.
3. If there's one platform that works for all architectures, pick that.

If none of the above apply then we either have no platform supporting
the architectures in the fat binary or multiple platforms with no good
way to disambiguate between them.

I've added a bunch of unit tests to codify this new behavior.

rdar://90360204

Differential revision: https://reviews.llvm.org/D122684
2022-03-30 15:30:05 -07:00
Martin Storsjö a37cb5ece5 [lldb-vscode] Avoid a -Wunused-but-set-variable warning. NFC.
Differential Revision: https://reviews.llvm.org/D122710
2022-03-31 00:10:05 +03:00
Pavel Labath 21c5bb0a63 Recommit [lldb/test] Make category-skipping logic "platform"-independent
This recommits dddf4ce03, which was reverted because of a couple of test
failures on macos. The reason behind the failures was that the patch
inadvertenly changed the value returned by the host platform from
"macosx" to "darwin". The new version fixes that.

Original commit message was:

The decision which categories are relevant for a particular test run
happen very early in the test setup process. They use the SBPlatform
object to determine which categories should be skipped. The platform
object created for this purpose transcends individual test runs.

This setup is not compatible with the direction discussed in
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>
-- when platform objects are tied to a specific (SB)Debugger, they need
to be created alongside it, which currently happens in the test setUp
method.

This patch is the first step in that direction -- it rewrites the
category skipping logic to avoid depending on a global SBPlatform
object. Fortunately, the skipping logic is fairly simple (and I believe
it outght to stay that way) and mainly consists of comparing the
platform name against some hardcoded lists. This patch bases this
comparison on the platform name instead of the os part of the triple (as
reported by the platform).

Differential Revision: https://reviews.llvm.org/D121605
2022-03-30 17:16:37 +02:00
Pavel Labath 1410a4860e [lldb] Remove vasprintf windows-compat implementation
We already have a VASprintf function for this purpose, so I'm switching
the remaining few users to that.
2022-03-30 09:32:35 +02:00
Pavel Labath c484857b2e [lldb] Use =default in the ValueList class 2022-03-30 09:12:59 +02:00
Jonas Devlieghere 8991ad43ff
[lldb] Make ModuleSpecList iterable (NFC) 2022-03-29 15:26:54 -07:00
Chris Bieneman dfde354958 NFC. Fixing warnings from adding DXContainer
Adds DXContainer to switch statements in Clang and LLDB to silence
warnings.
2022-03-29 14:46:24 -05:00
Pavel Labath 13a3b0bb4b [lldb] Remove usages of case-insensitive c-string functions
They are not portable (which meant we had a hand-rolled implementation
for windows), and llvm::StringRef provides equivalent functionality.
2022-03-29 17:59:17 +02:00
Benjamin Kramer 42d3d717b8 Silence compiler warning after the addition of HLSL to Clang
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:472:16: warning: enumeration value 'HLSL' not handled in switch [-Wswitch]
    switch (IK.getLanguage()) {
               ^
2022-03-29 01:23:20 +02:00
Pavel Labath 3631b9014d [lldb] Remove some unused functions from PosixApi.h
There are better llvm replacements for all of these.
2022-03-28 15:14:19 +02:00
Muhammad Omair Javaid 5c6ee1305e [LLDB] Skip TestProcessIOHandlerInterrupt Arm/AArch64 Linux
This patch skips TestProcessIOHandlerInterrupt on Arm/AArch64.
PExpect tests are not stable when run in containerized machine.
2022-03-28 12:32:49 +05:00
Martin Storsjö b548f58472 [lldb] Fix interpreting absolute Windows paths with forward slashes
In practice, Windows paths can use either backslashes or forward slashes.

This fixes an issue reported downstream at
https://github.com/mstorsjo/llvm-mingw/issues/266.

Differential Revision: https://reviews.llvm.org/D122389
2022-03-26 22:34:02 +02:00
Martin Storsjö bc13101cf9 [lldb] Fix building for mingw after changes to sigtstp_handler
Some signal handlers were set up within an !_MSC_VER condition,
i.e. omitted in MSVC builds but included in mingw builds. Previously
sigtstp_handler was defined in all builds, but since
4bcadd6686 / D120320 it's only
defined non platforms other than Windows.

Change the condition to !_WIN32 for consistency between the MSVC
and mingw builds, fixing the build for mingw.

Differential Revision: https://reviews.llvm.org/D122486
2022-03-26 22:32:53 +02:00
Alisamar Husain bcf1978a87 [intelpt] Refactoring instruction decoding for flexibility
Now the decoded thread has Append methods that provide more flexibility
in terms of the underlying data structure that represents the
instructions. In this case, we are able to represent the sporadic errors
as map and thus reduce the size of each instruction.

Differential Revision: https://reviews.llvm.org/D122293
2022-03-26 11:34:47 -07:00
Fred Riss 3427eddd9a
Adopt new dyld SPIs to introspect the shared cache.
With the shared cache getting split into multiple files, the current
way we created ObjectFileMachO objects for shared cache dylib images
will break.

This patch conditionally adopts new SPIs which will do the right
thing in the new world of multi-file caches.
2022-03-25 18:02:15 -07:00
Med Ismail Bennani 150db43e41 [lldb/Plugin] Sort the ScriptedProcess' thread list before creating threads
With Scripted Processes, in order to create scripted threads, the blueprint
provides a dictionary that have each thread index as the key with the respective
thread instance as the pair value.

In Python, this is fine because a dictionary key can be of any type including
integer types:

```
>>> {1: "one", 2: "two", 10: "ten"}
{1: 'one', 2: 'two', 10: 'ten'}
```

However, when the python dictionary gets bridged to C++ we convert it to a
`StructuredData::Dictionary` that uses a `std::map<ConstString, ObjectSP>`
for storage.

Because `std::map` is an ordered container and ours uses the `ConstString`
type for keys, the thread indices gets converted to strings which makes the
dictionary sorted alphabetically, instead of numerically.

If the ScriptedProcess has 10 threads or more, it causes thread “10”
(and higher) to be after thread “1”, but before thread “2”.

In order to solve this, this sorts the thread info dictionary keys
numerically, before iterating over them to create ScriptedThreads.

rdar://90327854

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-25 14:59:50 -07:00
Med Ismail Bennani 29f363611d [lldb/Utility] Make StructuredData::Dictionary::GetKeys return an Array
This patch changes `StructuredData::Dictionary::GetKeys` return type
from an `StructuredData::ObjectSP` to a `StructuredData::ArraySP`.

The function already stored the keys in an array but implicitely upcasted
it to an `ObjectSP`, which required the user to convert it again to a
Array object to access each element.

Since we know the keys should be held by an iterable container, it makes
more sense to return the allocated ArraySP as-is.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-25 14:59:50 -07:00
Med Ismail Bennani 12301d616f [lldb/crashlog] Parse thread fields and pass it to crashlog scripted process
Previously, the ScriptedThread used the thread index as the thread id.

This patch parses the crashlog json to extract the actual thread "id" value,
and passes this information to the Crashlog ScriptedProcess blueprint,
to create a higher fidelity ScriptedThreaad.

It also updates the blueprint to show the thread name and thread queue.

Finally, this patch updates the interactive crashlog test to reflect
these changes.

rdar://90327854

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-25 14:59:50 -07:00
Jonas Devlieghere 8f7db763ef
[lldb] Conditionalize target_link_libraries on the target
Fixes "Cannot specify link libraries for target "lldb-target-fuzzer"
which is not built by this project." Normally that's taken care of by
add_llvm_fuzzer but we need target_link_libraries for liblldb and our
utility library.
2022-03-25 09:50:34 -07:00
Jonas Devlieghere 61efe14e21
[lldb] Add a fuzzer for target creation
This patch adds a generic fuzzer that interprets inputs as object files
and uses them to create a target in lldb. It is very similar to the
llvm-dwarfdump fuzzer which found a bunch of issues in libObject.

Differential revision: https://reviews.llvm.org/D122461
2022-03-25 09:34:00 -07:00
Jason Molenda 99515783a6 Don't search for sim SDK path until we know we need it
When iterating over all Platforms looking for the best one, on a Mac the
Simulator platforms (iOS, tvOS, watchOS) will first find their SDK
directory by calling xcrun, then decide if they should activate or not.
When that SDK is absent, the call to xcrun to find it can be very slow.
This patch delays that directory search until we know we're activating
this platform, so non-simulator environments don't pay a perf cost ever
time they go through the list of platforms.

Differential Revision: https://reviews.llvm.org/D122373
rdar://87960090
2022-03-24 15:44:57 -07:00
Shafik Yaghmour aca9648078 [LLDB] Cleanup for Fixing DWARFExpression handling of ValueType::FileAddress case for DW_OP_deref_size
Late review on https://reviews.llvm.org/D121408 spotted some nice quick clean-ups on this code.
2022-03-24 10:00:26 -07:00
Jakob Johnson 9b79187c96 [trace][intelpt] Server side changes for TSC to wall time conversion
Update the response schema of the TraceGetState packet and add
Intel PT specific response structure that contains the TSC conversion,
if it exists. The IntelPTCollector loads the TSC conversion and caches
it to prevent unnecessary calls to perf_event_open. Move the TSC conversion
calculation from Perf.h to TraceIntelPTGDBRemotePackets.h to remove
dependency on Linux specific headers.

Differential Revision: https://reviews.llvm.org/D122246
2022-03-24 05:36:21 -07:00
Nikita Popov 840bb72543 [lldb] Avoid pointer element type accesses 2022-03-24 13:09:23 +01:00
Nikita Popov b3fbbabdc1 [lldb] Use byval type
Query byval type instead of pointer element type.
2022-03-24 12:55:42 +01:00
Nikita Popov 00fb050408 [lldb] Remove unused Module argument (NFC) 2022-03-24 12:53:02 +01:00
Jonas Devlieghere 4ad19b80ea
[lldb] Test parsing the symtab with indirect symbols from the shared cache
This patch adds a test for b0dc2fae60. That commit fixed a bug where
we could increment the indirect symbol offset every time we parsed the
symbol table.
2022-03-23 21:13:55 -07:00
Jason Molenda 9a8a0a3861 Load dyld manually with 'main bin spec' userland corefiles
In ProcessMachCore::DoLoadCore when we have a standalone
binary and a 'main bin spec' LC_NOTE detailing the UUID and
load address, ProcessMachCore will do a (potentially slow)
lookup to try to find the binary and/or dSYM.  For kernel and
userland corefile using 'main bin spec', we would follow the
normal schemes of locating them.  DynamicLoaderDarwinKernel would
use the same (possibly expensive) calls to find the correct
binary.  dyld by default would use the in-core-file binary image,
and so if the corefile didn't include the entire address space,
the LINKEDIT for dyld could be missing.  This means we can't find
the dyld4::dyld_all_image_infos struct, which tells us where the
other binaries are loaded in memory.

Treat userland 'bin main spec' like we do standalone firmewares;
try the expensive checks to find the best dyld we can, before
falling back to using a memory module out of the corefile.

Also add a little TODO for myself in this load_standalone_binary
function that we should handle the case of a binary in the shared
cache correctly, creating a memory module in the corefile and
using the segment load addresses from that to set our segment
load addresses for the final binary.

rdar://89717101
2022-03-23 17:12:17 -07:00
Jonas Devlieghere b0dc2fae60
[lldb] Don't persist the LINKEDIT slide in the indirect symbol offset
The current code increment the indirect symbol offset with the LINKEDIT
slide every time ObjectFileMachO::ParseSymtab is called.

This resulted in a crash when calling add-dsym which causes us to
potentially re-parse the original binary's symbol table. There's a
separate question about whether we should re-parse the symbol table at
all which was fixed by D114288. Regardless, copying the load command is
cheap enough that this is still the right thing to do.

rdar://72337717

Differential revision: https://reviews.llvm.org/D122349
2022-03-23 16:39:53 -07:00
Jonas Devlieghere b0f1f3b95c
[lldb] Remove lldbassert from CommandInterpreter::PrintCommandOutput
The assertion checks that the command output doesn't contain any null
bytes. I'm not sure if the intention was to make sure the string wasn't
shorter than the reported length or if this was a way to catch us
accidentally writing an (unformatted) null byte.

The consensus is that we don't want to have embedded nulls in the
command output, but that this isn't the right place to enforce that.

Differential revision: https://reviews.llvm.org/D122025
2022-03-23 16:19:50 -07:00
Jonas Devlieghere a765f2a044
[lldb] Support class_ro_t pointer authentication
Upstream support for signed class_ro_t pointers.
2022-03-23 16:19:49 -07:00
Adrian Prantl 12606d16bc Revert "Expose GetAddressingBits() in the Process API."
This reverts commit 7504dd5e00.

In newer review feedback it was pointed out that there is a better API for this in Process::GetCodeAddressMask().
2022-03-23 15:28:34 -07:00
Adrian Prantl 7504dd5e00 Expose GetAddressingBits() in the Process API.
This is needed by the Swift Plugin.

See also  https://github.com/apple/llvm-project/pull/4110.

Differential Revision: https://reviews.llvm.org/D122347
2022-03-23 14:22:26 -07:00
Med Ismail Bennani 9216baf87d [lldb/test] Add events listener helper function to lldbtest
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>
2022-03-23 12:30:09 -07:00
Jonas Devlieghere 9a88c2b639
[lldb] Fixup tagged pointers ISAs
This patch upstreams support for tagger pointer ISAs.
2022-03-23 09:59:34 -07:00
Danny Mösch a749e3295d Replace links to archived mailing lists by links to Discourse forums 2022-03-23 10:10:20 -04:00
Alisamar Husain 84caf73c52 [lldb/docs] Fixed minor ugly links 2022-03-23 13:00:18 +05:30
Jonas Devlieghere f54931865d
[lldb] Set the TERM environment variable for the API tests
Avoid "TERM environment variable not set" by either propagating the TERM
environment variable or defaulting to vt100. All of our CI is already
doing this explicitly through the --env dotest arg, but it's easy to
forget when setting up a new job. I don't see any downside in making it
the default.
2022-03-22 11:01:38 -07:00
Walter Erquinigo 360dcb759d [simple] fix some the documentation
Some links were not rendered correctly in the intel pt documentation and
some spacing was fixed in some command objects.
2022-03-22 09:10:42 -07:00
Pavel Labath 56fb745695 [lldb/test] Increase pexpect termination timeouts
By default these timeouts are extremely small (0.1s). This means that
100ms after sending an EOF, pexpect will start sending the process
increasingly aggressive signals, but the small timeouts mean that (on a
loaded machine) the kernel may not have enough time to process the
signal even if the overall effect of the signal is to kill the
application.

It turns out we were already relying on this signals (instead of regular
EOF quits) in our tests. In my experiments it was sufficient to block
SIGINT and SIGHUP to cause some test to become flaky. This was most
likely the reason of a couple of flakes on the lldb-x86_64-debian bot,
and is probably the reason why the pexpect tests are flaky on several
other (e.g. asan) bots.

This patch increses the timeout to 6 seconds (60-fold increase), which
is hopefully sufficient to avoid flakes even in the most extreme
situations.
2022-03-22 15:14:21 +01:00
Walter Erquinigo a80c6c7d36 [trace] clear any existing tracing sessions before relaunching the binary
There's a bug caused when a process is relaunched: the target, which
doesn't change, keeps the Trace object from the previous process, which
is already defunct, and causes segmentation faults when it's attempted
to be used.
A fix is to clean up the Trace object when the target is disposing of
the previous process during relaunches.

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

Differential Revision: https://reviews.llvm.org/D122176
2022-03-21 16:03:37 -07:00
Walter Erquinigo 31e44c01e3 [trace] Use vector instead of ArrayRef when reading data
I incorrectly returned an ArrayRef when the underlying object didn't own
the data. Instead, returning a vector<uint8_t> is what we should do.

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

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

Differential Revision: https://reviews.llvm.org/D122192
2022-03-21 16:03:37 -07:00
Walter Erquinigo 15c2d9cd79 [simple] fix formatting in the intel-pt doc
A list needs to be properly formatted.
2022-03-21 15:56:55 -07:00
Jonas Devlieghere 3323321f4e
[lldb] Fix log & progress report for in-memory binaries
Fix the log and progress report message for in-memory binaries. If
there's no object file, use the name from the Module. With this patch we
correctly show the library name when attaching to a remote process
without an expanded shared cache.

Differential revision: https://reviews.llvm.org/D122177
2022-03-21 15:35:21 -07:00
Jakob Johnson 45d9aab7a5 Fix e6c84f82b8
Failed buildbot: https://lab.llvm.org/buildbot/#/builders/17/builds/19490

Only run perf event tsc conversion test on x86_64.
2022-03-21 15:02:02 -07:00
Jakob Johnson d13752851a Fix e6c84f82b8
Failed buildbot: https://lab.llvm.org/buildbot/#/builders/68/builds/29250

Use toString() to consume the Error
2022-03-21 14:35:14 -07:00
Jakob Johnson e412529c93 Fix e6c84f82b8
Failed buildbot: https://lab.llvm.org/buildbot/#/builders/17/builds/19480

The fix seems to be simply be adding some type casts to make the compiler happy
2022-03-21 14:00:39 -07:00
Jakob Johnson e6c84f82b8 Add thin wrapper for perf_event_open API
- Add PerfEvent class to handle creating ring buffers and handle the resources associated with a perf_event
  - Refactor IntelPT collection code to use this new API
  - Add TSC to timestamp conversion logic with unittest

Differential Revision: https://reviews.llvm.org/D121734
2022-03-21 13:38:52 -07:00
Alisamar Husain ca47011e73 [tests][intelpt] Fix outdated trace load test
Differential Revision: https://reviews.llvm.org/D122114
2022-03-21 13:21:45 +05:30
Pavel Labath 8bf8934666 Revert "[lldb/test] Add events listener helper class to lldbtest"
It removes the "wait-until-event-thread-stops" logic, which makes
TestDiagnosticReporting.py flaky.

This reverts commits 09ff41a087 and
acdd41b459.
2022-03-21 08:32:16 +01:00
Alisamar Husain 37a466dd72 [trace][intelpt] Added total memory usage by decoded trace
This fails currently but the basics are there

Differential Revision: https://reviews.llvm.org/D122093
2022-03-21 12:36:08 +05:30
Alisamar Husain 8271220a99 [trace][intelpt] Instruction count in trace info
Added a line to `thread trace dump info` results which shows total number of instructions executed until now.

Differential Revision: https://reviews.llvm.org/D122076
2022-03-20 11:28:16 +05:30
Alisamar Husain 1bcc28b884 [docs] Fixed minor ordering issue
Differential Revision: https://reviews.llvm.org/D122073
2022-03-19 22:23:42 +05:30
Alisamar Husain 752e9cdbb0 [trace][intelpt][docs] Added intel-pt build instructions for lldb
Differential Revision: https://reviews.llvm.org/D121935
2022-03-19 15:26:59 +05:30
Med Ismail Bennani acdd41b459 [lldb/test] Fix typo in eventlistener.py (NFC)
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-18 21:59:11 -07:00
Med Ismail Bennani 09ff41a087 [lldb/test] Add events listener helper class to lldbtest
This patch introduces a generic helper class that will listen for
event in a background thread and match it against a source broadcaster.

If the event received matches the source broadcaster, the event is
queued up in a list that the user can access later on.

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 this new helper class.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-18 16:35:33 -07:00
Walter Erquinigo b7d525ad38 [trace][intelpt] fix some test failures
Minor fixes needed and now `./bin/lldb-dotest -p TestTrace` passes
correctly.

- There was an incorrect iteration.
- Some error messages changed.
- The way repeat commands are handled changed a bit, so I had to create
a new --continue arg in "thread trace dump instructions" to handle this
correctly.

Differential Revision: https://reviews.llvm.org/D122023
2022-03-18 10:35:34 -07:00
Jonas Devlieghere 453f8c87ff
[lldb] Remove lldb/lldb subdir created by wrong patch level
Bad application of patch -p<level>.
2022-03-18 09:06:15 -07:00
David Spickett 9f052f3dd2 [lldb] Require x86 target for NativePDB test
This test would fail if you only build for example,
just the AArch64 backend, due to the x86 triple.
2022-03-18 12:31:03 +00:00
Pavel Labath af4da4f995 [lldb] Increase timeout in TestProcessIOHandlerInterrupt
The small value was not meant to be checked in.
2022-03-18 12:14:10 +01:00
Pavel Labath a4d6de2031 [lldb] Fix TestProcessIOHandlerInterrupt.py for macos
On darwin, we don't completely suppress the signal used to interrupt the
inferior. The underlying read syscall returns EINTR, which causes premature
termination of the input loop.

Work around that by hand-rolling an EINTR-resistant version of getline.
2022-03-18 11:51:55 +01:00
Pavel Labath 14bd14f9f9 [lldb] Fix ^C handling in IOHandlerProcessSTDIO
D120762 accidentally moved the interrupt check into the block which was
reading stdio. This meant that a ^C only took effect after a regular
character has been pressed.

This patch fixes that and adds a (pexpect) test.

Differential Revision: https://reviews.llvm.org/D121912
2022-03-18 08:58:30 +01:00
Pavel Labath 53e9ee3027 Revert "[lldb] Fix ^C handling in IOHandlerProcessSTDIO"
This reverts commit f93d861349 -- looks
like a bad application of `patch -p<level>`
2022-03-18 08:58:30 +01:00
Pavel Labath c7fc7205bb [lldb] Add more documentation on test variants
This formalizes some of the discussion on D121631.

Differential Revision: https://reviews.llvm.org/D121900
2022-03-18 08:58:29 +01:00
Pavel Labath 0f362f9d25 [lldb] Remove process->LoadModules call from DynamicLoaderPOSIXDYLD
The call is useless, as any modules loaded there will be removed in
ResolveExecutableModule. Modules will be reloaded again through the
GetLoadedModuleList call in DYLDRendezvous.cpp.
2022-03-18 08:58:29 +01:00
Jonas Devlieghere 74b45f91b8
[lldb] Migrate ProcessGDBRemote to ReportWarning 2022-03-17 15:13:48 -07:00
Pavel Labath f93d861349
[lldb] Fix ^C handling in IOHandlerProcessSTDIO
D120762 accidentally moved the interrupt check into the block which was
reading stdio. This meant that a ^C only took effect after a regular
character has been pressed.

This patch fixes that and adds a (pexpect) test.

Differential revision: https://reviews.llvm.org/D121912
2022-03-17 11:52:19 -07:00
Shafik Yaghmour 33d74170a3 [LLDB] Modifying expression code in MakeLoadImageUtilityFunction to be more consistent
MakeLoadImageUtilityFunction() is not using extern "C" for external C functions
and it is not using eLanguageTypeC_plus_plus. So I am modifying it to be consistent.

Also see: rdar://87544782

Differential Revision: https://reviews.llvm.org/D121831
2022-03-17 08:52:56 -07:00
Jonas Devlieghere 7ed1abd4a6
[lldb] Skip invalid-condition.test on Windows
This test is making the Windows bot unhappy. Unfortunately the output
doesn't tell me much about what exactly is wrong.
2022-03-17 08:34:12 -07:00
Jonas Devlieghere cae735f72b
[lldb] Migrate runtime instrumentation plugins to ReportWarning 2022-03-16 23:20:58 -07:00
Jonas Devlieghere ea0f8ecc43
[lldb] Remove commented-out code in CommandObjectExpression (NFC) 2022-03-16 23:02:59 -07:00
Jonas Devlieghere d10c0c7b18
[lldb] Migrate condition evaluation failure to ReportError
Migrate to using ReportError to report a failure to evaluate a
watchpoint condition. I had already done so for the parallel code for
breakpoints.

In the process, I noticed that I accidentally regressed the error
reporting for breakpoint conditions by dropping the call to
GetDescription. This patch rectifies that and adds a test.

Because the call to GetDescription expects a Stream*, I also switches
from using a raw_string_ostream to a StreamString for both breakpoints
and watchpoints.
2022-03-16 22:54:02 -07:00
Jonas Devlieghere 8212b41b7b
[lldb] Fix flakiness in command-disassemble-process.yaml (2/2)
I split up the test so we could stop redirecting stderr to stdout but I
forgot to include that part in the previous commit.
2022-03-16 22:12:39 -07:00
Jonas Devlieghere 557a0e7b96
[lldb] Fix flakyness in command-disassemble-process.yaml 2022-03-16 21:27:54 -07:00
Jonas Devlieghere 8e893dfed5
[lldb] Fix flakyness in Minidump/no-process-id.yaml 2022-03-16 21:21:11 -07:00
Jonas Devlieghere c354f13e69
[lldb] Update TargetProperties::CheckJITObjectsDir to use ReportError 2022-03-16 21:11:53 -07:00
Med Ismail Bennani 0a65112cf7 [lldb/crashlog] Create artificial frames for non-crashed scripted threads
This patch pipes down the `-a|--load-all` crashlog command option to the
Scripted Process initializer to load all the images used by crashed
process instead of only loading the images related to the crashed
thread.

This allows us to recreate artificial frames also for the non-crashed
scripted threads.

rdar://90396265

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-16 15:50:10 -07:00
Jakob Johnson 22077627ae Minor refactor and renaming:
- Rename IntelPTManager class and files to IntelPTCollector
  - Change GetTimestampCounter API to general trace counter API,
    GetCounter

Differential Revision: https://reviews.llvm.org/D121711
2022-03-16 15:35:36 -07:00
Jonas Devlieghere ff9e596b10
[lldb] Expose diagnostic events through the SB API
Expose diagnostic events through the SB API. Unlike the progress events,
I opted to use a SBStructuredData so that we can add fields in the
future.

Differential revision: https://reviews.llvm.org/D121818
2022-03-16 15:03:31 -07:00
Yonghong Song 212f714ff7 [lldb] add missed handling for new BTFTagAttributed type
Commit 3251ba2d0f ("[Attr] Fix a btf_type_tag AST generation")
added a new type BTFTagAttributedType to the clang AST type
system. There are a few places in lldb needed to handle this type
similar to Attributed type to avoid compilation warning/error
when 'switch' is used to enumerate all types.
2022-03-16 11:00:35 -07:00
Jonas Devlieghere 3f0e050842
[lldb] Fix Minidump/no-process-id.yaml
Update warning after 2fc38b2b7b.
2022-03-16 09:32:06 -07:00
Jonas Devlieghere 2fc38b2b7b
[lldb] Report debugger diagnostics as events
Report warnings and errors through events instead of printing directly
the to the debugger's error stream. By using events, IDEs such as Xcode
can report these issues in the UI instead of having them show up in the
debugger console.

The new diagnostic events are handled by the default event loop. If a
diagnostic is reported while nobody is listening for the new event
types, it is printed directly to the debugger's error stream.

Differential revision: https://reviews.llvm.org/D121511
2022-03-16 08:33:01 -07:00
Pavel Labath ccba163d85 [lldb] Change back LLDBLog::Commands->Types in a couple more places
This was inadvertedly changed (bad search&replace) when I was removing
the LLDBLOG macros.
2022-03-16 15:46:17 +01:00
Will Hawkins d58ef6df0d [LLDB] Change enumaration to enumeration
Change enumaration to enumeration in code handling LLDB help output.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D121800
2022-03-16 15:31:25 +01:00
Will Hawkins fe93395b92 [LLDB] Fix typos in LLDB help output.
Correct a few spelling errors and typos in the LLDB help output.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D121802
2022-03-16 15:31:25 +01:00
Sam McCall 75acad41bc Use lit_config.substitute instead of foo % lit_config.params everywhere
This mechanically applies the same changes from D121427 everywhere.

Differential Revision: https://reviews.llvm.org/D121746
2022-03-16 09:57:41 +01:00
Shafik Yaghmour 37400dd3e8 [LLDB][NFC] Remove dead code from Section.cpp
Removing comment out code, looks like debugging code left over from a while ago.
2022-03-15 18:11:30 -07:00
Zequan Wu 384e890dd3 [LLDB][NativePDB] Remove REQUIRES: system-windows for local-variables-regsiters.s 2022-03-15 17:49:46 -07:00
Jonas Devlieghere 527d2c5867
[lldb] Fix AppleObjCRuntime log channels
The log channel was changed from Types to Commands in
a007a6d84471bb956abe10974cac3066799f583f:

-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_TYPES));
+    Log *log = GetLog(LLDBLog::Process | LLDBLog::Commands);
2022-03-15 14:47:33 -07:00
Zequan Wu 583223cd5e [LLDB][NativePDB] Don't complete static members' types when completing a record type.
`UdtRecordCompleter` shouldn't complete static members' types. static members' types are going to be completed when the types are called in `SymbolFile::CompleteType`.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D121030
2022-03-15 14:06:54 -07:00
Sterling Augustine 7518e0ff63 Avoid using a variable-sized array for a tiny allocation.
Differential Revision: https://reviews.llvm.org/D121732
2022-03-15 13:00:14 -07:00
Jonas Devlieghere 8e776bb660
Re-land "[lldb] Synchronize output through the IOHandler"
Add synchronization to the IOHandler to prevent multiple threads from
writing concurrently to the output or error stream.

A scenario where this could happen is when a thread (the default event
thread for example) is using the debugger's asynchronous stream. We
would delegate this operation to the IOHandler which might be running on
another thread. Until this patch there was nothing to synchronize the
two at the IOHandler level.

Differential revision: https://reviews.llvm.org/D121500
2022-03-15 12:53:46 -07:00
Jonas Devlieghere 9a5f04e01d
Revert "[lldb] Synchronize output through the IOHandler"
This reverts commit 242c574dc0 because it
breaks the following tests on the bots:

 - TestGuiExpandThreadsTree.py
 - TestBreakpointCallbackCommandSource.py
2022-03-15 09:55:30 -07:00
Shafik Yaghmour 6583f01707 [LLDB] Fixing DWARFExpression handling of ValueType::FileAddress case for DW_OP_deref_size
Currently DW_OP_deref_size just drops the ValueType::FileAddress case and does
not attempt to handle it. This adds support for this case and a test that
verifies this support.

I did a little refactoring since DW_OP_deref and DW_OP_deref_size have some
overlap in code.

Also see: rdar://66870821

Differential Revision: https://reviews.llvm.org/D121408
2022-03-15 09:36:20 -07:00
Jonas Devlieghere b783e5c203
[lldb] Make the PlatformMacOSX unit test Apple specific
I thought that x86GetSupportedArchitectures would always return
x86_64-apple-macosx as a compatible architecture, regardless of the host
achitecture, but the Debian bot disagrees with that.
2022-03-15 09:32:56 -07:00
Jonas Devlieghere 242c574dc0
[lldb] Synchronize output through the IOHandler
Add synchronization to the IOHandler to prevent multiple threads from
writing concurrently to the output or error stream.

A scenario where this could happen is when a thread (the default event
thread for example) is using the debugger's asynchronous stream. We
would delegate this operation to the IOHandler which might be running on
another thread. Until this patch there was nothing to synchronize the
two at the IOHandler level.

Differential revision: https://reviews.llvm.org/D121500
2022-03-15 09:32:56 -07:00
Jonas Devlieghere c22c7a61b6
[lldb] Fix platform selection on Apple Silicon (again)
This patch is another attempt to fix platform selection on Apple
Silicon. It partially undoes D117340 which tried to fix the issue by
always instantiating a remote-ios platform for "iPhone and iPad Apps on
Apple Silicon Macs".

While the previous patch worked for attaching, it broke launching and
everything else that expects the remote platform to be connected. I made
an attempt to work around that, but quickly found out that there were
just too may places that had this assumption baked in.

This patch takes a different approach and reverts back to marking the
host platform compatible with iOS triples. This brings us back to the
original situation where platform selection was broken for remote iOS
debugging on Apple Silicon. To fix that, we now look at the process'
host architecture to differentiate between iOS binaries running remotely
and iOS binaries running locally.

I tested the following scenarios, which now all uses the desired
platform:

  - Launching an iOS binary on macOS: uses the host platform
  - Attaching to an iOS binary on macOS: uses the host platform
  - Attaching to a remote iOS binary: uses the remote-ios platform

rdar://89840215

Differential revision: https://reviews.llvm.org/D121444
2022-03-15 09:06:29 -07:00
Pavel Labath be09f83760 Revert "[lldb/test] Make category-skipping logic "platform"-independent"
This reverts commit dddf4ce034. It breaks
a couple of tests on macos.
2022-03-15 16:23:43 +01:00
Pavel Labath dddf4ce034 [lldb/test] Make category-skipping logic "platform"-independent
The decision which categories are relevant for a particular test run
happen very early in the test setup process. They use the SBPlatform
object to determine which categories should be skipped. The platform
object created for this purpose transcends individual test runs.

This setup is not compatible with the direction discussed in
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>
-- when platform objects are tied to a specific (SB)Debugger, they need
to be created alongside it, which currently happens in the test setUp
method.

This patch is the first step in that direction -- it rewrites the
category skipping logic to avoid depending on a global SBPlatform
object. Fortunately, the skipping logic is fairly simple (and I believe
it outght to stay that way) and mainly consists of comparing the
platform name against some hardcoded lists. This patch bases this
comparison on the platform name instead of the os part of the triple (as
reported by the platform).

Differential Revision: https://reviews.llvm.org/D121605
2022-03-15 13:38:13 +01:00
Jonas Devlieghere 0aaf480be9
[lldb] Cleanup MacOSX platform headers (NFC)
While working on dde487e547 I noticed that the MacOSX platforms were
in need of some love. This patch cleans up the headers:

 - Move platforms into the lldb_private namespace.
 - Remove lldb_private:: prefixes to improve readability.
 - Fix header includes and use forward declarations (iwyu).
 - Fix formatting
2022-03-14 22:01:05 -07:00
Jim Ingham 33f9fc77d1 Don't report memory return values on MacOS_arm64 of SysV_arm64 ABI's.
They don't require that the memory return address be restored prior to
function exit, so there's no guarantee the value is correct.  It's better
to return nothing that something that's not accurate.

Differential Revision: https://reviews.llvm.org/D121348
2022-03-14 15:25:40 -07:00
Shafik Yaghmour 28c878aeb2 [LLDB] Applying clang-tidy modernize-use-default-member-init over LLDB
Applied modernize-use-default-member-init clang-tidy check over LLDB.
It appears in many files we had already switched to in class member init but
never updated the constructors to reflect that. This check is already present in
the lldb/.clang-tidy config.

Differential Revision: https://reviews.llvm.org/D121481
2022-03-14 13:32:03 -07:00
Jonas Devlieghere dde487e547
[lldb] Plumb process host architecture through platform selection
To allow us to select a different platform based on where the process is
running, plumb the process host architecture through platform selection.

This patch is in preparation for D121444 which needs this functionality
to tell apart iOS binaries running on Apple Silicon vs on a remote iOS
device.

Differential revision: https://reviews.llvm.org/D121484
2022-03-14 12:17:01 -07:00
Ben Barham cc63ae42d7 [VFS] Rename `RedirectingFileSystem::dump` to `print`
The rest of LLVM uses `print` for the method taking the `raw_ostream`
and `dump` only for the method with no parameters. Use the same for
`RedirectingFileSystem`.

Differential Revision: https://reviews.llvm.org/D121494
2022-03-14 11:44:07 -07:00
Jonas Devlieghere b0a76b0162
[lldb] Fix the Windows build after D121536 2022-03-14 11:22:21 -07:00
Jonas Devlieghere c231deb791
[lldb] Use the debugger's asynchronous output stream for progress events.
Use the debugger's asynchronous output stream for printing progress
events. This allows the active IOHandler to be in charge of printing
them and doing the necessary synchronization.

Differential revision: https://reviews.llvm.org/D121502
2022-03-14 10:31:22 -07:00
Jonas Devlieghere 2436c5703e
[lldb] Use the IOHandler's stream instead of the debugger's in PrintAsync
PrintAsync is relying on the IOHandler to print to the output/error
stream. In that context it doesn't make much sense that this is using
the debugger's streams rather than the one from the IOHandler.

Differential revision: https://reviews.llvm.org/D121536
2022-03-14 10:11:50 -07:00
Stella Stamenova 8bd1988e74 [lldb] Skip Test11588 on Windows
The test was marked as XFAIL on Windows, but recent changes have made it flaky instead
2022-03-14 09:26:41 -07:00
Jonas Devlieghere 5e65e79bac
[lldb] Move ProgressEventData out of debugger and into its own file (NFC)
Move ProgressEventData out of debugger and into its own file. This is in
preparation of adding a few new type of event data for diagnostics.

Differential revision: https://reviews.llvm.org/D121506
2022-03-14 09:24:17 -07:00
Ayush Sahay d506a9ef2b [lldb] Require native for command-thread-siginfo.test
command-thread-siginfo.test employs a subject with a call to wait, and
thus requires system-linux. However, it's possible to target non-Linux
platforms despite operating on Linux hosts. So, have it require native
too.

Reviewed By: mgorny, labath

Differential Revision: https://reviews.llvm.org/D121487
2022-03-14 21:20:21 +05:30
Petr Hosek 0c0f6cfb7b [CMake] Rename TARGET_TRIPLE to LLVM_TARGET_TRIPLE
This clarifies that this is an LLVM specific variable and avoids
potential conflicts with other projects.

Differential Revision: https://reviews.llvm.org/D119918
2022-03-11 15:43:01 -08:00
Dave Lee 94bda3aaa1 [lldb] Removed scoped timer from ReadMemoryFromFileCache
`ReadMemoryFromFileCache` can be called at a high rate, and has fast execution.
Signposts for high rate & brief duration can have a negative impact on tracing;
emitting a high volume signposts can lead to blocking, affecting performance,
and total volume makes human review of the trace harder because of the noise.

Differential Revision: https://reviews.llvm.org/D121226
2022-03-11 12:46:38 -08:00
Dave Lee 3ca91adef8 [lldb] Move FindTypes scoped timer to SymbolFileDWARFDebugMap 2022-03-11 12:40:06 -08:00
Jonas Devlieghere a6eeffa106
[lldb] Include lldb/Host/HostInfo.h in ProcessWindows.cpp 2022-03-11 12:34:41 -08:00
Jonas Devlieghere 530bc61901
[lldb] Fix typo in ProcessWindows.h 2022-03-11 11:33:16 -08:00
Jonas Devlieghere 68099b1d5c
[lldb] Add a getter for the process' system architecture
This patch adds a getter for the process' system architecture. I went
with Process::GetSystemArchitecture to match
Platform::GetSystemArchitecture.

Differential revision: https://reviews.llvm.org/D121443
2022-03-11 10:58:04 -08:00
Jonas Devlieghere 4ef07e5ffe
[lldb] Don't overwrite the host arch with the process arch
Don't overwrite the host architecture (obtained from qHostInfo) with the
process info (obtained from qProcessInfo).

Differential revision: https://reviews.llvm.org/D121442
2022-03-11 09:23:01 -08:00
Dave Lee 14e4d2e564 [lldb] Remove unused include in ScriptedProcessInterface.h 2022-03-10 14:56:21 -08:00
Dave Lee 47f652d695 [lldb] Call ThreadPlan::DiscardPlan from Thread::DiscardPlan
Correct `Thread::DiscardPlan` to call `DiscardPlan` instead of `PopPlan`.

Differential Revision: https://reviews.llvm.org/D96655
2022-03-10 13:58:08 -08:00
Saleem Abdulrasool c604207608 lldb/ObjectFile,Disassembler: read some state from the executable
Add support to inspect the ELF headers for RISCV targets to determine if
RVC or RVE are enabled and the floating point support to enable.  As per
the RISCV specification, d implies f, q implies d implies f, which gives
us the cascading effect that is used to enable the features when setting
up the disassembler.  With this change, it is now possible to attach the
debugger to a remote process and be able to disassemble the instruction
stream.

~~~
$ bin/lldb tmp/reduced
(lldb) target create "reduced"
Current executable set to '/tmp/reduced' (riscv64).
(lldb) gdb-remote localhost:1234
(lldb) Process 5737 stopped
* thread #1, name = 'reduced', stop reason = signal SIGTRAP
    frame #0: 0x0000003ff7fe1b20
->  0x3ff7fe1b20: mv     a0, sp
    0x3ff7fe1b22: jal    1936
    0x3ff7fe1b26: mv     s0, a0
    0x3ff7fe1b28: auipc  a0, 27
~~~
2022-03-10 21:42:06 +00:00
Jonas Devlieghere c24199e8e8
[lldb] Always listen for progress events in the default event handler
We came to the conclusion that this doesn't matter for VSCode/Xcode
because they don't use the default event loop and that other clients
who might care should use the setting.

Differential revision: https://reviews.llvm.org/D120972
2022-03-10 12:51:27 -08:00
Zequan Wu 5e9c9b324a [LLDB][NativePDB] Add support for S_DEFRANGE_REGISTER and S_DEFRANGE_SUBFIELD_REGISTER
Differential Revision: https://reviews.llvm.org/D119508
2022-03-10 12:40:31 -08:00
Dave Lee e3dfa30501 [lldb] Remove extra space in step logging message
When seeing the extra space in the log, it wasn't clear if there was a missing
printf argument. Removing the extra space removes the potential confusion.
2022-03-10 12:02:58 -08:00
Pavel Labath ed1a83befe [lldb/gdb-remote] Remove ancient debugserver workaround
This workaround is the source of an awkwared Process->Platform
dependency. While this could be solved in various ways (the only thing
we really use is the plugin name), it may be better to just remove it --
the workaround was added 10 years ago (43c555dfc), and the affected
debugservers were "old" even then, so hopefully they are not in use
anymore.

Differential Revision: https://reviews.llvm.org/D121305
2022-03-10 20:26:54 +01:00
Med Ismail Bennani deb359aab3 [lldb/crashlog] Reformat module loading logs (NFC)
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-10 11:06:59 -08:00
Med Ismail Bennani 6aa48034f9 [lldb/Plugin] Test that a scripted process blueprint can be loaded for the dSYM
This patch ensures that lldb can automatically load a scripted process
blueprint from a dSYM bundle and launch a scripted process with it.

rdar://74502750

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-10 11:06:59 -08:00
Med Ismail Bennani 8d097a6b93 [lldb/crashlog] Make interactive mode display more user-friendly
This patch makes the crashlog interactive mode show the scripted process
status with the crashed scripted thread backtrace after launching it.

rdar://89634338

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-10 11:06:59 -08:00
serge-sans-paille 3c4410dfca Cleanup includes: LLVMTarget
Most notably, Pass.h is no longer included by TargetMachine.h
before: 1063570306
after:  1063332844

Differential Revision: https://reviews.llvm.org/D121168
2022-03-10 10:00:29 +01:00
Saleem Abdulrasool f52b5a852a lldb/ObjectFile: reflow a comment (NFC)
Reflow the textual comment which preserves formatted output from
tooling.  This makes the content legible again after the lldb source
code was reformatted with automated tooling.
2022-03-09 18:47:31 +00:00
Pavel Labath d65e6ff2f1 Revert "[lldb] Remove the global platform list"
It makes module dependencies loopier.

This reverts commits 49cffe3c7f and
ffb9429b6f.
2022-03-09 18:13:45 +01:00
Dave Lee 02def06e60 [lldb] Fix step-avoid-regexp logging
Ensure step-avoid-regexp logs are emitted in the case where the regex has no
capture groups.

Without this change, the log is printed only if the regex has at least one
capture group.

Another change is to the log message: the first capture group has been removed
from the message. There could be zero capture groups, and there could be two or
more capture groups.

Differential Revision: https://reviews.llvm.org/D119298
2022-03-09 08:35:15 -08:00
Dave Lee 704001e90b [lldb] Add SBType::IsAggregateType
Add `IsAggregateType` to the SB API.

I'd like to use this from tests, and there are numerous other `Is<X>Type`
predicates on `SBType`.

Differential Revision: https://reviews.llvm.org/D121252
2022-03-09 08:33:08 -08:00
Pavel Labath 49cffe3c7f [lldb] Fix TestDebuggerAPI on windows (broken by D120810) 2022-03-09 16:54:24 +01:00
Pavel Labath ffb9429b6f [lldb] Remove the global platform list
This patch moves the platform creation and selection logic into the
per-debugger platform lists. I've tried to keep functional changes to a
minimum -- the main (only) observable difference in this change is that
APIs, which select a platform by name (e.g.,
Debugger::SetCurrentPlatform) will not automatically pick up a platform
associated with another debugger (or no debugger at all).

I've also added several tests for this functionality -- one of the
pleasant consequences of the debugger isolation is that it is now
possible to test the platform selection and creation logic.

This is a product of the discussion at
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>.

Differential Revision: https://reviews.llvm.org/D120810
2022-03-09 16:11:16 +01:00
Pavel Labath acf77bd2fd [lldb] Don't print *trailing* nuls in char arrays
Embedded nul characters are still printed, and they don't terminate the
string. See also D111634.

Differential Revision: https://reviews.llvm.org/D120803
2022-03-09 14:31:17 +01:00
Pavel Labath 4bcadd6686 [lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.

The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).

Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.

Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.

This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
  automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
  the thread which is running the handler

This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.

I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.

Differential Revision: https://reviews.llvm.org/D120320
2022-03-09 14:31:17 +01:00
Pavel Labath 8f6ee17f22 [lldb] Warn when we fail to find dwo/dwp files
This ensures that the user is aware that many commands will not work
correctly.

We print the warning only once (per module) to avoid spamming the user
with potentially thousands of error messages.

Differential Revision: https://reviews.llvm.org/D120892
2022-03-09 14:31:17 +01:00
Krasimir Georgiev ad709bcfb0 [lldb] Fix -Wformat warning after 5a27b99825
No functional changes intended.
2022-03-09 12:41:34 +01:00
Jonas Devlieghere 8a0fa4db39
[lldb] Add --exists flag to `settings set`
Add a --exists/-e flag to `settings set` that sets the setting if it
exists, but doesn't print an error otherwise. This is useful for example
when setting options in your ~/.lldbinit that might not exist in older
versions of lldb.

Differential revision: https://reviews.llvm.org/D121155
2022-03-08 22:59:26 -08:00
Jonas Devlieghere e618eb8727
[lldb] A few small changes to HandleProgressEvent
Of course I only noticed these things *after* landing the original
patch...

 - Flush the output after clearing the line.
 - Move up the printing the carriage return to avoid duplication.
 - Use hexadecimal instead of octal for escape codes.
2022-03-08 20:27:40 -08:00
Jonas Devlieghere 43374bee0e
[lldb] Undef GetMessage when including Windows.h
GetMessage is a define that can expand to GetMessageA (ANSI) or
GetMessageW (wide). Avoid the issue when including this header by
undef'ing the macro.
2022-03-08 20:07:49 -08:00
Jonas Devlieghere 116715270d
[lldb] Always move the cursor back after printing progress
This got lost while iterating on the patch. We need to always move the
cursor to the front of the line so that if something else
(asynchronously) prints to the debugger's output it overwrites the
progress message.
2022-03-08 18:35:09 -08:00
Jonas Devlieghere 097d46f41c
[lldb] Add a setting to change the progress color
Add a setting to change how progress is shown in a color enabled
terminal. This follows the existing -prefix, -suffix pattern
that's used elsewhere in lldb.

Differential revision: https://reviews.llvm.org/D121062
2022-03-08 18:25:10 -08:00
Jonas Devlieghere 5a27b99825
[lldb] Show progress events in the command line driver
This patch adds support for showing progress events when using lldb on
the command line. It spawns a separate thread that listens for progress
events and prints them to the debugger's output stream.

It's nothing fancy (yet), for now it just prints the progress message.
If we know the total number of items being processed, we prefix the
message with something like [1/100], similar to ninja's output.

This patch doesn't use any fancy terminal manipulation: it uses a simple
carriage return (\r) to bring the cursor to the front of the line and
vt100 escape codes to clear the (rest) of the line.

Differential revision: https://reviews.llvm.org/D120972
2022-03-08 18:24:26 -08:00
Jonas Devlieghere bfab18d86b
[lldb] Remove "(i.e. ANSI)" from several property descriptions.
Addresses Adrian's feedback from D121062.
2022-03-08 18:24:24 -08:00
Muhammad Omair Javaid de0b4f4b86 [LLDB] Skip TestIOHandlerProcessSTDIO.py for Arm/AArch64 Linux
This patch disables TestIOHandlerProcessSTDIO.py for Arm/AArch64 Linux
to silence random test failures on buildbots. IO handler tests are known
to randomly fail on arm/aarch64 linux buildbots due to pexpect timeouts.
2022-03-08 14:15:41 +05:00