Commit Graph

25161 Commits

Author SHA1 Message Date
Michał Górny 3d3017d344 [lldb] [gdb-remote] Use standardized GDB errno values
GDB uses normalized errno values for vFile errors.  Implement
the translation between them and system errno values in the gdb-remote
plugin.

Differential Revision: https://reviews.llvm.org/D108148
2021-09-10 14:08:36 +02:00
Michał Górny 3fade95422 [lldb] [gdb-remote] Support QEnvironment fallback to hex-encoded
Fall back to QEnvironmentHexEncoded if QEnvironment is not supported.
The latter packet is an LLDB extension, while the former is universally
supported.

Add tests for both QEnvironment and QEnvironmentHexEncoded packets,
including both use due to characters that need escaping and fallback
when QEnvironment is not supported.

Differential Revision: https://reviews.llvm.org/D108018
2021-09-10 14:08:36 +02:00
Michał Górny 6ba3f7237d [lldb] [gdb-remote] Implement the vRun packet
Implement the simpler vRun packet and prefer it over the A packet.
Unlike the latter, it tranmits command-line arguments without redundant
indices and lengths.  This also improves GDB compatibility since modern
versions of gdbserver do not implement the A packet at all.

Make qLaunchSuccess not obligatory when using vRun.  It is not
implemented by gdbserver, and since vRun returns the stop reason,
we can assume it to be successful.

Differential Revision: https://reviews.llvm.org/D107931
2021-09-10 14:08:36 +02:00
Michał Górny 501eaf8877 [lldb] [gdb-remote] Add fallbacks for vFile:mode and vFile:exists
Add a GDB-compatible fallback to vFile:fstat for vFile:mode, and to
vFile:open for vFile:exists.  Note that this is only partial fallback,
as it fails if the file cannot be opened.

Differential Revision: https://reviews.llvm.org/D107811
2021-09-10 14:08:36 +02:00
Michał Górny dbb0c14d27 [lldb] Add new commands and tests for getting file perms & exists
Add two new commands 'platform get-file-permissions' and 'platform
file-exists' for the respective bits of LLDB protocol.  Add tests for
them.  Fix error handling in GetFilePermissions().

Differential Revision: https://reviews.llvm.org/D107809
2021-09-10 14:08:36 +02:00
Michał Górny c240d2bb06 [lldb] [test] Move "platform connect" logic into a common class
Create a common GDBPlatformClientTestBase class and move the platform
select/connect logic there to reduce duplication.

Differential Revision: https://reviews.llvm.org/D109585
2021-09-10 14:08:35 +02:00
Raphael Isemann 0c8444bd34 [lldb] Fix Clang modules build after D101329
D101329 introduces the Process:SaveCore function returning a
`llvm::Expected<bool>`. That function causes that Clang with -fmodules crashes
while compiling LLDB's PythonDataObjects.cpp. With enabled asserts Clang fails
because of:

    Assertion failed: (CachedFieldIndex && "failed to find field in parent")

Crash can be reproduced by building via -DLLVM_ENABLE_MODULES=On with Clang
12.0.1 and then building PythonDataObjects.cpp.o .

Clang bug is tracked at rdar://82901462
2021-09-10 13:10:19 +02:00
Michał Górny caf508d712 [lldb] [test] Synchronize before the breakpoint in fork tests
We set breakpoint on child_func, so synchronization inside it is too
late to guarantee ordering between the parent output and child
breakpoint.  Split the function in two, and perform synchronization
before the breakpoint.

Differential Revision: https://reviews.llvm.org/D109591
2021-09-10 13:06:01 +02:00
Michał Górny e066c00be0 [lldb] [gdb-server] Zero-initialize fields on WIN32 2021-09-10 11:59:06 +02:00
Michał Górny a1097d315c Reland "[lldb] [gdb-server] Implement the vFile:fstat packet"
Now with an #ifdef for WIN32.

Differential Revision: https://reviews.llvm.org/D107840
2021-09-10 11:57:59 +02:00
Michał Górny 70558d39f0 Revert "[lldb] [gdb-server] Implement the vFile:fstat packet"
This reverts commit 9e886fbb18.  It breaks
on Windows.
2021-09-10 11:43:24 +02:00
Michał Górny 9e886fbb18 [lldb] [gdb-server] Implement the vFile:fstat packet
Differential Revision: https://reviews.llvm.org/D107840
2021-09-10 11:09:35 +02:00
Michał Górny 21e2d7ce43 [lldb] [gdb-remote] Implement fallback to vFile:stat for GetFileSize()
Implement a fallback to getting the file size via vFile:stat packet
when the remote server does not implement vFile:size.  This makes it
possible to query file sizes from remote gdbserver.

Note that unlike vFile:size, the fallback will not work if the server is
unable to open the file.

While at it, add a few tests for the 'platform get-size' command.

Differential Revision: https://reviews.llvm.org/D107780
2021-09-10 11:09:35 +02:00
Michał Górny 24332f0e27 [lldb] [Process/FreeBSD] Introduce mips64 FPU reg support
Differential Revision: https://reviews.llvm.org/D96766
2021-09-10 09:13:15 +02:00
Michał Górny f659bf00b4 [lldb] [test] Add synchronization fix Subprocess test flakiness
Add synchronization routines to ensure that Subprocess tests output
in a predictable order, and all test strings are output before the tests
terminate.

Differential Revision: https://reviews.llvm.org/D109495
2021-09-10 09:11:08 +02:00
Jason Molenda f3472ad5c5 Add specific error messages around gdb RSP handshake failures
Report timeout exceeded and connection lost error messages
when sending the initial handshake packet in a gdb remote
serial protocol connection, an especially fragile time.

Differential Revision: https://reviews.llvm.org/D108888
2021-09-09 17:02:42 -07:00
Jason Molenda 766afbc804 Don't re-define constants that are now in compact_unwind_encoding.h. 2021-09-09 17:01:43 -07:00
Chris Lattner 735f46715d [APInt] Normalize naming on keep constructors / predicate methods.
This renames the primary methods for creating a zero value to `getZero`
instead of `getNullValue` and renames predicates like `isAllOnesValue`
to simply `isAllOnes`.  This achieves two things:

1) This starts standardizing predicates across the LLVM codebase,
   following (in this case) ConstantInt.  The word "Value" doesn't
   convey anything of merit, and is missing in some of the other things.

2) Calling an integer "null" doesn't make any sense.  The original sin
   here is mine and I've regretted it for years.  This moves us to calling
   it "zero" instead, which is correct!

APInt is widely used and I don't think anyone is keen to take massive source
breakage on anything so core, at least not all in one go.  As such, this
doesn't actually delete any entrypoints, it "soft deprecates" them with a
comment.

Included in this patch are changes to a bunch of the codebase, but there are
more.  We should normalize SelectionDAG and other APIs as well, which would
make the API change more mechanical.

Differential Revision: https://reviews.llvm.org/D109483
2021-09-09 09:50:24 -07:00
Ryan Mansfield 4f1c90a6d4 [lldb] Fix format string in Communication::Write
Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D109508
2021-09-09 17:55:38 +02:00
Raphael Isemann cda1450f1c [lldb][NFC] Add some tests for function-local classes and document some bugs
This feature doesn't seem to have any dedicated test. Instead some random tests
(e.g. the bitfield tests) are declaring function-local classes for some reason.
This adds a dedicated test so we can clean up those other tests.

Also add FIXME's for some basic stuff that doesn't work. The first FIXME is a
good beginner bug which just requires prepending the function name (in case we
decide to fix it instead of documenting this behaviour). The second FIXME is
caused by LLDB searching for definitions by name (which also seems to miss the
function name so there is a conflict with the outer type).

Some more things that should be tested (and might not work):
* Local classes with member functions with local classes.
* Classes in different functions with same name.
* Classes with the same name in different TUs with internal linkage functions of
  the same name.
* Empty classes are parsed by the DWARF parser in a fast path, so that requires
  dedicated tests.
* Repeat some of the tested logic for C.
2021-09-09 14:12:02 +02:00
Muhammad Omair Javaid 8901f8beea AArch64 SVE restore SVE registers after expression
This patch fixes register save/restore on expression call to also include SVE registers.

This will fix expression calls like:

re re p1

<Register Value P1 before expression>

p <var-name or function call>

re re p1

<Register Value P1 after expression>

In above example register P1 should remain the same before and after the expression evaluation.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D108739
2021-09-09 16:06:48 +05:00
Michał Górny d1280f6967 [lldb] [test] Add tests for coredumps with multiple threads
Differential Revision: https://reviews.llvm.org/D101157
2021-09-09 09:59:52 +02:00
Jonas Devlieghere d1d4f36556 [lldb] Make sure there's a value for the key before dereferencing.
Make sure there's a value for the shared_cache_base_address key exists
in the dictionary before trying to dereference the value.

rdar://76894476
2021-09-08 13:46:09 -07:00
Alex Langford 303b27f21b [lldb] Delete IRExecutionUnit::SearchSpec
IRExecutionUnit::SearchSpec is a struct that encapsulates information
needed to look for a symbol. Specifically, it is comprised of a name
represented with a ConstString and a FunctionNameType mask.
Because the mask is unused (effectively always set to
eFunctionNameTypeFull), we can remove the mask and replace all uses with
eFunctionNameTypeFull.  After doing that, SearchSpec is effectively a
wrapper around a ConstString.

As an aside, SearchSpec is similar in purpose to Module::LookupInfo. I
briefly considered replacing uses of SearchSpec with LookupInfo, but
the current code only cares about symbol names (treating them as
eFunctionNameTypeFull). This code does care about language type, so
LookupInfo may be appropriate for IRExecutionUnit in the future.

Differential Revision: https://reviews.llvm.org/D109384
2021-09-08 11:27:10 -07:00
David Spickett d2189b5c4b [lldb] Remove unused GDBRemoteCommunicationClient::SendAttach function
Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D109427
2021-09-08 15:14:02 +00:00
Michał Górny 2c6d90d741 [lldb] [Commands] Remove 'append' from 'platform file open' mode
Remove File::eOpenOptionAppend from the mode used by 'platform file
open' command.  According to POSIX, O_APPEND causes all successive
writes to be done at the end of the file.  This effectively makes
the offset argument to 'platform file write' meaningless.

Furthermore, apparently O_APPEND is not implemented reliably everywhere.
The Linux manpage for pwrite(2) suggests that Linux does respect
O_APPEND there while according to POSIX it should not, so the actual
behavior would be dependent on how the vFile:pwrite packet is
implemented on the server.

Ideally, the mode used for opening flags would be provided via options.
However, changing the default mode seems to be a reasonable intermediate
solution.

Differential Revision: https://reviews.llvm.org/D107664
2021-09-08 15:28:03 +02:00
Michał Górny c01b76e733 [lldb] Support "eflags" register name in generic reg fallback
Enhance the generic register fallback code to support "eflags" register
name in addition to "rflags", as the former is used by gdbserver.  This
permits lldb-server to recognize the generic flags register when
interfacing with gdbserver-style target.xml (i.e. without generic=""
attributes), and therefore aligns ABI plugins' AugmentRegisterInfo()
between lldb-server and gdbserver.

Differential Revision: https://reviews.llvm.org/D108548
2021-09-08 11:33:29 +02:00
Michał Górny 8872c9d1ca [lldb] [gdb-server] Add tests for more vFile packets
Differential Revision: https://reviews.llvm.org/D107821
2021-09-08 10:58:12 +02:00
Michał Górny 39a2449ea1 [lldb] [Commands] Fix reporting errors in 'platform file read/write'
Fix 'platform file read' and 'platform file write' commands to correctly
detect erraneous return and report it as such.  Currently, errors were
implicitly printed as a return value of -1, and the commands were
assumed to be successful.

Differential Revision: https://reviews.llvm.org/D107665
2021-09-08 10:58:12 +02:00
Michał Górny b07803ee2a [lldb] [Process/FreeBSD] Support SaveCore() using PT_COREDUMP
Differential Revision: https://reviews.llvm.org/D109326
2021-09-08 10:58:12 +02:00
Nico Weber cfe0284749 [gn build] Add build files for LLDB
This is enough to get the lit-based tests to pass on macOS.

Doesn't yet add build targets for:
- Any LLDB unit tests
- swig bindings
- various targets not needed by lit tests

LLDB has many dependency cycles, something GN doesn't allow. For
that reason, I've omitted some dependency edges. Hopefully we can
clean up the cycles one day.

LLDB has a public/private header distinction, but mostly ignores it.
Many libraries include private headers from other modules.

Since LLDB is the first target the LLVM/GN build that uses Objective-C++
code, add some machinery to the toolchain file to handle that.

Differential Revision: https://reviews.llvm.org/D109185
2021-09-07 15:25:04 -04:00
Nico Weber ea04bf302c [lldb] Alphabetize some CMake files a bit better
No observable behavior change, but makes the generated Plugins.def a bit easier
to read.

Differential Revision: https://reviews.llvm.org/D109367
2021-09-07 13:19:00 -04:00
David Spickett a97efde54e [lldb] Add missing newline to stderr output on failed attach 2021-09-07 15:49:07 +00:00
Jonas Devlieghere 4da5a446f8 [lldb] Update crashlog.py to accept multiple results from mdfind
mdfind can return multiple results, some of which are not even dSYM
bundles, but Xcode archives (.xcrachive).

Currently, we end up concatenating the paths, which is obviously bogus.
This patch not only fixes that, but now also skips paths that don't have
a Contents/Resources/DWARF subdirectory.

rdar://81270312

Differential revision: https://reviews.llvm.org/D109263
2021-09-07 08:36:58 -07:00
Benjamin Kramer 4a0ba4180b [lldb] Fix pessimizing move warning
lldb/source/Core/PluginManager.cpp:695:21: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
      return Status(std::move(ret.takeError()));
                    ^
lldb/source/Core/PluginManager.cpp:695:21: note: remove std::move call here
      return Status(std::move(ret.takeError()));
                    ^~~~~~~~~~               ~
2021-09-06 21:17:29 +02:00
Michał Górny 25fbbc5936 [lldb] Support SaveCore() from gdb-remote client
Extend PluginManager::SaveCore() to support saving core dumps
via Process plugins.  Implement the client-side part of qSaveCore
request in the gdb-remote plugin, that creates the core dump
on the remote host and then uses vFile packets to transfer it.

Differential Revision: https://reviews.llvm.org/D101329
2021-09-06 18:33:02 +02:00
Benjamin Kramer ac312a9d7c [lldb] Silence compiler warnings from 37cbd817d3
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:3638:30: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
    return SendErrorResponse(std::move(ret.takeError()));
                             ^
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:3638:30: note: remove std::move call here
    return SendErrorResponse(std::move(ret.takeError()));
                             ^~~~~~~~~~               ~
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:3622:8: error: unused variable 'cf' [-Werror,-Wunused-variable]
  bool cf = packet_str.consume_front("qSaveCore");
2021-09-06 13:04:21 +02:00
Benjamin Kramer 7fa6b9f610 [lldb] Silence compiler warning after fae0dfa642
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4765:13: warning: enumeration value 'Ibm128' not handled in switch [-Wswitch]
    switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) {
            ^
2021-09-06 12:30:47 +02:00
Michał Górny 37cbd817d3 [lldb] [llgs server] Support creating core dumps on NetBSD
Add a new SaveCore() process method that can be used to request a core
dump.  This is currently implemented on NetBSD via the PT_DUMPCORE
ptrace(2) request, and enabled via 'savecore' extension.

Protocol-wise, a new qSaveCore packet is introduced.  It accepts zero
or more semicolon-separated key:value options, invokes the core dump
and returns a key:value response.  Currently the only option supported
is "path-hint", and the return value contains the "path" actually used.
The support for the feature is exposed via qSaveCore qSupported feature.

Differential Revision: https://reviews.llvm.org/D101285
2021-09-06 12:16:14 +02:00
Shivam Gupta 59c954f76a [LLDB][Docs] Indicate `PS1` variable by $ 2021-09-04 20:57:59 +05:30
Med Ismail Bennani 5f6f33da9e [lldb/Plugins] Move member template specialization out of class
This patch should fix the build failure that surfaced when build llvm
with GCC: https://lab.llvm.org/staging/#/builders/16/builds/10450

GCC complained that I explicitely specialized
 `ScriptedPythonInterface::ExtractValueFromPythonObject` in a
in non-namespace scope, which is tolerated by Clang.

To solve this issue, the specialization were declared out of the class
and implemented in the source file.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-09-03 22:18:55 +00:00
Jonas Devlieghere 05cdd294ab [lldb] Adjust parse_frames for unnamed images
Follow up to 2cbd3b04fe which added
support for unnamed images but missed the use case in parse_frames.
2021-09-03 13:23:24 -07:00
Med Ismail Bennani 3925204c1f [lldb/Plugins] Introduce Scripted Interface Factory
This patch splits the previous `ScriptedProcessPythonInterface` into
multiple specific classes:

1. The `ScriptedInterface` abstract class that carries the interface
   instance object and its virtual pure abstract creation method.

2. The `ScriptedPythonInterface` that holds a generic `Dispatch` method that
   can be used by various interfaces to call python methods and also keeps a
   reference to the Python Script Interpreter instance.

3. The `ScriptedProcessInterface` that describes the base Scripted
   Process model with all the methods used in the underlying script.

All these components are used to refactor the `ScriptedProcessPythonInterface`
class, making it more modular.

This patch is also a requirement for the upcoming work on `ScriptedThread`.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-09-03 19:37:25 +02:00
Michał Górny 5ef63c953f [lldb] [test] Mark the remaining vfork-follow-child test unsupported (flaky) on aarch64 2021-09-03 16:30:25 +02:00
Michał Górny dda643c9fb [lldb] [test] Mark vfork-follow-child-* tests unsupported (flaky) on aarch64 2021-09-03 16:04:34 +02:00
Kim-Anh Tran ec671f3ea0 [lldb] Support .debug_rnglists.dwo sections in dwp file
This patch considers the CU index entry
when reading the .debug_rnglists.dwo section.

Reviewed By: jankratochvil

Differential Revision: https://reviews.llvm.org/D107456
2021-09-03 15:19:50 +02:00
Siger Yang 49229bb92b Revert "[lldb/lua] Force Lua version to be 5.3"
This commit causes buildbot failures if SWIG is available but Lua is
not present.

This reverts commit 7bb42dc6b1.
2021-09-03 17:31:25 +08:00
Siger Yang 7bb42dc6b1 [lldb/lua] Force Lua version to be 5.3
Due to CMake cache, find_package in FindLuaAndSwig.cmake
will be ignored. This commit adds EXACT and REQUIRED flags
to it and removes find_package in Lua ScriptInterpreter.

Signed-off-by: Siger Yang <sigeryeung@gmail.com>

Reviewed By: tammela, JDevlieghere

Differential Revision: https://reviews.llvm.org/D108515
2021-09-03 15:22:57 +08:00
Michał Górny 808bcb7a0e [lldb] [test] Mark *fork-follow-child* tests non-Darwin 2021-09-03 09:07:53 +02:00
Arthur Eubanks ebbf7f90b5 Fix lldb after D108614 2021-09-02 12:58:41 -07:00
Nico Weber 7f544f7658 Try to unbreak lldb build after 973519826e 2021-09-02 11:32:28 -04:00
Raphael Isemann bbcb4d6bc0 Revert "[lldb server] Tidy up LLDB server return codes and associated tests"
This reverts commit e387c8c413. The
TestErrorMessages.test is failing on the Linux bots.
2021-09-02 15:27:39 +02:00
Michał Górny 4a2a947317 [lldb] [client] Implement follow-fork-mode
Implement a new target.process.follow-fork-mode setting to control
LLDB's behavior on fork.  If set to 'parent', the forked child is
detached and parent continues being traced.  If set to 'child',
the parent is detached and child becomes traced instead.

Differential Revision: https://reviews.llvm.org/D100503
2021-09-02 12:16:58 +02:00
Sebastian Schwartz e387c8c413 [lldb server] Tidy up LLDB server return codes and associated tests
This diff modifies the LLDB server return codes to more accurately reflect usage
error paths. Specifically we always propagate the return codes from the main
entrypoints into GDB remote LLDB server, and platform LLDB server. This way, the
top-level caller of LLDB server will be able to correctly check whether the
executable exited with or without an error.

We additionally modify and extend the associated shell unit tests to expect
nonzero return codes on error conditions.

Test Plan:
LLDB tests pass:

```
ninja check-lldb
```

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D108351
2021-09-02 11:16:37 +02:00
Andrej Korman eee687a66d [lldb] Add minidump save-core functionality to ELF object files
This change adds save-core functionality into the ObjectFileELF that enables
saving minidump of a stopped process. This change is mainly targeting Linux
running on x86_64 machines. Minidump should contain basic information needed
to examine state of threads, local variables and stack traces. Full support
for other platforms is not so far implemented. API tests are using LLDB's
MinidumpParser.

This relands commit aafa05e, reverted in 1f986f6.
Failed tests were fixed.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D108233
2021-09-01 15:14:29 +02:00
Michał Górny c568985845 [lldb] [gdb-remote client] Remove breakpoints throughout vfork
Temporarily remove breakpoints for the duration of vfork, in order
to prevent them from triggering in the child process.  Restore them
once the server reports that vfork has finished and it is ready to
resume execution.

Differential Revision: https://reviews.llvm.org/D100267
2021-09-01 10:33:48 +02:00
Michał Górny ceccbb8145 Revert "[lldb] [gdb-remote client] Remove breakpoints throughout vfork"
This reverts commit 199344d832.
It caused regressions on arm, as reported by lldb-arm-ubuntu buildbot.
2021-09-01 08:53:35 +02:00
Michał Górny 199344d832 [lldb] [gdb-remote client] Remove breakpoints throughout vfork
Temporarily remove breakpoints for the duration of vfork, in order
to prevent them from triggering in the child process.  Restore them
once the server reports that vfork has finished and it is ready to
resume execution.

Differential Revision: https://reviews.llvm.org/D100267
2021-09-01 08:16:12 +02:00
Alex Langford 862a311301 [lldb] Tighten lock in Language::ForEach
It is easy to accidentally introduce a deadlock by having the callback
passed to Language::ForEach also attempt to acquire the same lock. It
is easy enough to disallow the callback from calling anything in
Language directly, but it may happen through a series of other
function/method calls.

The solution I am proposing is to tighten the lock in Language::ForEach
so that it is only held as we gather the currently loaded language
plugins. We store them in a vector and then iterate through them with
the callback so that the callback can't introduce a deadlock.

Differential Revision: https://reviews.llvm.org/D109013
2021-08-31 15:45:38 -07:00
Michał Górny 84f99ef2b1 [lldb] [test] Mark fork-follow-parent-softbp.test as darwin-unsupported 2021-08-31 21:19:27 +02:00
Raphael Isemann 4f7fb13f87 [lldb] Don't save empty expressions in the multiline editor history
Right now running `expr` to start the multiline expression editor and then
pressing enter causes an empty history empty to be created for the multiline
editor. That doesn't seem very useful for users as pressing the 'up' key will
now also bring up these empty expressions.

I don't think there is ever a use case for recalling a completely empty
expression from the history, so instead don't save those entries to the history
file and make sure we never recall them when navigating over the expression
history.

Note: This is actually a Swift downstream patch that got shipped with Apple's
LLDB for many years. However, this recently started conflicting with upstream
LLDB as D100048 added a test that made sure that empty expression entries don't
crash LLDB. Apple's LLDB was never affected by this crash as it never saved
empty expressions in the first place.

Reviewed By: augusto2112

Differential Revision: https://reviews.llvm.org/D108983
2021-08-31 18:51:18 +02:00
Michał Górny 8307869a22 [lldb] [gdb-remote client] Remove breakpoints in forked processes
Remove software breakpoints from forked processes in order to restore
the original program code before detaching it.

Differential Revision: https://reviews.llvm.org/D100263
2021-08-31 13:41:35 +02:00
Andy Yankovsky 1f986f6057 Revert "[lldb] Add minidump save-core functionality to ELF object files"
This reverts commit aafa05e03d.

Broke builder on aarch64 --
https://lab.llvm.org/buildbot/#/builders/96/builds/10926
2021-08-31 13:36:53 +02:00
Andrej Korman aafa05e03d [lldb] Add minidump save-core functionality to ELF object files
This change adds save-core functionality into the ObjectFileELF that enables
saving minidump of a stopped process. This change is mainly targeting Linux
running on x86_64 machines. Minidump should contain basic information needed
to examine state of threads, local variables and stack traces. Full support
for other platforms is not so far implemented. API tests are using LLDB's
MinidumpParser.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D108233
2021-08-31 13:04:38 +02:00
Jason Molenda c1184ca6eb Use dSYM's file addr for Sections when it doesn't match binary
When adding a dSYM to a Module and it has different file addresses
from the already-present ObjectFile binary, change the Sections to
use the dSYM's file addresses so the symbol table and DWARF are
properly contained in the Sections.  Previously this was only done
for IsInMemory ObjectFiles, but it's more common than that.

Differential Revision: https://reviews.llvm.org/D108889
rdar://81504400
2021-08-31 01:35:07 -07:00
Shivam Gupta 654e8d6c31 [LLDB][Docs] Move best-practices.txt contain to resources/test.rst
This file contain some old reference to files those are now either renamed or replaced.
Also this .txt file didn't generate to html during the sphnix documentation build so I send its contents to resources/test.rst file.

Signed-off-by: Shivam Gupta <shivam98.tkg@gmail.com>

Reviewed By: teemperor, mgorny, JDevlieghere

Differential Revision: https://reviews.llvm.org/D108812
2021-08-31 11:45:24 +05:30
Shivam Gupta 3af9847a95 [LLDB][Docs] Convert some .txt files to .rst
Upadate some .txt files to .rst for consistency as most
of the documentation is written in reStructuredText format.

Signed-off-by: Shivam Gupta <shivam98.tkg@gmail.com>

Differential Revision: https://reviews.llvm.org/D108807
2021-08-31 11:45:24 +05:30
Raphael Isemann 2ce889fa4e [lldb][NFC] Add size tests for empty records with alignment and with empty members
This came up during the Windows bot failure discussing after D105471 . See
also 3d9a9fa691 .
2021-08-30 16:38:13 +02:00
Hiroki ffcf571107 [LLDB] Fix 'std::out_of_range' crashing bug when file name completion using file path.
When I run a lldb command that uses filename completion, if I enter a string
that is not only a filename but also a string with a non-file name string added,
such as "./" that is relative path string , it will crash as soon as I press the
[Tab] key. For example, debugging an executable file named "hello" that is
compiled from a file named "hello.c" , and I’ll put a breakpoint on line 3 of
hello.c.

```
$ lldb ./hello
(lldb) breakpoint set --file hello.c --line 3
```

This is not a problem, but if I set "--file ./hello."  and then press [Tab] key
to complete file name, lldb crashes.

```
$ lldb ./hello
(lldb) breakpoint set --file ./hello.terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 8) > this->size() (which is 7)
```

The crash was caused because substr() (in lldb/source/Host/common/Editline.cpp)
cut out string which size is user's input string from the completion string.

I modified the code that erase the user's intput string from current line and
then add the completion string.

Differential Revision: https://reviews.llvm.org/D108817
2021-08-30 15:14:09 +02:00
Kim-Anh Tran 3973d8b29e [lldb] Return all line entries matchign a line if no column is specified
Previously, if no column was specified, ResolveSymbolContext would take
the first match returned by FindLineEntryIndexByFileIndex, and reuse it
to find subsequent exact matches. With the introduction of columns, columns
are now considered when matching the line entries.

This leads to a problem if one wants to get all existing line entries
that match that line, since now the column is also used for the exact match.
This way, all line entries are filtered out that have a different
column number, but the same line number.

This patch changes that by ignoring the column information of the first match
if the original request of ResolveSymbolContext was also ignoring it.

Reviewed By: mib

Differential Revision: https://reviews.llvm.org/D108816
2021-08-30 14:45:46 +02:00
Raphael Isemann f3ad3ea471 [lldb][NFC] Remove TypeSystemClang::CreateFunctionType overload
This can just be a default argument.
2021-08-30 12:28:20 +02:00
Michał Górny 0a1d80d56e [lldb] [gdb-remote client] Support minimal fork/vfork handling
Add a support for handling fork/vfork stops in LLGS client.  At this
point, it only sends a detach packet for the newly forked child
(and implicitly resumes the parent).

Differential Revision: https://reviews.llvm.org/D100206
2021-08-30 10:24:38 +02:00
Roman Podoliaka 54c496dad6 [lldb] Allow to register frame recognizers applied beyond the first instruction
It is currently possible to register a frame recognizer, but it will be applied if and only if the frame's PC points to the very first instruction of the specified function, which limits usability of this feature.

The implementation already supports changing this behaviour by passing an additional flag, but it's not possible to set it via the command interface. Fix that.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D108510
2021-08-29 17:28:46 +02:00
Walter Erquinigo 602497d672 [trace] [intel pt] Create a "process trace save" command
added new command "process trace save -d <directory>".
-it saves a JSON file as <directory>/trace.json, with the main properties of the trace session.
-it saves binary Intel-pt trace as <directory>/thread_id.trace; each file saves each thread.
-it saves modules to the directory <directory>/modules .
-it only works for live process and it only support Intel-pt right now.

Example:
```
b main
run
process trace start
n
process trace save -d /tmp/mytrace
```
A file named trace.json and xxx.trace should be generated in /tmp/mytrace. To load the trace that was just saved:
```
trace load /tmp/mytrace
thread trace dump instructions
```
You should see the instructions of the trace got printed.

To run a test:
```
cd ~/llvm-sand/build/Release/fbcode-x86_64/toolchain
ninja lldb-dotest
./bin/lldb-dotest -p TestTraceSave
```

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D107669
2021-08-27 09:34:01 -07:00
David Blaikie 3784fc493e Remove set-but-unused variable 2021-08-26 16:58:47 -07:00
Shafik Yaghmour 2a4a498a88 [LLDB] Add type to the output for FieldDecl when logging in ClangASTSource::layoutRecordType
I was debugging a problem and noticed that it would have been helpful to have
the type of each FieldDecl when looking at the output from
ClangASTSource::layoutRecordType.

Differential Revision: https://reviews.llvm.org/D108257
2021-08-26 11:17:47 -07:00
Walter Erquinigo c62ef0255d [NFC] Removing deprecated intel-features test folder
This folder has no valid tests anymore
2021-08-26 10:36:00 -07:00
Walter Erquinigo 600a2a7ec0 [NFC] Remove deprecated Intel PT test 2021-08-26 10:34:04 -07:00
Omar Emara 3c11e5722c [LLDB][GUI] Add initial searcher support
This patch adds a new type of reusable UI components. Searcher Windows
contain a text field to enter a search keyword and a list of scrollable
matches are presented. The target match can be selected and executed
which invokes a user callback to do something with the match.

This patch also adds one searcher delegate, which wraps the common
command completion searchers for simple use cases.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D108545
2021-08-25 13:55:11 -07:00
Rumeet Dhindsa 120d97b1a7 Revert "[lldb] Add support for debugging via the dynamic linker."
This reverts commit 1cbdc07ec0.

Buildbot failure started after this patch with failure in
api/multithreaded/TestMultithreaded.py:
https://lab.llvm.org/buildbot/#/builders/68/builds/17556
2021-08-24 15:20:52 -07:00
Muhammad Omair Javaid d7e2e9794a [LLDB] Remove typos from NativeRegisterContextLinux_arm*
This patch removed some typos from NativeRegisterContextLinux_arm and
NativeRegisterContextLinux_arm64. Some of the log/error messages were
being reported as x86_64.
2021-08-25 02:55:38 +05:00
Alex Langford ce512d5c2a Revert "[lldb] Refactor Module::LookupInfo constructor"
This reverts commit cd2134e42a.

Seems like this broke some tests on arm and aarch64 boxes. Will
investigate before re-landing.
2021-08-24 14:52:17 -07:00
Alex Langford cd2134e42a [lldb] Refactor Module::LookupInfo constructor
Module::LookupInfo's constructor currently goes over supported languages
trying to figure out the best way to search for a symbol name. This
seems like a great candidate for refactoring. Specifically, this is work
that can be delegated to language plugins.

Once again, the goal here is to further decouple plugins from
non-plugins. The idea is to have each language plugin take a name and
give you back some information about the name from the perspective of
the language. Specifically, each language now implements a
`GetFunctionNameInfo` method which returns an object of type
`Language::FunctionNameInfo`. Right now, it consists of a basename,
a context, and a FunctionNameType. Module::LookupInfo's constructor will
call `GetFunctionNameInfo` with the appropriate language plugin(s) and
then decide what to do with that information. I have attempted to maintain
existing behavior as best as possible.

A nice side effect of this change is that lldbCore no longer links
against the ObjC Language plugin.

Differential Revision: https://reviews.llvm.org/D108229
2021-08-24 13:53:49 -07:00
Rumeet Dhindsa 1cbdc07ec0 [lldb] Add support for debugging via the dynamic linker.
This patch adds support for shared library load when the executable is
called through ld.so.

Differential Revision:https://reviews.llvm.org/D108061
2021-08-24 13:41:22 -07:00
Omar Emara 292f013395 [LLDB][GUI] Handle extra navigation keys in forms
This patch handles the up and down keys if they weren't handled by the
selected field. Moreover, it makes sure the form always absorb the key
to take full control until the form is canceled or submitted.

Differential Revision: https://reviews.llvm.org/D108414
2021-08-23 22:42:57 -07:00
Omar Emara 945cde8b6a [LLDB][GUI] Add submit form key combination
This patch adds a new key ALt+Enter key combination to form windows.
Once invoked, the first action is executed without having to navigate to
its button.

Field exit callbacks are now also invoked on validation to support this
aforementioned key combination.

One concern for this key combination is its potential use by the window
manager of the host. I am not sure if this will be a problem, but it is
worth putting in consideration.

Differential Revision: https://reviews.llvm.org/D108410
2021-08-23 22:07:04 -07:00
Omar Emara d95d2a8e4a [LLDB][GUI] Add extra keys to text field
This patch adds many new keys to the text field and implements new
behaviors as follows:

```
case KEY_HOME:
case KEY_CTRL_A:
  MoveCursorToStart();
case KEY_END:
case KEY_CTRL_E:
  MoveCursorToEnd();
case KEY_RIGHT:
case KEY_SF:
  MoveCursorRight();
case KEY_LEFT:
case KEY_SR:
  MoveCursorLeft();
case KEY_BACKSPACE:
case KEY_DELETE:
  RemovePreviousChar();
case KEY_DC:
  RemoveNextChar();
case KEY_EOL:
case KEY_CTRL_K:
  ClearToEnd();
case KEY_DL:
case KEY_CLEAR:
  Clear();
```

This patch also refactors scrolling to be dynamic at draw time for
easier handing.

Differential Revision: https://reviews.llvm.org/D108385
2021-08-23 21:16:48 -07:00
Alex Langford 23c19395c0 [lldb][NFC] Remove unused method RichManglingContext::IsFunction 2021-08-23 11:45:55 -07:00
Kirill Shmakov 2cc1198e36 [lldb] Fix typo in the description of breakpoint options 2021-08-21 12:24:29 +02:00
Fangrui Song 40aab0412f [test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=
Space separated driver options are uncommon but Clang traditionally
did not do a good job. --gcc-toolchain= is the preferred form.
2021-08-20 15:24:58 -07:00
Rumeet Dhindsa d9c5613e85 Update logic to close inherited file descriptors.
This patch adds the support to close all inherited fds into the child
process by iterating over /proc/self/fd entries.

Differential Revision: https://reviews.llvm.org/D105732
2021-08-19 14:40:43 -07:00
Omar Emara 28a76049c6 [LLDB][GUI] Handle return key for compound fields
This patch handles the return key for compound fields like lists and
mapping fields. The return key, if not handled by the field will select
the next primary element, skipping secondary elements like remove
buttons and the like.

Differential Revision: https://reviews.llvm.org/D108331
2021-08-19 11:46:30 -07:00
Alex Langford 4947f6d8bc [lldb][NFC] Remove unused header include 2021-08-19 11:06:56 -07:00
Omar Emara 82507f1798 [LLDB][GUI] Add Process Launch form
This patch adds a process launch form. Additionally, a LazyBoolean field
was implemented and numerous utility methods were added to various
fields to get the launch form working.

Differential Revision: https://reviews.llvm.org/D107869
2021-08-18 15:43:30 -07:00
Omar Emara 698e210636 [LLDB][GUI] Fix text field incorrect key handling
The isprint libc function was used to determine if the key code
represents a printable character. The problem is that the specification
leaves the behavior undefined if the key is not representable as an
unsigned char, which is the case for many ncurses keys. This patch adds
and explicit check for this undefined behavior and make it consistent.

The llvm::isPrint function didn't work correctly for some reason, most
likely because it takes a char instead of an int, which I guess makes it
unsuitable for checking ncurses key codes.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D108327
2021-08-18 15:06:27 -07:00
Jonas Devlieghere c64d1855b9 [lldb] Include arm64 in affected_by_radar_34562999
The same issue impacts arm64, both on-device and on Apple Silicon.
2021-08-17 19:45:45 -07:00
Jonas Devlieghere a452ca471c [lldb] Extend isAArch64 to arm64 and arm64e
This fixes TestMemoryTag on Apple Silicon.
2021-08-17 19:45:45 -07:00
Omar Emara b26e1efc42 [LLDB][GUI] Add Breakpoints window
This patch adds a breakpoints window that lists all breakpoints and
breakpoints locations. The window is implemented as a tree, where the
first level is the breakpoints and the second level is breakpoints
locations.

The tree delegate was hardcoded to only draw when there is a process,
which is not necessary for breakpoints, so the relevant logic was
abstracted in the TreeDelegateShouldDraw method.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D107386
2021-08-17 17:38:16 -07:00
Omar Emara 79e950a29e [LLDB][GUI] Refactor form drawing using subsurfaces
This patch adds a new method SubSurface to the Surface class. The method
returns another surface that is a subset of this surface. This is
important to further abstract away drawing from the ncurses objects. For
instance, fields could previously be drawn on subpads only but can now
be drawn on any surface. This is needed to create the file search
dialogs and similar functionalities.

There is an opportunity to refactor window drawing in general using
surfaces, but we shall consider this separately later.

Differential Revision: https://reviews.llvm.org/D107761
2021-08-17 16:54:41 -07:00
Shafik Yaghmour 0479afb3d6 [LLDB] Fix off by one logging placeholders in ClangASTSource::layoutRecordType()
D72391 Added some additional information to the logging but in this case instead of using
placeholder 2 and 3 they used 3 and 4.
2021-08-17 16:47:46 -07:00