Commit Graph

4901 Commits

Author SHA1 Message Date
Michał Górny bc125665c5 [lldb] [Host/freebsd] Set Arg0 for 'platform process list -v'
Same fix as in NetBSD (a6712889f5).

Differential Revision: https://reviews.llvm.org/D91026
2020-11-09 12:09:12 +01:00
Michał Górny 2384c4f971 Revert "[lldb] [Host/freebsd] Set Arg0 for 'platform process list -v'"
Accidentally referenced the wrong diff.

This reverts commit fce8e75889.
2020-11-09 12:09:12 +01:00
Georgii Rymar 62e3b2ec1d [lldb][test] - Update test cases after yaml2obj change.
The format of program header descriptions was changed by D90458.
2020-11-09 13:53:40 +03:00
Michał Górny afcdd43bf7 [llvm] [Support] Fix segv if argv0 is null in getMainExecutable()
When LLDB Python bindings are used and stack backtraces are enabled
for logging, getMainExecutable() is called with argv0 being null.
This caused the fallback function getprogpath() (used on FreeBSD, NetBSD
and Linux) to segfault.  Make it handle null executable name gracefully.

Differential Revision: https://reviews.llvm.org/D91012
2020-11-09 11:35:11 +01:00
Michał Górny fce8e75889 [lldb] [Host/freebsd] Set Arg0 for 'platform process list -v'
Same fix as in NetBSD (a6712889f5).

Differential Revision: https://reviews.llvm.org/D91012
2020-11-09 11:35:11 +01:00
Michał Górny 7e2ef84fe7 [lldb] [test] Extend watchpoint test to wait for thread to start
TestWatchpointMultipleThreads currently accounts for two scenarios:
setting the watchpoint before a new thread starts (presumably, verifying
that it will be propagated to the new thread) and setting it after
the thread starts (presumably, verifying that a new watchpoint is set
on all threads).  However, the latter test currently assumes that
the thread will be reported to the debugger before the breakpoint is
hit.  This is not the case on FreeBSD and NetBSD.

On NetBSD, new threads do not inherit debug registers from their parent
threads.  Instead, LLDB copies them manually after the new thread is
reported.  Since the thread is actually reported after the second
breakpoint location, both tests effectively check the same behavior
(i.e. watchpoint being set before the new thread is reported).

On FreeBSD, new threads inherit debug registers and we seem to hit
an interesting race condition.  While the thread is reported after
the breakpoint is hit, the kernel seems to construct it and copy
the debug register before that happens.  As a result, setting
the watchpoint at the second breakpoint location modifies the debug
registers of the first thread after they have been copied to the second
thread but before the debugger is aware of it.  Therefore,
the watchpoint is not propagated to the second thread and the test
fails.

Extend the test to cover all three possible scenarios: setting
watchpoint before the thread is lanched, after it is launched but before
it is guaranteed to have started and after it has actually started.  Add
a second barrier to account for the last case.  This should ensure that
the second assumption (i.e. that the watchpoint is set on all currently
known threads) is actually tested on FreeBSD and NetBSD.

Differential Revision: https://reviews.llvm.org/D91030
2020-11-09 11:35:11 +01:00
Michał Górny 9e1409aa1e [lldb] [Process/FreeBSDRemote] Handle exec() from inferior
Differential Revision: https://reviews.llvm.org/D90938
2020-11-09 11:35:11 +01:00
Jan Kratochvil 24f07531a3 [lldb] Fix DW_AT_decl_file from DW_AT_specification from a different CU
This would be reproducible in future DWZ category of the testsuite as:
  Failed Tests (1):
    lldb-api :: python_api/symbol-context/two-files/TestSymbolContextTwoFiles.py

Differential Revision: https://reviews.llvm.org/D91014
2020-11-09 10:52:48 +01:00
Michał Górny 93c9110c98 [lldb] [test] Use skipUnlessDarwin for tests specific to Darwin
Use skipUnlessDarwin decorator for tests that are specific to Darwin,
instead of skipIf... for all other platforms.  This should make it clear
that these tests are not supposed to work elsewhere.  It will also make
these tests stop repeatedly popping up while I look for tests that could
be fixed on the platform in question.

Differential Revision: https://reviews.llvm.org/D91003
2020-11-07 19:26:42 +01:00
Michał Górny 1ba9cedd0a [lldb] [test] Un-skip one of TestRaise signals on fbsd 2020-11-07 19:26:42 +01:00
Walter Erquinigo cfd96f057b [trace][intel-pt] Implement the basic decoding functionality
Depends on D89408.

This diff finally implements trace decoding!

The current interface is

  $ trace load /path/to/trace/session/file.json
  $ thread trace dump instructions

  thread #1: tid = 3842849, total instructions = 22
    [ 0] 0x40052d
    [ 1] 0x40052d
    ...
    [19] 0x400521

  $ # simply enter, which is a repeat command
    [20] 0x40052d
    [21] 0x400529
    ...

This doesn't do any disassembly, which will be done in the next diff.

Changes:
- Added an IntelPTDecoder class, that is a wrapper for libipt, which is the actual library that performs the decoding.
- Added TraceThreadDecoder class that decodes traces and memoizes the result to avoid repeating the decoding step.
- Added a DecodedThread class, which represents the output from decoding and that for the time being only stores the list of reconstructed instructions. Later it'll contain the function call hierarchy, which will enable reconstructing backtraces.
- Added basic APIs for accessing the trace in Trace.h:
  - GetInstructionCount, which counts the number of instructions traced for a given thread
  - IsTraceFailed, which returns an Error if decoding a thread failed
  - ForEachInstruction, which iterates on the instructions traced for a given thread, concealing the internal storage of threads, as plug-ins can decide to generate the instructions on the fly or to store them all in a vector, like I do.
- DumpTraceInstructions was updated to print the instructions or show an error message if decoding was impossible.
- Tests included

Differential Revision: https://reviews.llvm.org/D89283
2020-11-05 18:38:03 -08:00
Jonas Devlieghere 99a99c29c6 [lldb] Remove Crashlog/interactive.test
This test requires running under the Python we built against (which is
easy) and setting up the PYTHONPATH (which is not worth it for this
simple test).
2020-11-05 17:10:52 -08:00
Pedro Tammela ca17571051 [LLDB-lua] modify Lua's 'print' to respect 'io.stdout'
This patch changes the implementation of Lua's `print()` function to
respect `io.stdout`.

The original implementation uses `lua_writestring()` internally, which is
hardcoded to `stdout`.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D90787
2020-11-05 21:23:20 +00:00
Michał Górny 40140e122f [lldb] [Process/FreeBSDRemote] Remove thread name caching
Remove the thread name caching code.  It does not handle the possibility
of thread name changing between requests, therefore breaking
TestGdbRemoteThreadName.  While technically we could cache the results
and reset the cache on resuming process, the gain from doing that
does not seem worth the effort.

Differential Revision: https://reviews.llvm.org/D90863
2020-11-05 20:45:34 +01:00
Michał Górny b643deb03f [lldb] [test] Fix TestGdbRemoteThreadName code on FreeBSD
Fix TestGdbRemoteThreadName to call ::pthread_setname_np instead
of ::pthread_set_name_np on FreeBSD.  While technically both names
are correct, the former is preferable because of compatibility
with Linux.  Furthermore, the latter requires `#include <pthread_np.h>`
that was missing causing the test to fail to compile.

Differential Revision: https://reviews.llvm.org/D90862
2020-11-05 20:45:34 +01:00
Michał Górny 2c2eb5e670 [lldb] Enable FreeBSDRemote plugin by default and update test status
The new FreeBSDRemote plugin has reached feature parity on i386
and amd64 targets.  Use it by default on these architectures, while
allowing the use of the legacy plugin via FREEBSD_LEGACY_PLUGIN envvar.

Revisit the method of switching plugins.  Apparently, the return value
of PlatformFreeBSD::CanDebugProcess() is what really decides whether
the legacy or the new plugin is used.

Update the test status.  Reenable the tests that were previously
disabled on FreeBSD and do not cause hangs or are irrelevant to FreeBSD.
Mark all tests that fail reliably as expectedFailure.  For now, tests
that are flaky (i.e. produce unstable results) are left enabled
and cause unpredictable test failures.

Differential Revision: https://reviews.llvm.org/D90757
2020-11-05 17:49:46 +01:00
Michał Górny 6ba2c2bf90 [lldb] [test/Shell] Simplify -pthread condition
Pass -pthread on all systems except for Darwin and Windows.
Suggested by Pavel Labath.
2020-11-05 17:49:20 +01:00
Raphael Isemann 239f488fd6 [lldb] Skip TestChangeProcessGroup on watchOS/tvOS
`fork` is marked as `__WATCHOS_PROHIBITED __TVOS_PROHIBITED` so the test source
which is calling fork will never compile on watchOS/tvOS. This just adds the
skip decorator for these platforms.

Reviewed By: mib

Differential Revision: https://reviews.llvm.org/D89695
2020-11-05 15:11:30 +01:00
Raphael Isemann 2f84b59a4c [lldb] Also Catch invalid calls to TestPExpectTest's expect()
This is a follow up to D88792 which found an issue in a call to PExpectTest's
expect function that allows passing a string to the `substrs` parameter. However
this issue was found by just grepping and TestPExpect's expect function is still
accepting a single string as a value to `substrs`.

This patch adds the same sanity check that D88792 added to the PExpectTest's
implementation of `expect` and also adds a small test for it.

Reviewed By: kastiglione, JDevlieghere

Differential Revision: https://reviews.llvm.org/D89302
2020-11-05 14:08:46 +01:00
Michał Górny 98257c3006 [lldb] [test] Update XFAILs/skips for FreeBSD
Update expected failures and test skips based on common results
for the old and new FreeBSD plugins.
2020-11-03 22:01:59 +01:00
Michał Górny 051da2bede [lldb] [test/Shell] Pass -pthread to host toolchain on FreeBSD too 2020-11-03 22:01:59 +01:00
Michał Górny b7de7be098 [lldb] [test] Remove xfail from tests that pass on FreeBSD 2020-11-03 22:01:59 +01:00
Andy Yankovsky f35a82384d Return actual type from SBType::GetArrayElementType
SBType::GetArrayElementType should return the actual type, not the
canonical type (e.g. int32_t, not the underlying int).

Added a test case to validate the new behavior. I also ran all other
tests on Linux (ninja check-lldb), they all pass.

Differential revision: https://reviews.llvm.org/D90318
2020-11-03 10:53:44 -08:00
Jonas Devlieghere 4b84682044 [crashlog] Move crash log parsing into its own class
Move crash log parsing out of the CrashLog class and into its own class
and add more tests.

Differential revision: https://reviews.llvm.org/D90664
2020-11-03 09:04:35 -08:00
Pavel Labath 1695c8420a [lldb] Generalize an deflake gdb-remote *client* tests
This is similar in spirit to what D90313 did for server tests.
2020-11-02 16:34:25 +01:00
Pavel Labath e3645fdff4 [lldb/test] Fix a fragile assumption in TestTypeGetModule
the binary can contain more than three compile units if the compiler
support files (crtbegin/end, etc.) come with their own debug info.
2020-11-02 15:42:14 +01:00
Ilya Bukonkin 1267bb2e41 [lldb] TestTypeGetModule.py review improvements 2020-11-01 13:55:57 +03:00
Joseph Tremoulet d20aa7ca42 [lldb] Report old modules from ModuleList::ReplaceEquivalent
This allows the Target to update its module list when loading a shared
module replaces an equivalent one.

A testcase is added which hits this codepath -- without the fix, the
target reports libbreakpad.so twice in its module list.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D89157
2020-10-30 15:14:32 -04:00
Jan Kratochvil a136699b2a [nfc] [lldb] Align `user_id_t` format to the current `DIERef` format
Current user_id_t format is:
        63{isDebugTypes} 62..32{dwo || 7fffffff}
        31..0 {die_offset}
while current DIERef format is (I have made up the bit positions but the
field widths do match):
        63{m_section==isDebugTypes} 62{m_dwo_num_valid} 61..32{m_dwo_num}
        31..0 {m_die_offset}

Proposing to change user_id_t to:
        63{isDebugTypes} 62{dwo_is_valid} 61..32{dwo; 0 if !valid}
        31..0 {die_offset}

There is no benefit of having 31-bits wide dwo_num in user_id_t when it
gets converted to 30-bits width in DIERef.

This patch is for future DWZ patchset which extends the dwo_is_valid bit
into a 2-bit field (normal, DWO, DWZ, DWZcommon) so that both user_id_t
and DIERef can be changed then the same way.

It would be best to somehow unify user_id_t and DIERef but I do not plan
to do that. user_id_t should probably remain a number for the Python API
compatibility while there still needs to be some class with all the
methods to access it.

SymbolFileDWARF::GetDwpSymbolFile() and SymbolFileDWARF::GetDIE use
0x3fffffff for DWP but that does not clash:

formerly:
  31bits32..62:0x7fffffff = normal unit / not any DWO
  31bits32..62:0x3fffffff = DWP
  31bits32..62:others = DWO unit number

after this patch:
  bit62=0 30bits32..61:any = normal unit / not any DWO
  bit62=1 30bits32..61:0x3fffffff = DWP
  bit62=1 30bits32..61:others = DWO unit number

Differential Revision: https://reviews.llvm.org/D90413
2020-10-30 16:50:52 +01:00
Pavel Labath 8485ee781f [lldb/DWARF] Fix dwo flavour of TestTypeGetModule
SymbolFileDWARF::GetTypes was not handling dwo correctly. The fix is
simple -- adding a GetNonSkeletonUnit call -- but I've snuck in a small
refactor as well.
2020-10-30 15:20:27 +01:00
Pavel Labath 62286c569d [lldb/test] Remove a double debugserver launch in TestGdbRemoteGPacket
Debug server is already launched by prep_debug_monitor_and_inferior. The
second seems to have been benign so far, but after 8cc49bec2 this test
started failing frequently on GreenDragon, and this is the only unusual
thing about it.
2020-10-30 14:27:50 +01:00
Jonas Devlieghere 30e7df0d58 [lldb] XFAIL TestTypeGetModule.py (temporarily)
Temporarily XFAIL'ing TestTypeGetModule.py while the DWO failure is
being investigated.
2020-10-29 18:37:46 -07:00
Ilya Bukonkin 56282cf7e2 [lldb] Update TestTypeGetModule.py
Differential revision: https://reviews.llvm.org/D88483
2020-10-29 18:28:57 -07:00
Jim Ingham 32a85b268a This is a preliminary version of the test for https://reviews.llvm.org/D88483.
The test can be cleaned up a bit, but this should be good to see why the
Debian bot is failing...
2020-10-29 16:39:35 -07:00
Jim Ingham fa5a132767 Provide a reasonable value for PATH_MAX if the lldb headers don't provide it. 2020-10-29 15:02:51 -07:00
Jim Ingham a37672e2db Mark the execution of stop-hooks as non-interactive.
The intention is not to allow stop-hook commands to query the
user, so this is correct.  It also works around a deadlock in
switching to the Python Session to execute python based commands
in the stop hook when the Debugger stdin is backed by a FILE *.

Differential Revision: https://reviews.llvm.org/D90332
2020-10-29 14:41:53 -07:00
Ilya Bukonkin 2c0cbc47ca GetModule, GetExeModule methods added 2020-10-29 23:44:51 +03:00
Pavel Labath 8cc49bec2e [lldb] Use reverse connection method for lldb-server tests
This fixes an flakyness is all gdb-remote tests. These tests have been
(mildly) flaky since we started using "localhost" instead of 127.0.0.1
in the test suite. The reason is that lldb-server needs to create two
sockets (v4 and v6) to listen for localhost connections. The algorithm
it uses first tries to select a random port (bind(localhost:0)) for the
first address, and then bind the same port for the second one.

The creating of the second socket can fail as there's no guarantee that
port will be available -- it seems that the (linux) kernel tries to
choose an unused port for the first socket (I've had to create thousands
of sockets to reproduce this reliably), but this can apparantly fail
when the system is under load (and our test suite creates a _lot_ of
sockets).

The socket creationg operation is considered successful if it creates at
least one socket is created, but the test harness has no way of knowing
which one it is, so it can end up connecting to the wrong address.

I'm not aware of a way to atomically create two sockets bound to the
same port. One way to fix this would be to make lldb-server report the
address is it listening on instead of just the port. However, this would
be a breaking change and it's not clear to me that's worth it (the
algorithm works pretty well under normal circumstances).

Instead, this patch sidesteps that problem by using "reverse"
connections. This way, the test harness is responsible for creating the
listening socket so it can pass the address that it has managed to open.
It also results in much simpler code overall.

To preserve test coverage for the named pipe method, I've moved the
relevant code to a dedicated test. To avoid original problem, this test
passes raw addresses (as obtained by getaddrinfo(localhost)) instead of
"localhost".

Differential Revision: https://reviews.llvm.org/D90313
2020-10-29 13:49:51 +01:00
Jonas Devlieghere 00bb397b0d [lldb] Support Python imports relative the to the current file being sourced
Make it possible to use a relative path in command script import to the
location of the file being sourced. This allows the user to put Python
scripts next to LLDB command files and importing them without having to
specify an absolute path.

To enable this behavior pass `-c` to `command script import`. The
argument can only be used when sourcing the command from a file.

rdar://68310384

Differential revision: https://reviews.llvm.org/D89334
2020-10-27 09:20:45 -07:00
Raphael Isemann d43c70a202 [lldb] Add llvm-pdbutil to lldb test dependencies
Since D89812 we use llvm-pdbutil in the LLDB tests but we didn't add it to
the test dependencies.
2020-10-27 15:46:25 +01:00
Michał Górny 8e7ea99c38 [lldb] [Process/FreeBSDRemote] Enable watchpoint support
Replace the inline x86 watchpoint handling code with the reusable
NativeRegisterContextWatchpoint_x86.  Implement watchpoint support
in NativeThreadFreeBSD and SIGTRAP handling for watchpoints.

Un-skip all concurrent_events tests as they pass with the new plugin.

Differential Revision: https://reviews.llvm.org/D90102
2020-10-27 15:38:00 +01:00
Raphael Isemann 1f933ff999 [lldb][NFC] Rewrite TestQuoting
TestQuoting's different test methods all build their own test binaries but
we can just reuse the same test binary by merging all asserts into one method.
This reduces the test runtime from 8 seconds to 4 seconds on my machine.
This also removes the ability to have partial failures in this test, but given
how rarely this code is touched this seems like a fair tradeoff (and we will be
able to re-add this feature once we updated our test framework).

Some other small changes:
  * Fixed that we cleanup "stdout.txt" instead of "output.txt" in the cleanup.
  * Fixed some formatting issues.
  * Call `build` instead of directly calling `buildDefault`.
2020-10-27 11:12:17 +01:00
Zequan Wu 779deb9750 [lldb][NativePDB] fix test load-pdb.cpp 2020-10-26 17:12:51 -07:00
Sriraman Tallam 9aa7a721ce Test to check backtraces with machine function splitting.
clang supports option -fsplit-machine-functions and this test checks if the
backtraces are sane when functions are split.

With -fsplit-machine-functions, a function with profiles can get split into 2
parts, the original function containing hot code and a cold part as determined
by the profile info and the cold cutoff threshold.. The cold part gets the
".cold" suffix to disambiguate its symbol from the hot part and can be placed
arbitrarily in the address space.

This test checks if the back-trace looks correct when the cold part is executed.

Differential Revision: https://reviews.llvm.org/D90081
2020-10-26 14:08:42 -07:00
Zequan Wu 4b83747ab1 [lldb][NativePDB] fix test load-pdb.cpp 2020-10-26 11:38:12 -07:00
Zequan Wu 242e1e9910 [lldb][PDB] Add ObjectFile PDB plugin
To allow loading PDB file with `target symbols add` command.

Differential Revision: https://reviews.llvm.org/D89812
2020-10-26 10:28:48 -07:00
Andy Yankovsky 206e8d8905 Fix SBError::SetErrorToGenericError
`SBError::SetErrorToGenericError` should call `Status::SetErrorToGenericError`,
not `Status::SetErrorToErrno`.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D90151
2020-10-26 15:44:38 +01:00
Pavel Labath 97ca9ca180 [lldb] Fix bitfield "frame var" for pointers (pr47743)
Displaying large packed bitfields did not work if one was accessing them
through a pointer, and he used the "->" notation ("[0]." notation is
fine). The reason for that is that implicit dereference in -> is plumbed
all the way down to ValueObjectChild::UpdateValue, where the process of
fetching the child value was forked for this flag. The bitfield
"sliding" code was implemented only for the branch which did not require
dereferencing.

This patch restructures the function to avoid this mistake. Processing
now happens in two stages.
- first the parent is dereferenced (if needed)
- then the child value is computed (this step includes sliding and is
  common for both branches)

Differential Revision: https://reviews.llvm.org/D89236
2020-10-26 12:01:20 +01:00
Michał Górny 37d4d3bb4d [lldb] [test/Register] Use initial state for write tests
Reset registers to their 'initial' state instead of a semi-random
pattern in write tests.  While the latter might have been helpful
while debugging failures (i.e. to distinguish unmodified registers
from mistakenly written zeroes), the former makes it possible to test
whether xstate_bv field is written correctly when using XSAVE.

With this change, the four relevant tests start failing on NetBSD
without D90105.

Differential Revision: https://reviews.llvm.org/D90114
2020-10-26 11:54:00 +01:00
Jonas Devlieghere 73811d32c7 [lldb] Move copying of files into reproducer out of process
For performance reasons the reproducers don't copy the files captured by
the file collector eagerly, but wait until the reproducer needs to be
generated.

This is a problematic when LLDB crashes and we have to do all this
signal-unsafe work in the signal handler. This patch uses a similar
trick to clang, which has the driver invoke a new cc1 instance to do all
this work out-of-process.

This patch moves the writing of the mapping file as well as copying over
the reproducers into a separate process spawned when lldb crashes.

Differential revision: https://reviews.llvm.org/D89600
2020-10-23 12:33:54 -07:00
Jonas Devlieghere 826997c462 [lldb] Fix a regression introduced by D75730
In a new Range class was introduced to simplify and the Disassembler API
and reduce duplication. It unintentionally broke the
SBFrame::Disassemble functionality because it unconditionally converts
the number of instructions to a Range{Limit::Instructions,
num_instructions}. This is subtly different from the previous behavior,
where now we're passing a Range and assume it's valid in the callee, the
original code would propagate num_instructions and the callee would
compare the value and decided between disassembling instructions or
bytes.

Unfortunately the existing tests was not particularly strict:

  disassembly = frame.Disassemble()
  self.assertNotEqual(len(disassembly), 0, "Disassembly was empty.")

This would pass because without this patch we'd disassemble zero
instructions, resulting in an error:

  (lldb) script print(lldb.frame.Disassemble())
  error: error reading data from section __text

Differential revision: https://reviews.llvm.org/D89925
2020-10-22 08:38:03 -07:00
Raphael Isemann 30d5590d17 [lldb] Fix TestTargetAPI.py on Apple simulators
This test checks that the output of `SBTarget.GetDescription()` contains the
substrings `'a.out', 'Target', 'Module', 'Breakpoint'` in that order. This test
is currently failing on Apple simulators as apparently 'Module' can't be found
in the output after 'Target".

The reason for that is that the actual output of `SBTarget.GetDescription()` looks like this:
```
Target
  Module /build/path/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_description_dwarf/a.out
0x7ff2b6d3f990:     ObjectFileMachO64, file = /build/path/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_description
[...]
0x7ff307150000:   BreakpointList with 0 Breakpoints:
<LLDB module output repeats for each loaded module>
```

Clearly the string order should be `'Target', 'Module', 'a.out', 'Breakpoint'`.
However, LLDB is also a bunch of system shared libraries (libxpc.dylib,
libobjc.A.dylib, etc.) when *not* running against a simulator, we end up
unintentionally finding the `'Target', 'Module', 'Breakpoint'` substrings in the
trailing descriptions of the system modules. When running against a simulator we
however don't load shared system libraries.

This patch just moves the substrings in the correct order to make this test pass
without having any shared library modules in the description output.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D89698
2020-10-22 16:41:54 +02:00
Pavel Labath fa5fa63fd1 [lldb] Port lldb gdb-server to libOption
The existing help text was very terse and was missing several important
options. In the new version, I add a short description of each option
and a slightly longer description of the tool as a whole.

The new option list does not include undocumented no-op options:
--debug and --verbose. It also does not include undocumented short
aliases for long options, with two exceptions: -h, because it's
well-known; and -S (--setsid), as it's used in one test. Using these
options will now produce an error. I believe that is acceptable as users
aren't generally invoking lldb-server directly, and the only way to
learn about the short aliases was by looking at the source.

Differential Revision: https://reviews.llvm.org/D89477
2020-10-21 16:16:18 +02:00
Pavel Labath dfb2266328 [lldb] Make DW_AT_declaration-with-children.s test more realistic
(Re)add DW_AT_specification and DW_AT_object_pointer attributes. These
were removed in fa89f641c, as they were bogus due to bad test case
reduction.
2020-10-19 10:34:13 +02:00
Jan Kratochvil fa89f641cf [nfc] [lldb] [testsuite] Fix DW_FORM_ref* in DW_AT_declaration-with-children.s .
There were invalid DIE references which nobody used. If LLDB starts to
report invalid DIE references it would lock up (mutex lock).

These invalid DIE references are there since initial check-in by:
  https://reviews.llvm.org/D83302
2020-10-18 16:57:27 +02:00
Sriraman Tallam 2e5b701d93 This test includes a source that will produce basic blocks and hence sections with -fbasic-block-sections=all.
The test reorders the basic blocks to be dis-contiguous in the address space and checks if the back trace contains the right symbol.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D89179
2020-10-16 21:31:42 -07:00
Joseph Tremoulet d30797b404 [lldb] Minidump: check for .text hash match with directory
When opening a minidump, we might discover that it reports a UUID for a
module that doesn't match the build ID, but rather a hash of the .text
section (according to either of two different hash functions, used by
breakpad and Facebook respectively).  The current logic searches for a
module by filename only to check the hash; this change updates it to
first search by directory+filename.  This is important when the
directory specified in the minidump must be interpreted relative to a
user-provided sysoort, as the leaf directory won't be in the search path
in that case.

Also add a regression test; without this change, module validation fails
because we have just the placeholder module which reports as its path
the platform path in the minidump.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D89155
2020-10-16 09:32:08 -04:00
Jim Ingham 6754caa9bf Add an SB API to get the SBTarget from an SBBreakpoint
Differential Revision: https://reviews.llvm.org/D89358
2020-10-15 14:28:44 -07:00
Raphael Isemann 82ed18601d [lldb] Explicitly test the template argument SB API 2020-10-15 11:17:43 +02:00
Pavel Labath a1ab2b773b [lldb] More memory allocation test fixes
XFAIL nodefaultlib.cpp on darwin - the test does not pass there

XFAIL TestGdbRemoteMemoryAllocation on windows - memory is allocated
with incorrect permissions
2020-10-14 20:43:47 +02:00
Pavel Labath 36f22cd28d [lldb] Fix TestGdbRemoteMemoryAllocation on windows
It appears that memory allocation actually works on windows (but it was
not fully wired up before 2c4226f8).
2020-10-14 16:46:10 +02:00
Pavel Labath 2c4226f8ac [lldb-server][linux] Add ability to allocate memory
This patch adds support for the _M and _m gdb-remote packets, which
(de)allocate memory in the inferior. This works by "injecting" a
m(un)map syscall into the inferior. This consists of:
- finding an executable page of memory
- writing the syscall opcode to it
- setting up registers according to the os syscall convention
- single stepping over the syscall

The advantage of this approach over calling the mmap function is that
this works even in case the mmap function is buggy or unavailable. The
disadvantage is it is more platform-dependent, which is why this patch
only works on X86 (_32 and _64) right now. Adding support for other
linux architectures should be easy and consist of defining the
appropriate syscall constants. Adding support for other OSes depends on
the its ability to do a similar trick.

Differential Revision: https://reviews.llvm.org/D89124
2020-10-14 15:02:09 +02:00
Michał Górny caedbc317a [lldb] [test/Register] Add read/write tests for multithreaded process
Add a test to verify that 'register read' and 'register write' commands
work correctly in a multithreaded program, in particular that they read
or write registers for the correct thread.  The tests use locking
to ensure that events are serialized and the test can execute reliably.

Differential Revision: https://reviews.llvm.org/D89248
2020-10-14 11:08:36 +02:00
Raphael Isemann cb81e662a5 [lldb] Reject redefinitions of persistent variables
Currently one can redefine a persistent variable and LLDB will just silently
ignore the second definition:

```
(lldb) expr int $i = 1
(lldb) expr int $i = 2
(lldb) expr $i
(int) $i = 1
```

This patch makes this an error and rejects the expression with the second
definition.

A nice follow up would be to refactor LLDB's persistent variables to not just be
a pair of type and name, but also contain some way to obtain the original
declaration and source code that declared the variable. That way we could
actually make a full diagnostic as we would get from redefining a variable twice
in the same expression.

Reviewed By: labath, shafik, JDevlieghere

Differential Revision: https://reviews.llvm.org/D89310
2020-10-14 10:24:35 +02:00
Raphael Isemann 02114e15da [lldb] Allow limiting the number of error diagnostics when parsing an expression
While debugging another bug I found out that we currently don't set any limit
for the number of diagnostics Clang emits. If a user does something that
generates a lot of errors (like including some long header file from within the
expression function), then we currently spam the LLDB output with potentially
thousands of Clang error diagnostics.

Clang sets a default limit of 20 errors, but given that LLDB is often used
interactively for small expressions I would say a limit of 5 is enough. The
limit is implemented as a setting, so if a user cares about seeing having a
million errors printed to their terminal then they can just increase the
settings value.

Reviewed By: shafik, mib

Differential Revision: https://reviews.llvm.org/D88889
2020-10-13 17:12:43 +02:00
Raphael Isemann ef733d9df4 [lldb] Add targets for running test suite against Watch/TV/iPhone simulators
This patch adds several build system targets that run the normal test suite but
against the Watch/TV/iPhone simulators.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D89224
2020-10-13 17:07:46 +02:00
Dave Lee a52cc9b4be [lldb] Handle alternative output in TestAbortExitCode
This test

On macOS, this test can instead return `status = 0 (0x00000000) Terminated due to signal 6`. This updates the `CHECK` accordingly.

Differential Revision: https://reviews.llvm.org/D89273
2020-10-12 16:27:06 -07:00
Jonas Devlieghere 360ab009e2 [lldb] Add instrumentation runtime category 2020-10-12 16:02:40 -07:00
Walter Erquinigo 26d861cbbd [trace] Scaffold "thread trace dump instructions"
Depends on D88841

As per the discussion in the RFC, we'll implement both

  thread trace dump [instructions | functions]

This is the first step in implementing the "instructions" dumping command.

It includes:

- A minimal ProcessTrace plugin for representing processes from a trace file. I noticed that it was a required step to mimic how core-based processes are initialized, e.g. ProcessElfCore and ProcessMinidump. I haven't had the need to create ThreadTrace yet, though. So far HistoryThread seems good enough.
- The command handling itself in CommandObjectThread, which outputs a placeholder text instead of the actual instructions. I'll do that part in the next diff.
- Tests

{F13132325}

Differential Revision: https://reviews.llvm.org/D88769
2020-10-12 12:08:18 -07:00
Walter Erquinigo ea1f49741e [intel pt] Refactor parsing
With the feedback I was getting in different diffs, I realized that splitting the parsing logic into two classes was not easy to deal with. I do see value in doing that, but I'd rather leave that as a refactor after most of the intel-pt logic is in place. Thus, I'm merging the common parser into the intel pt one, having thus only one that is fully aware of Intel PT during parsing and object creation.

Besides, based on the feedback in https://reviews.llvm.org/D88769, I'm creating a ThreadIntelPT class that will be able to orchestrate decoding of its own trace and can handle the stop events correctly.

This leaves the TraceIntelPT class as an initialization class that glues together different components. Right now it can initialize a trace session from a json file, and in the future will be able to initialize a trace session from a live process.

Besides, I'm renaming SettingsParser to SessionParser, which I think is a better name, as the json object represents a trace session of possibly many processes.

With the current set of targets, we have the following

- Trace: main interface for dealing with trace sessions
- TraceIntelPT: plugin Trace for dealing with intel pt sessions
- TraceIntelPTSessionParser: a parser of a json trace session file that can create a corresponding TraceIntelPT instance along with Targets, ProcessTraces (to be created in https://reviews.llvm.org/D88769), and ThreadIntelPT threads.
- ProcessTrace: (to be created in https://reviews.llvm.org/D88769) can handle the correct state of the traces as the user traverses the trace. I don't think there'll be a need an intel-pt specific implementation of this class.
- ThreadIntelPT: a thread implementation that can handle the decoding of its own trace file, along with keeping track of the current position the user is looking at when doing reverse debugging.

Differential Revision: https://reviews.llvm.org/D88841
2020-10-09 17:32:04 -07:00
Pavel Labath 19d64138e6 [lldb] Fix "frame var" for large bitfields
The problem here is in the "sliding" code in
ValueObjectChild::UpdateValue. It modifies m_bitfield_bit_offset and
m_value to ensure the bitfield value fits the window given by the
underlying type.

However, this is broken next time UpdateValue is called, because it
updates the m_value value from the parent. However, the value cannot be
slid again because the m_bitfield_bit_offset is already modified.

It seems this can happen only under specific circumstances. One way to
trigger is is to run an expression which can be interpreted (jitting it
causes a new StackFrame and ValueObject variables to be created).

I fix this bug by modifying m_byte_offset instead of m_scalar, and
ensuring the changes are folded into m_scalar regardless of how many
times UpdateValue is called.

Differential Revision: https://reviews.llvm.org/D88992
2020-10-08 18:42:50 +02:00
Alexandre Ganea 79809f58b0 [LLDB] On Windows, fix tests
This patch fixes a few issues seen when running `ninja check-lldb` in a Release build with VS2017:

- Some binaries couldn't be found (such as lldb-vscode.exe), because .exe wasn't appended to the file name.
- Many tests used to fail since our installed locale is in French - the OS error messages are not emitted in English.
- Our codepage being Windows-1252, python failed to decode some error messages with accentuations.

Differential Revision: https://reviews.llvm.org/D88975
2020-10-08 11:46:59 -04:00
Michał Górny 1a600266c3 [lldb] Initial version of FreeBSD remote process plugin
Add a new FreeBSD Process plugin using client/server model.  This plugin
is based on the one used by NetBSD.  It currently supports a subset
of functionality for amd64.  It is automatically used when spawning
lldb-server.  It can also be used by lldb client by setting
FREEBSD_REMOTE_PLUGIN environment variable (to any value).

The code is capable of debugging simple single-threaded programs.  It
supports general purpose, debug and FPU registers (up to XMM) of amd64,
basic signalling, software breakpoints.

Adding the support for the plugin involves removing some dead code
from FreeBSDPlatform plugin (that was not ever used because
CanDebugProcess() returned false), and replacing it with appropriate
code from NetBSD platform support.

Differential Revision: https://reviews.llvm.org/D88796
2020-10-08 16:03:00 +02:00
Jim Ingham be66987e20 Fix raciness in the StopHook check for "has the target run".
This was looking at the privateState, but it's possible that
the actual process has started up and then stopped again by the
time we get to the check, which would lead us to get out of running
the stop hooks too early.

Instead we need to track the intention of the stop hooks directly.

Differential Revision: https://reviews.llvm.org/D88753
2020-10-05 15:44:28 -07:00
Dave Lee 010d7a388b [lldb/test] Catch invalid calls to expect()
Add preconditions to `TestBase.expect()` that catch semantically invalid calls
that happen to succeed anyway. This also fixes the broken callsites caught by
these checks.

This prevents the following incorrect calls:

1. `self.expect("lldb command", "some substr")`
2. `self.expect("lldb command", "assert message", "some substr")`

Differential Revision: https://reviews.llvm.org/D88792
2020-10-05 12:41:52 -07:00
David Spickett 71cf97e95b Reland "[lldb] Don't send invalid region addresses to lldb server"
This reverts commit c65627a1fe.

The test immediately after the new invalid symbol test was
failing on Windows. This was because when we called
VirtualQueryEx to get the region info for 0x0,
even if it succeeded we would call GetLastError.

Which must have picked up the last error that was set while
trying to lookup "not_an_address". Which happened to be 2.
("The system cannot find the file specified.")

To fix this only call GetLastError when we know VirtualQueryEx
has failed. (when it returns 0, which we were also checking for anyway)

Also convert memory region to an early return style
to make the logic clearer.

Reviewed By: labath, stella.stamenova

Differential Revision: https://reviews.llvm.org/D88229
2020-10-05 11:50:29 +01:00
Michał Górny e8beb6988b [lldb] [test/Register] Attempt to fix x86-fp-read.test on Darwin
Darwin seems to use stmmN instead of stN. Use a regex to accept both.

Also try to actually clear st(7).

Differential revision: https://reviews.llvm.org/D88795
2020-10-04 23:04:40 -07:00
Jonas Devlieghere 0f08a1a5b1 [lldb] [test/Register] Mark new FP reg tests XFAIL on Darwin
This is failing on GreenDragon:
http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24066/
2020-10-03 22:36:28 -07:00
Michał Górny 508ac0ec13 [lldb] [test/Register] Mark new FP reg tests XFAIL on Windows 2020-10-03 22:16:29 +02:00
Michał Górny 381bdc75ee [lldb] [test/Register] Add read/write tests for x87 regs
Add a partial read/write tests for x87 FPU registers.  This includes
reading and writing ST registers, control registers and floating-point
exception data registers (fop, fip, fdp).

The tests assume the current (roughly incorrect) behavior of reporting
the 'abridged' 8-bit ftag state as 16-bit ftag.  They also assume Linux
plugin behavior of reporting fip/fdp split into halves as (fiseg, fioff)
and (foseg, fooff).

Differential Revision: https://reviews.llvm.org/D88583
2020-10-03 19:54:38 +02:00
Raphael Isemann 15ea45f16b [lldb] Skip unique_ptr import-std-module tests on Linux
This seems to fail on ubuntu 18.04.5 with Clang 9 due to:

Error output:
error: Couldn't lookup symbols:
  std::__1::default_delete<int>::operator()(int) const
2020-10-01 23:04:36 +02:00
Raphael Isemann cccb7cf1a5 [lldb] Add missing import for LLDB test decorators to TestStopHookScripted
This test wasn't using decorators before and was missing the import, so my
previous commit broke the test.
2020-10-01 14:33:13 +02:00
Raphael Isemann b272250221 [lldb] Skip the flakey part of TestStopHookScripted on Linux
This test seems to randomly fail on Linux machines. It's only one part of the
test failing randomly, so let's just skip it instead of reverting the whole
patch (again).
2020-10-01 14:24:38 +02:00
Muhammad Omair Javaid 3d27a99b2e [LLDB] Remove AArch64/Linux xfail decorator from TestGuiBasicDebug
This test now passes on AArch64/Linux after following change by Jonas:
d689570d7d
2020-10-01 10:20:22 +05:00
Jonas Devlieghere d689570d7d [lldb] Make TestGuiBasicDebug more lenient
Matt's change to the register allocator in 89baeaef2f changed where we
end up after the `finish`. Before we'd end up on line 4.

* thread #1, queue = 'com.apple.main-thread', stop reason = step out
Return value: (int) $0 = 1
    frame #0: 0x0000000100003f7d a.out`main(argc=1, argv=0x00007ffeefbff630) at main.c:4:3
   1    extern int func();
   2
   3    int main(int argc, char **argv) {
-> 4      func(); // Break here
   5      func(); // Second
   6      return 0;
   7    }

Now, we end up on line 5.

* thread #1, queue = 'com.apple.main-thread', stop reason = step out
Return value: (int) $0 = 1

    frame #0: 0x0000000100003f8d a.out`main(argc=1, argv=0x00007ffeefbff630) at main.c:5:3
   2
   3    int main(int argc, char **argv) {
   4      func(); // Break here
-> 5      func(); // Second
   6      return 0;
   7    }

Given that this is not expected stable to be stable I've made the test a
bit more lenient to accept both scenarios.
2020-09-30 17:06:47 -07:00
Jim Ingham afaeb6af79 Fix crash in SBStructuredData::GetDescription() when there's no StructuredDataPlugin.
Also, use the StructuredData::Dump method to print the StructuredData if there
is no plugin, rather than just returning an error.

Differential Revision: https://reviews.llvm.org/D88266
2020-09-30 11:48:54 -07:00
Jordan Rupprecht ad865d9d10 [lldb-vscode] Allow an empty 'breakpoints' field to clear breakpoints.
Per the DAP spec for SetBreakpoints [1], the way to clear breakpoints is: `To clear all breakpoint for a source, specify an empty array.`

However, leaving the breakpoints field unset is also a well formed request (note the `breakpoints?:` in the `SetBreakpointsArguments` definition). If it's unset, we have a couple choices:

1. Crash (current behavior)
2. Clear breakpoints
3. Return an error response that the breakpoints field is missing.

I propose we do (2) instead of (1), and treat an unset breakpoints field the same as an empty breakpoints field.

[1] https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetBreakpoints

Reviewed By: wallace, labath

Differential Revision: https://reviews.llvm.org/D88513
2020-09-30 11:32:06 -07:00
Jordan Rupprecht c3193e464c [lldb/ipv6] Support running lldb tests in an ipv6-only environment.
When running in an ipv6-only environment where `AF_INET` sockets are not available, many lldb tests (mostly gdb remote tests) fail because things like `127.0.0.1` don't work there.

Use `localhost` instead of `127.0.0.1` whenever possible, or include a fallback of creating `AF_INET6` sockets when `AF_INET` fails.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D87333
2020-09-30 11:08:41 -07:00
Matt Arsenault 89baeaef2f Reapply "RegAllocFast: Rewrite and improve"
This reverts commit 73a6a164b8.
2020-09-30 10:35:25 -04:00
Jonas Devlieghere 154860af33 [lldb] Use config.lldb_src_root in lit_config.load_config (NFC)
Rather than relaying on CMake to substitute the full path to the lldb
source root, use the  value set in config.lldb_src_root. This makes it
slightly easier to write a custom lit.site.cfg.py.
2020-09-29 23:05:12 -07:00
Jonas Devlieghere bd14d6ea15 [lldb] Hoist -s (trace directory) argument out of LLDB_TEST_COMMON_ARGS (NFC)
Give the trace directory argument its own variable
(LLDB_TEST_TRACE_DIRECTORY) so that we can configure it in
lit.site.cfg.py if we so desire.
2020-09-29 17:23:33 -07:00
Jonas Devlieghere 3c7070f1a6 [lldb] Hoist --server argument out of LLDB_TEST_COMMON_ARGS (NFC)
Give the server argument its own variable (LLDB_TEST_SERVER) so that we
can configure it in lit.site.cfg.py if we so desire.
2020-09-29 13:27:29 -07:00
Jim Ingham 1b1d981598 Revert "Revert "Add the ability to write target stop-hooks using the ScriptInterpreter.""
This reverts commit f775fe5964.

I fixed a return type error in the original patch that was causing a test failure.
Also added a REQUIRES: python to the shell test so we'll skip this for
people who build lldb w/o Python.
Also added another test for the error printing.
2020-09-29 12:01:14 -07:00
Jonas Devlieghere ccbb9827db [lldb] Also configure lldb_framework_dir in the lit.site.cfg.py
Configuring the variable in CMake isn't enought, because the build mode
can't be resolved until execution time, which requires the build mode to
be substituted by lit.
2020-09-29 09:13:26 -07:00
Jonas Devlieghere d0ed45dc92 [lldb] Configure LLDB_FRAMEWORK_DIR in multi-generator builds 2020-09-29 08:56:31 -07:00
Jonas Devlieghere f775fe5964 Revert "Add the ability to write target stop-hooks using the ScriptInterpreter."
This temporarily reverts commit b65966cff6
while Jim figures out why the test is failing on the bots.
2020-09-28 09:04:32 -07:00
Raphael Isemann cabee89bed [lldb] Reference STL types in import-std-module tests
With the recent patches to the ASTImporter that improve template type importing
(D87444), most of the import-std-module tests can now finally import the
type of the STL container they are testing. This patch removes most of the casts
that were added to simplify types to something the ASTImporter can import
(for example, std::vector<int>::size_type was casted to `size_t` until now).
Also adds the missing tests that require referencing the container type (for
example simply printing the whole container) as here we couldn't use a casting
workaround.

The only casts that remain are in the forward_list tests that reference
the iterator and the stack test. Both tests are still failing to import the
respective container type correctly (or crash while trying to import).
2020-09-28 10:37:03 +02:00
Raphael Isemann 070a1d562b [lldb] Remove nothreadallow from SWIG's __str__ wrappers to work around a Python>=3.7 crash
Usually when we enter a SWIG wrapper function from Python, SWIG automatically
adds a `Py_BEGIN_ALLOW_THREADS`/`Py_END_ALLOW_THREADS` around the call to the SB
API C++ function. This will ensure that Python's GIL is released when we enter
LLDB and locked again when we return to the wrapper code.

D51569 changed this behaviour but only for the generated `__str__` wrappers. The
added `nothreadallow` disables the injection of the GIL release/re-acquire code
and the GIL is now kept locked when entering LLDB and is expected to be still
locked when returning from the LLDB implementation. The main reason for that was
that back when D51569 landed the wrapper itself created a Python string. These
days it just creates a std::string and SWIG itself takes care of getting the GIL
and creating the Python string from the std::string, so that workaround isn't
necessary anymore.

This patch just removes `nothreadallow` so that our `__str__` functions now
behave like all other wrapper functions in that they release the GIL when
calling into the SB API implementation.

The motivation here is actually to work around another potential bug in LLDB.
When one calls into the LLDB SB API while holding the GIL and that call causes
LLDB to interpret some Python script via `ScriptInterpreterPython`, then the GIL
will be unlocked when the control flow returns from the SB API. In the case of
the `__str__` wrapper this would cause that the next call to a Python function
requiring the GIL would fail (as SWIG will not try to reacquire the GIL as it
isn't aware that LLDB removed it).

The reason for this unexpected GIL release seems to be a workaround for recent
Python versions:
```
    // The only case we should go further and acquire the GIL: it is unlocked.
    if (PyGILState_Check())
      return;
```

The early-exit here causes `InitializePythonRAII::m_was_already_initialized` to
be always false and that causes that `InitializePythonRAII`'s destructor always
directly unlocks the GIL via `PyEval_SaveThread`. I'm investigating how to
properly fix this bug in a follow up patch, but for now this straightforward
patch seems to be enough to unblock my other patches (and it also has the
benefit of removing this workaround).

The test for this is just a simple test for `std::deque` which has a synthetic
child provider implemented as a Python script. Inspecting the deque object will
cause `expect_expr` to create a string error message by calling
`str(deque_object)`. Printing the ValueObject causes the Python script for the
synthetic children to execute which then triggers the bug described above where
the GIL ends up being unlocked.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D88302
2020-09-28 10:10:34 +02:00
Jim Ingham b65966cff6 Add the ability to write target stop-hooks using the ScriptInterpreter.
Differential Revision: https://reviews.llvm.org/D88123
2020-09-25 15:44:55 -07:00
Jason Molenda 1bec6eb3f5 Add support for firmware/standalone LC_NOTE "main bin spec" corefiles
When a Mach-O corefile has an LC_NOTE "main bin spec" for a
standalone binary / firmware, with only a UUID and no load
address, try to locate the binary and dSYM by UUID and if
found, load it at offset 0 for the user.

Add a test case that tests a firmware/standalone corefile
with both the "kern ver str" and "main bin spec" LC_NOTEs.

<rdar://problem/68193804>

Differential Revision: https://reviews.llvm.org/D88282
2020-09-25 15:19:22 -07:00
Walter Erquinigo bddebca61e [intel-pt] Refactor the JSON parsing
Recently https://reviews.llvm.org/D88103 introduced a nice API for
converting a JSON object into C++ types, which include nice error
messaging.

I'm using that new functioniality to perform the parsing in a much more
elegant way. As a result, the code looks simpler and more maintainable,
as we aren't parsing anymore individual fields manually.

I updated the test cases accordingly.

Differential Revision: https://reviews.llvm.org/D88264
2020-09-24 16:35:34 -07:00
Joseph Tremoulet 4a55c98fa7 [lldb] Normalize paths in new test
The minidump-sysroot test I added in commit 20f84257 compares two paths
using a string comparison.  This causes the Windows buildbot to fail
because of mismatched forward slashes and backslashes.  Use
os.path.normcase to normalize before comparing.
2020-09-23 12:41:47 -07:00
Jim Ingham 3726ac41e9 Add `breakpoint delete --disabled`: deletes all disabled breakpoints.
Differential Revision: https://reviews.llvm.org/D88129
2020-09-23 11:35:11 -07:00
Joseph Tremoulet 20f84257ac [lldb] Fix GetRemoteSharedModule fallback logic
When the various methods of locating the module in GetRemoteSharedModule
fail, make sure we pass the original module spec to the bail-out call to
the provided resolver function.

Also make sure we consistently use the resolved module spec from the
various success paths.

Thanks to what appears to have been an accidentally inverted condition
(commit 85967fa applied the new condition to a path where GetModuleSpec
returns false, but should have applied it when GetModuleSpec returns
true), without this fix we only pass the original module spec in the
fallback if the original spec has no uuid (or has a uuid that somehow
matches the resolved module's uuid despite the call to GetModuleSpec
failing).  This manifested as a bug when processing a minidump file with
a user-provided sysroot, since in that case the resolver call was being
applied to resolved_module_spec (despite resolution failing), which did
not have the path of its file_spec set.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D88099
2020-09-23 06:00:50 -07:00
Fangrui Song f212122150 [lldb][test] Remove accidental import pdb in 783dc7dc7e 2020-09-22 13:08:12 -07:00
Raphael Isemann ef7d22a986 Revert "[lldb] XFAIL TestMemoryHistory on Linux"
This reverts commit 7518006d75.

This test apparently works on the Swift CI ubuntu bot, so it shouldn't be
XFAIL'd on Linux.
2020-09-22 21:13:44 +02:00
Jonas Devlieghere 783dc7dc7e [lldb] Skip TestMiniDumpUUID with reproducers
The modules not getting orphaned is wreaking havoc when the UUIDs match
between tests.
2020-09-22 11:28:39 -07:00
Jonas Devlieghere 8457ae0d93 [lldb] Skip test_common_completion_process_pid_and_name with reproducers
This test launches a subprocess which will have a different PID during
capture and replay.
2020-09-22 11:28:39 -07:00
Raphael Isemann b5e49e91cb [lldb] Ignore certain Clang type sugar when creating the type name
Clang has some type sugar that only serves as a way to preserve the way a user
has typed a certain type in the source code. These types are currently not
unwrapped when we query the type name for a Clang type, which means that this
type sugar actually influences what formatters are picked for a certain type.
Currently if a user decides to reference a type by doing `::GlobalDecl Var = 3;`,
the type formatter for `GlobalDecl` will not be used (as the type sugar
around the type gives it the name `::GlobalDecl`. The same goes for other ways
to spell out a type such as `auto` etc.

With this patch most of this type sugar gets stripped when the full type name is
calculated. Typedefs are not getting desugared as that seems counterproductive.
I also don't desugar atomic types as that's technically not type sugar.

Reviewed By: jarin

Differential Revision: https://reviews.llvm.org/D87481
2020-09-22 13:37:20 +02:00
Muhammad Omair Javaid 73a6a164b8 Revert "Reapply Revert "RegAllocFast: Rewrite and improve""
This reverts commit 55f9f87da2.

Breaks following buildbots:
http://lab.llvm.org:8011/builders/lldb-arm-ubuntu/builds/4306
http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/9154
2020-09-22 14:40:06 +05:00
Jim Ingham 94b0d836a1 Fix reporting the lack of global variables in "target var".
There was a little thinko which meant when stopped in a frame with
debug information but whose CU didn't have any global variables we
report:

no debug info for frame <N>

This patch fixes that error message to say the intended:

no global variables in current compile unit

<rdar://problem/69086361>
2020-09-21 17:29:40 -07:00
Walter Erquinigo 74c93956e1 Add a "Trace" plug-in to LLDB to add process trace support in stages.
This is the first in a series of patches that will adds a new processor trace plug-in to LLDB.

The idea for this first patch to to add the plug-in interface with simple commands for the trace files that can "load" and "dump" the trace information. We can test the functionality and ensure people are happy with the way things are done and how things are organized before moving on to adding more functionality.

Processor trace information can be view in a few different ways:
- post mortem where a trace is saved off that can be viewed later in the debugger
- gathered while a process is running and allow the user to step back in time (with no variables, memory or registers) to see how each thread arrived at where it is currently stopped.

This patch attempts to start with the first solution of loading a trace file after the fact. The idea is that we will use a JSON file to load the trace information. JSON allows us to specify information about the trace like:
- plug-in name in LLDB
- path to trace file
- shared library load information so we can re-create a target and symbolicate the information in the trace
- any other info that the trace plug-in will need to be able to successfully parse the trace information
  - cpu type
  - version info
  - ???

A new "trace" command was added at the top level of the LLDB commmands:
- "trace load"
- "trace dump"

I did this because if we load trace information we don't need to have a process and we might end up creating a new target for the trace information that will become active. If anyone has any input on where this would be better suited, please let me know. Walter Erquinigo will end up filling in the Intel PT specific plug-in so that it works and is tested once we can agree that the direction of this patch is the correct one, so please feel free to chime in with ideas on comments!

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D85705
2020-09-21 17:13:18 -07:00
shafik 6807f244fa [ASTImporter] Modifying ImportDeclContext(...) to ensure that we also handle the case when the FieldDecl is an ArrayType whose ElementType is a RecordDecl
When we fixed ImportDeclContext(...) in D71378 to make sure we complete each
FieldDecl of a RecordDecl when we are importing the definition we missed the
case where a FeildDecl was an ArrayType whose ElementType is a record.

This fix was motivated by a codegen crash during LLDB expression parsing. Since
we were not importing the definition we were crashing during layout which
required all the records be defined.

Differential Revision: https://reviews.llvm.org/D86660
2020-09-21 14:57:00 -07:00
Matt Arsenault 55f9f87da2 Reapply Revert "RegAllocFast: Rewrite and improve"
This reverts commit dbd53a1f0c.

Needed lldb test updates
2020-09-21 15:45:27 -04:00
David Spickett c65627a1fe Revert "[lldb] Don't send invalid region addresses to lldb server"
This reverts commit c687af0c30
due to a test failure on Windows.
2020-09-17 13:07:44 +01:00
David Spickett c687af0c30 [lldb] Don't send invalid region addresses to lldb server
Previously when <addr> in "memory region <addr>" didn't
parse correctly, we'd print an error then also ask lldb-server
for a region containing LLDB_INVALID_ADDRESS.

(lldb) memory region not_an_address
error: invalid address argument "not_an_address"...
error: Server returned invalid range

Only send the command to lldb-server if the address
parsed correctly.

(lldb) memory region not_an_address
error: invalid address argument "not_an_address"...

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D87694
2020-09-17 10:26:16 +01:00
Jonas Devlieghere 127faae752 [lldb] Add -l/--language option to script command
Make it possible to run the script command with a different language
than currently selected.

  $ ./bin/lldb -l python
  (lldb) script -l lua
  >>> io.stdout:write("Hello, World!\n")
  Hello, World!

When passing the language option and a raw command, you need to separate
the flag from the script code with --.

  $ ./bin/lldb -l python
  (lldb) script -l lua -- io.stdout:write("Hello, World!\n")
  Hello, World!

Differential revision: https://reviews.llvm.org/D86996
2020-09-15 09:40:17 -07:00
Pavel Labath af3789a188 [lldb] Improve qemu interop for aarch64
qemu calls the "fp" and "lr" registers via their generic names
(x29/x30). This mismatch manifested itself as not being able to unwind
or display values of some local variables.
2020-09-15 13:32:08 +02:00
Walter Erquinigo 132e57bc59 Retry of D84974
- Fix a small issue caused by a conflicting name (GetObject) on Windows.
  The fix was to rename the internal GetObject function to
  GetNextFunction.
2020-09-14 10:44:13 -07:00
Jonas Devlieghere 76e3a27c16 [lldb] Add test for CFMutableDictionaryRef
While writing a test for a change in Foundation I noticed we didn't yet
test CFMutableDictionaryRef.
2020-09-11 16:11:25 -07:00
Med Ismail Bennani 4da8fa45a0 [lldb/API] Add Breakpoint::SerializeToStructuredData to SBAPI
This patch adds a way to fetch breakpoint metadatas as a serialized
`Structured` Data format (JSON). This can be used by IDEs to update
their UI when a breakpoint is set or modified from the console.

rdar://11013798

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-09-11 20:09:55 +02:00
Stella Stamenova c464f1d8f9 [lldb, tests] Correctly configure the yaml2obj paths
They are currently not being set correctly for the case of multi-config generators like XCode and VS. There's also a typo in one of the cmake files.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D87466
2020-09-10 10:10:28 -07:00
Raphael Isemann b85222520f [lldb] Enable std::pair in CxxModuleHandler
This adds support for substituting std::pair instantiations with enabled
import-std-module.

With the fixes in parent revisions we can currently substitute a single pair
(however, a result that returns a second pair currently causes LLDB to crash
while importing the second template instantiation).

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D85141
2020-09-09 10:49:53 +02:00
Raphael Isemann 7866b91405 [lldb] Fix a crash when the ASTImporter is giving us two Imported callbacks for the same target decl
The ASTImporter has an `Imported(From, To)` callback that notifies subclasses
that a declaration has been imported in some way. LLDB uses this in the
`CompleteTagDeclsScope` to see which records have been imported into the scratch
context. If the record was declared inside the expression, then the
`CompleteTagDeclsScope` will forcibly import the full definition of that record
to the scratch context so that the expression AST can safely be disposed later
(otherwise we might end up going back to the deleted AST to complete the
minimally imported record). The way this is implemented is that there is a list
of decls that need to be imported (`m_decls_to_complete`) and we keep completing
the declarations inside that list until the list is empty. Every `To` Decl we
get via the `Imported` callback will be added to the list of Decls to be
completed.

There are some situations where the ASTImporter will actually give us two
`Imported` calls with the same `To` Decl. One way where this happens is if the
ASTImporter decides to merge an imported definition into an already imported
one. Another way is that the ASTImporter just happens to get two calls to
`ASTImporter::Import` for the same Decl. This for example happens when importing
the DeclContext of a Decl requires importing the Decl itself, such as when
importing a RecordDecl that was declared inside a function.

The bug addressed in this patch is that when we end up getting two `Imported`
calls for the same `To` Decl, then we would crash in the
`CompleteTagDeclsScope`.  That's because the first time we complete the Decl we
remove the Origin tracking information (that maps the Decl back to from where it
came from). The next time we try to complete the same `To` Decl the Origin
tracking information is gone and we hit the `to_context_md->getOrigin(decl).ctx
== m_src_ctx` assert (`getOrigin(decl).ctx` is a nullptr the second time as the
Origin was deleted).

This is actually a regression coming from D72495. Before D72495
`m_decls_to_complete` was actually a set so every declaration in there could
only be queued once to be completed. The set was changed to a vector to make the
iteration over it deterministic, but that also causes that we now potentially
end up trying to complete a Decl twice.

This patch essentially just reverts D72495 and makes the `CompleteTagDeclsScope`
use a SetVector for the list of declarations to be completed. The SetVector
should filter out the duplicates (as the original `set` did) and also ensure that
the completion order is deterministic. I actually couldn't find any way to cause
LLDB to reproduce this bug by merging declarations (this would require that we
for example declare two namespaces in a non-top-level expression which isn't
possible). But the bug reproduces very easily by just declaring a class in an
expression, so that's what the test is doing.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D85648
2020-09-09 10:31:39 +02:00
Raphael Isemann 32c8da41dc [lldb] Don't infinite loop in SemaSourceWithPriorities::CompleteType when trying to complete a forward decl
SemaSourceWithPriorities is a special SemaSource that wraps our normal LLDB
ExternalASTSource and the ASTReader (which is used for the C++ module loading).
It's only active when the `import-std-module` setting is turned on.

The `CompleteType` function there in `SemaSourceWithPriorities` is looping over
all ExternalASTSources and asks each to complete the type. However, that loop is
in another loop that keeps doing that until the type is complete. If that
function is ever called on a type that is a forward decl then that causes LLDB
to go into an infinite loop.

I remember I added that second loop and the comment because I thought I saw a
similar pattern in some other Clang code, but after some grepping I can't find
that code anywhere and it seems the rest of the code base only calls
CompleteType once (It would also be kinda silly to have calling it multiple
times). So it seems that's just a silly mistake.

The is implicitly tested by importing `std::pair`, but I also added a simpler
dedicated test that creates a dummy libc++ module with some forward declarations
and then imports them into the scratch AST context. At some point the
ASTImporter will check if one of the forward decls could be completed by the
ExternalASTSource, which will cause the `SemaSourceWithPriorities` to go into an
infinite loop once it receives the `CompleteType` call.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D87289
2020-09-09 10:05:57 +02:00
Walter Erquinigo 5c463d107d Revert "Retry of D84974"
This reverts commit 5b2b4f331d.

This caused a link error in
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/18794/steps/build/logs/stdio
2020-09-08 13:41:11 -07:00
Walter Erquinigo 5b2b4f331d Retry of D84974
The test is being disabled on Linux, as lldb-vscode has a bug with
--wait-for on LInux.
I'm also fixing some compilation warnings.
2020-09-08 11:50:09 -07:00
Muhammad Omair Javaid 9bee13f890 Move targetHasSVE function to lldbtest.py
targetHasSVE helper function was added to test for availability of SVE support
by connected platform. We now intend to use this function in other testcases
and I am moving it to a generic location in lldbtest.py to allow usage by
other upcoming testcases.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D86872
2020-09-07 08:37:39 +05:00
Raphael Isemann 101f37a1b3 [lldb][NFC] Rewrite CPP11EnumTypes test to make it faster
TestCPP11EnumTypes is one of the most expensive tests on my system and takes
around 35 seconds to run. A relatively large amount of that time is actually
doing CPU intensive work it seems (and not waiting on timeouts like other
slow tests).

The main issue is that this test repeatedly compiles the same source files
with different compiler defines. The test is also including standard library
headers, so it will also build all system modules with the gmodules debug
info variant. This leads to the problem that this test ends up compiling all
system Clang modules 8 times (one for each subtest with a unique define). As
the system modules are quite large, this causes that this test spends most
of its runtime just recompiling all system modules on macOS.

There is also the small issue that this test is starting and start-stopping
the test process a few hundred times.

This rewrites the test to instead just use a macro to instantiate all the
enum types in a single source and uses global variables to test the values
(which means there is no more need to continue/stop or even start a process).

I kept running all the debug info variants (event though it doesn't seem really
relevant) to keep this as NFC as possible.

This reduced the test runtime by around 1.5 seconds on my system (or in relative
numbers, the runtime of this test decreases by 95%).
2020-09-04 13:45:42 +02:00
Raphael Isemann f9ad112770 [lldb] Speed up TestValueObjectRecursion by making it a no_debug_info_test
This is one of the most expensive tests and runs for nearly half a minute on
my machine. Beside this test just doing a lot of work by iterating 15k times on
one ValueObject (which seems to be the point), it also runs this for every
debug info variant which doesn't seem relevant to just iterating ValueObject.

This marks it as no_debug_info_test to only run one debug info variation
and cut down the runtime to around 7 seconds on my machine.
2020-09-04 11:25:43 +02:00
Walter Erquinigo ddcc7ce591 [lldb-vscode] Fix TestVSCode_module
Caused by D86662. The fix is only checking some fields when the expect_debug_info_size flag is true. For some reason this was not failing on a local linux machine.
2020-09-03 09:01:56 -07:00
David Spickett 9f18f3c858 [lldb] Improve test failure reporting for expect()
This updates the errors reported by expect()
to something like:

```
Ran command:
"help"

Got output:
Debugger commands:
<...>

Expecting start string: "Debugger commands:" (was found)
Expecting end string: "foo" (was not found)
```
(see added tests for more examples)

This shows the user exactly what was run,
what checks passed and which failed. Along with
whether that check was supposed to pass.
(including what regex patterns matched)

These lines are also output to the test
trace file, whether the test passes or not.

Note that expect() will still fail at the first failed
check, in line with previous behaviour.

Also I have flipped the wording of the assert
message functions (.*_MSG) to describe failures
not successes. This makes more sense as they are
only shown on assert failures.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D86792
2020-09-03 13:35:05 +01:00
Raphael Isemann 5b354d204d [lldb] Make symbol list output from `image dump symtab` not depend on internal ordering of DenseMap
`image dump symtab` seems to output the symbols in whatever order they appear in
the DenseMap that is used to filter out symbols with non-unique addresses. As
DenseMap is a hash map this order can change at any time so the output of this
command is pretty unstable. This also causes the `Breakpad/symtab.test` to fail
with enabled reverse iteration (which reverses the DenseMap order to find issues
like this).

This patch makes the DenseMap a std::vector and uses a separate DenseSet to do
the address filtering. The output order is now dependent on the order in which
the symbols are read (which should be deterministic). It might also avoid a bit
of work as all the work for creating the Symbol constructor parameters is only
done when we can actually emplace a new Symbol.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D87036
2020-09-03 10:27:19 +02:00
Raphael Isemann e123959e94 [lldb] Remove debugserver specific string from TestAbortExitCode check
The test only checks the exit code that the debug server sends back, but
not the following explanation which is different for debugserver and lldb-server.
2020-09-03 10:03:02 +02:00
Raphael Isemann f0699d9109 [debugserver] Fix that debugserver's stop reply packets always return signal code 0
If our process terminates due to an unhandled signal, we are supposed to get the
signal code via WTERMSIG. However, we instead try to get the exit status via
WEXITSTATUS which just ends up always calculating signal code 0 (at least on the
macOS implementation where it just shifts the signal code bits away and we're
left with only 0 bits).

The exit status calculation on the LLDB side also seems a bit off as it claims
an exit status that is just the signal code (instead of for example 128 + signal
code), but that will be another patch.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D86336
2020-09-03 09:47:03 +02:00
Jonas Devlieghere 3746906193 [lldb] Add reproducer verifier
Add a reproducer verifier that catches:

 - Missing or invalid home directory
 - Missing or invalid working directory
 - Missing or invalid module/symbol paths
 - Missing files from the VFS

The verifier is enabled by default during replay, but can be skipped by
passing --reproducer-no-verify.

Differential revision: https://reviews.llvm.org/D86497
2020-09-02 22:00:00 -07:00
Walter Erquinigo 5f6ca065a5 Revert de6caf871b and 51128b670d (https://reviews.llvm.org/D84974)
The tests seem to be timing out in all linux bots. Need further analysis.

Revert "run in terminal"

This reverts commit de6caf871b.
2020-09-02 17:06:48 -07:00
Walter Erquinigo de6caf871b run in terminal 2020-09-02 14:38:00 -07:00
Med Ismail Bennani 0e86f39045
[lldb/test] Fix TestPlatform*.py Windows failures (NFC)
This patch fixes the windows failures introduced by `addb514`:
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/18671/steps/test/logs/stdio

This macro, used in the test to check the platform, was missing a `_`,
making the test behave like it was run from a UNIX platform.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-09-02 21:41:35 +02:00
Med Ismail Bennani addb5148f5 [lldb/Target] Add custom interpreter option to `platform shell`
This patch adds the ability to use a custom interpreter with the
`platform shell` command. If the user set the `-s|--shell` option
with the path to a binary, lldb passes it down to the platform's
`RunShellProcess` method and set it as the shell to use in
`ProcessLaunchInfo to run commands.

Note that not all the Platforms support running shell commands with
custom interpreters (i.e. RemoteGDBServer is only expected to use the
default shell).

This patch also makes some refactoring and cleanups, like swapping
CString for StringRef when possible and updating `SBPlatformShellCommand`
with new methods and a new constructor.

rdar://67759256

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-09-02 16:36:10 +02:00
Yifan Shen 82139b8770 Simplify Symbol Status Message to Only Debug Info Size
The Symbol Status in modules view is simplified so that only when the module has debug info and its size is non-zero, will the status message be displayed. The symbol status message is renamed to debug info size and flag message like "Symbols not found" and "Symbols loaded" is deleted.

Differential Revision: https://reviews.llvm.org/D86662
2020-09-01 16:25:20 -07:00
Raphael Isemann 7c80f2da81 Revert "[lldb] Add reproducer verifier"
This reverts commit 297f69afac. It broke
the Fedora 33 x86-64 bot. See the review for more info.
2020-09-01 12:21:44 +02:00
Jonas Devlieghere 297f69afac [lldb] Add reproducer verifier
Add a reproducer verifier that catches:

 - Missing or invalid home directory
 - Missing or invalid working directory
 - Missing or invalid module/symbol paths
 - Missing files from the VFS

The verifier is enabled by default during replay, but can be skipped by
passing --reproducer-no-verify.

Differential revision: https://reviews.llvm.org/D86497
2020-08-31 15:14:18 -07:00
Gongyu Deng 1cd99fe9d4 [lldb] tab completion for class `CommandObjectTypeFormatterDelete`
1. Added a dedicated completion to class `CommandObjectTypeFormatterDelete`
   which can be used by these commands: `type filter/format/summary/synthetic delete`;
2. Added a related test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84142
2020-08-31 14:18:07 +02:00
Raphael Isemann da0d43d90a [lldb][NFC] Remove trailing whitespace in TestCompletion 2020-08-31 12:24:25 +02:00
Raphael Isemann b51321ccc8 [lldb] Fix TestCompletion's pid completion failing randomly
TestCompletion is randomly failing on some bots. The error message however states
that the computed completions actually do contain the expected pid we're
looking for, so there shouldn't be any test failure.

The reason for that turns out to be that complete_from_to is actually used
for testing two different features. It can be used for testing what the
common prefix for the list of completions is and *also* for checking all the
possible completions that are returned for a command. Which one of the two
things should be checked can't be defined by a parameter to the function, but
is instead guessed by the test method instead based on the results that were
returned. If there is a common prefix in all completions, then that prefix
is searched and otherwise all completions are searched.

For TestCompletion's pid test this behaviour leads to the strange test failures.
If all the pid's that our test LLDB can see have a common prefix (e.g., it
can only see pids [123, 122, 10004, 10000] -> common prefix '1'), then
complete_from_to check that the common prefix contains our pid, which is
always fails ('1' doesn't contain '123' or any other valid pid). If there
isn't a common prefix (e.g., pids are [123, 122, 10004, 777]) then
complete_from_to will check the list of completions instead which works correctly.

This patch is fixing this by adding a simple check method that doesn't
have this behaviour and is simply searching the returned list of completions.
This should get the bots green while I'm working on a proper fix that fixes
complete_from_to.
2020-08-31 12:22:41 +02:00
Xing GUO 1d01fc100b [Test] Simplify DWARF test cases. NFC.
The Length, AbbrOffset and Values fields of the debug_info section are
optional. This patch helps remove them and simplify test cases.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D86857
2020-08-31 14:03:48 +08:00
Jonas Devlieghere 2965e9bd5e [lldb] Hoist --framework argument out of LLDB_TEST_COMMON_ARGS (NFC)
Give the framework argument its own variable (LLDB_FRAMEWORK_DIR) so
that we can configure it in lit.site.cfg.py if we so desire.
2020-08-28 18:15:33 -07:00
Jonas Devlieghere 3f2fb0132f [lldb] Make the lit configuration values optional for the API tests
LIT uses a model where the test suite is configurable trough a
lit.site.cfg file. Most of the time we use the lit.site.cfg with values
that match the current build configuration, generated by CMake.

Nothing prevents you from running the test suite with a different
configuration, either by overriding some of these values from the
command line, or by passing a different lit.site.cfg.

The latter is currently tedious. Many configuration values are optional
but they still need to be set because lit.cfg.py is accessing them
directly. This patch changes the code to use getattr to return the
attribute if it exists. This makes it possible to specify a minimal
lit.site.cfg with only the mandatory/desired configuration values.

Differential revision: https://reviews.llvm.org/D86821
2020-08-28 18:08:22 -07:00
Jonas Devlieghere 141c8475b6 [lldb] Get rid of LLDB_LIB_DIR and LLDB_IMPLIB_DIR in dotest
This patch removes the rather confusing LLDB_LIB_DIR and LLDB_IMPLIB_DIR
environment variables. They are confusing because LLDB_LIB_DIR would
point to the bin subdirectory in the build root while LLDB_IMPLIB_DIR
would point to the lib subdirectory. The reason far this was
LLDB.framework, which gets build under bin.

This patch replaces their uses with configuration.lldb_framework_path
and configuration.lldb_libs_dir respectively.

Differential revision: https://reviews.llvm.org/D86817
2020-08-28 15:45:54 -07:00
Jonas Devlieghere 55e7d91072 [lldb] Dervice dotest.py path from config.lldb_src_root (NFC) 2020-08-28 15:45:54 -07:00
Jordan Rupprecht 8bd895cac0 [lldb/test] Use shorter test case names in TestStandardUnwind
TestStandardUnwind uses the full absolute path to a set of C/C++ files as the test case name, which in turn is used in the name of a log file. When the source file is long, and the directory where log files are stored is also long, this causes an OSError because the log filename is too long.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D86752
2020-08-28 11:49:50 -07:00
Pavel Labath 0de1463373 [lldb] Fix Type::GetByteSize for pointer types
The function was returning an incorrect (empty) value on the first
invocation. Given that this only affected the first invocation, this
bug/typo went mostly unaffected. DW_AT_const_value were particularly
badly affected by this as the GetByteSize call is
SymbolFileDWARF::ParseVariableDIE is likely to be the first call of this
function, and its effects cannot be undone by retrying.

Depends on D86348.

Differential Revision: https://reviews.llvm.org/D86436
2020-08-27 15:37:49 +02:00
Pavel Labath 9f5927e42b [lldb/DWARF] Fix handling of variables with both location and const_value attributes
Class-level static constexpr variables can have both DW_AT_const_value
(in the "declaration") and a DW_AT_location (in the "definition")
attributes. Our code was trying to handle this, but it was brittle and
hard to follow (and broken) because it was processing the attributes in
the order in which they were found.

Refactor the code to make the intent clearer -- DW_AT_location trumps
DW_AT_const_value, and fix the bug which meant that we were not
displaying these variables properly (the culprit was the delayed parsing
of the const_value attribute due to a need to fetch the variable type.

Differential Revision: https://reviews.llvm.org/D86615
2020-08-27 15:05:47 +02:00
Pavel Labath 82982304d7 [lldb/DWARF] More DW_AT_const_value fixes
This fixes several issues in handling of DW_AT_const_value attributes:
- the first is that the size of the data given by data forms does not
  need to match the size of the underlying variable. We already had the
  case to handle this for DW_FORM_(us)data -- this extends the handling
  to other data forms. The main reason this was not picked up is because
  clang uses leb forms in these cases while gcc prefers the fixed-size
  ones.
- The handling of DW_AT_strp form was completely broken -- we would end
  up using the pointer value as the result. I've reorganized this code
  so that it handles all string forms uniformly.
- In case of a completely bogus form we would crash due to
  strlen(nullptr).

Depends on D86311.

Differential Revision: https://reviews.llvm.org/D86348
2020-08-26 13:17:26 +02:00
Raphael Isemann 7518006d75 [lldb] XFAIL TestMemoryHistory on Linux
This test appears to have never worked on Linux but it seems none of the current
bots ever ran this test as it required enabling compiler-rt (otherwise it
would have just been skipped).

This just copies over the XFAIL decorator that are already on all other sanitizer
tests.
2020-08-26 10:24:13 +02:00
Jason Molenda b1e856d3a9 Ah, one test too many updated. This one should be unmodified. 2020-08-25 21:03:39 -07:00
Jason Molenda 99d187a003 Update UnwindPlan dump to list if it is a trap handler func; also Command
Update the "image show-unwind" command output to show if the function
being shown is listed as a user-setting or platform trap handler.

Update the individual UnwindPlan dumps to show whether the unwind plan
is registered as a trap handler.
2020-08-25 20:53:59 -07:00
Raphael Isemann 7de7fe5d0e [lldb] Don't ask for QOS_CLASS_UNSPECIFIED queue in TestQueues
TestQueues is curiously failing for me as my queue for QOS_CLASS_UNSPECIFIED
is named "Utility" and not "User Initiated" or "Default". While debugging, this
I noticed that this test isn't actually using this API right from what I understand. The API documentation
for `dispatch_get_global_queue` specifies for the parameter: "You may specify the value
QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_USER_INITIATED, QOS_CLASS_UTILITY, or QOS_CLASS_BACKGROUND."

QOS_CLASS_UNSPECIFIED isn't listed as one of the supported values. swift-corelibs-libdispatch
even checks for this value and returns a DISPATCH_BAD_INPUT. The
libdispatch shipped on macOS seems to also check for QOS_CLASS_UNSPECIFIED and seems to
instead cause a "client crash", but somehow this doesn't trigger in this test and instead we just
get whatever queue

This patch just removes that part of the test as it appears the code is just incorrect.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D86211
2020-08-25 20:13:33 +02:00
Raphael Isemann 2501e911a5 [lldb] Don't depend on psutil in TestCompletion.py
psutil isn't reall a dependency of the test suite so this shouldn't be
unconditionally be imported here. Instead just check for the process name
by looking for the "a.out" string to get the bots green again.
2020-08-25 08:30:33 +02:00
shafik 93b255142b [LLDB] Fix how ValueObjectVariable handles DW_AT_const_value when the DWARFExpression holds the data that represents a constant value
In some cases when we have a DW_AT_const_value and the data can be found in the
DWARFExpression then ValueObjectVariable does not handle it properly and we end
up with an extracting data from value failed error.

The test is a very stripped down assembly file since reproducing this relies on the results of compiling with -O1 which may not be stable over time.

Differential Revision: https://reviews.llvm.org/D86311
2020-08-24 15:17:27 -07:00
Jonas Devlieghere a842950b62 [lldb] Add a SymbolFileProvider to record and replay calls to dsymForUUID
When replaying a reproducer captured from a core file, we always use
dsymForUUID for the kernel binary. When enabled, we also use it to find
kexts. Since these files are already contained in the reproducer,
there's no reason to call out to an external tool. If the tool returns a
different result, e.g. because the dSYM got garbage collected, it will
break reproducer replay. The SymbolFileProvider solves the issue by
mapping UUIDs to module and symbol paths in the reproducer.

Differential revision: https://reviews.llvm.org/D86389
2020-08-24 15:09:08 -07:00
Greg Clayton 0e6c9a6e79 Add hashing of the .text section to ProcessMinidump.
Breakpad will always have a UUID for binaries when it creates minidump files. If an ELF files has a GNU build ID, it will use that. If it doesn't, it will create one by hashing up to the first 4096 bytes of the .text section. LLDB was not able to load these binaries even when we had the right binary because the UUID didn't match. LLDB will use the GNU build ID first as the main UUID for a binary and fallback onto a 8 byte CRC if a binary doesn't have one. With this fix, we will check for the Breakpad hash or the Facebook hash (a modified version of the breakpad hash that collides a bit less) and accept binaries when these hashes match.

Differential Revision: https://reviews.llvm.org/D86261
2020-08-24 11:43:50 -07:00
Gongyu Deng 188f1ac301 [lldb] type category name common completion
1. Added a new common completion TypeCategoryNames to provide a list of category names for completion;
2. Applied the completion to these commands: type category delete/enable/disable/list/define;
3. Added a related test case;
4. Bound the completion to the arguments of the type 'eArgTypeName'.

Reviewed By: teemperor, JDevlieghere

Differential Revision: https://reviews.llvm.org/D84124
2020-08-24 19:54:23 +02:00
Gongyu Deng 3cd8d7b172 [lldb] Remote disk file/directory completion for platform commands
1. Extended the gdb-remote communication related classes with disk file/directory
   completion functions;
2. Added two common completion functions RemoteDiskFiles and
   RemoteDiskDirectories based on the functions above;
3. Added completion for these commands:
   A. platform get-file <remote-file> <local-file>;
   B. platform put-file <local-file> <remote-file>;
   C. platform get-size <remote-file>;
   D. platform settings -w <remote-dir>;
   E. platform open file <remote-file>.
4. Added related tests for client and server;
5. Updated docs/lldb-platform-packets.txt.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D85284
2020-08-24 17:55:54 +02:00
Gongyu Deng 19311f5c3e [lldb] common completion for process pids and process names
1. Added two common completions: `ProcessIDs` and `ProcessNames`, which are
refactored from their original dedicated option completions;
2. Removed the dedicated option completion functions of `process attach` and
`platform process attach`, so that they can use arg-type-bound common
completions instead;
3. Bound `eArgTypePid` to the pid completion, `eArgTypeProcessName` to the
process name completion in `CommandObject.cpp`;
4. Added a related test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D80700
2020-08-24 17:30:43 +02:00
Jonas Devlieghere 86fc193309 [lldb] Don't pass --rerun-all-issues on Windows.
The functionality has been removed for a while and now the dotest
argument has been removed asll.
2020-08-21 19:58:24 -07:00
Jonas Devlieghere 52e758f352 [lldb] Fix build error in TestSimulatorPlatform.py
Before e5d08fcbac the Makefile would always compute the min-version,
even if it wasn't set in the triple. This nuance got lost when passing
the ARCH_CFLAGS directly from TestSimulatorPlatform.
2020-08-21 13:35:26 -07:00
Jonas Devlieghere 57e0ef131b [lldb] Make it a fatal error when %lldb cannot be substituted
Refuse to run the shell tests when %lldb cannot be substituted. This
prevents the test from silently running again the `lldb` in your PATH.

I noticed because when this happens, %lldb-init gets substituted with
lldb-init, which does not exists.
2020-08-21 11:18:21 -07:00
Jonas Devlieghere 08249d7f72 [lldb] Fix TestAPILog.py for reproducer replay
With the log file being a build artifact we don't need to clean it up.
If this happens before the reproducer is captured, the file will be
missing from the reproducer root but being part of the mapping.
2020-08-21 10:35:35 -07:00
Jonas Devlieghere 2799031a14 [lldb] Skip PDB and NativePDB tests with reproducers 2020-08-21 09:09:45 -07:00
Gongyu Deng e1cd7cac8a [lldb] Tab completion for process load/unload
1. Complete `process load` with the common disk file completion, so there is not test provided for it;
2. Complete `process unload` with the tokens of valid loaded images.

Thanks for Raphael's help on the test for `process unload`.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D79887
2020-08-21 10:36:39 +02:00
Xing GUO 290e399f96 [DWARFYAML] Add support for emitting multiple abbrev tables.
This patch adds support for emitting multiple abbrev tables. Currently,
compilation units will always reference the first abbrev table.

Reviewed By: jhenderson, labath

Differential Revision: https://reviews.llvm.org/D86194
2020-08-21 10:12:08 +08:00
Jonas Devlieghere 73af341beb [lldb] Capture and load home directory from the reproducer.
When replaying the reproducer, lldb should source the .lldbinit file
that was captured by the reproducer and not the one in the current home
directory. This requires that we store the home directory as part of the
reproducer. By returning the virtual home directory during replay, we
ensure the correct virtual path gets constructed which the VFS can then
find and remap to the correct file in the reproducer root.

This patch adds a new HomeDirectoryProvider, similar to the existing
WorkingDirectoryProvider. As the home directory is not part of the VFS,
it is stored in LLDB's FileSystem instance.
2020-08-20 18:08:59 -07:00
Fangrui Song b587ca93be [test] Replace `yaml2obj >` with `yaml2obj -o` and remove unneeded input redirection 2020-08-20 15:01:09 -07:00
Gongyu Deng 22e63cba17 [lldb] tab completion for breakpoint names
1. created a common completion for breakpoint names;
2. bound the breakpoint name common completion with eArgTypeBreakpointName;
3. implemented the dedicated completion for breakpoint read -N.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D80693
2020-08-20 20:56:34 +02:00
Pavel Labath 9109311356 [lldb] Forcefully complete a type when adding typedefs
This is very similar to D85968, only more elusive to since we were not
adding the typedef type to the relevant DeclContext until D86140, which
meant that the DeclContext was populated (and the relevant assertion
hit) only after importing the type into the expression ast in a
particular way.

I haven't checked whether this situation can be hit in the gmodules
case, but my money is on "yes".

Differential Revision: https://reviews.llvm.org/D86216
2020-08-20 15:19:10 +02:00
Jonas Devlieghere 09ca3f41bb [lldb] Update TestSimulatorPlatform.py to set ARCH_CFLAGS instead of TRIPLE
I move the triple (de)composition logic into the builder in e5d08fcbac
but this test is relying on Make to construct the set the ARCH,
ARCH_CFLAGS and SDKROOT based on the given TRIPLE. This patch updates
the test to pass these variables directly.

Differential revision: https://reviews.llvm.org/D86244
2020-08-19 15:42:44 -07:00
Jonas Devlieghere a3fc61c80f [lldb] Move Xcode SDK helper functions into lldbutil
This allows the logic to be reused by both the builders and the tests.
2020-08-19 13:30:27 -07:00
Jonas Devlieghere 9f5210aacf [lldb] Print the load command that wasn't found in TestSimulatorPlatform
Print which load command we were looking for when the sanity check
fails:

  AssertionError: 0 != 1 : wrong number of load commands for
  LC_VERSION_MIN_MACOSX
2020-08-19 12:42:59 -07:00
Pavel Labath 9cc2f13dee [lldb] Clean up DW_AT_declaration-with-children.s test
Address some post-commit feedback on D85968.
2020-08-19 14:58:50 +02:00
Pavel Labath d7363397c6 [lldb] Add typedefs to the DeclContext they are created in
TypeSystemClang::CreateTypedef was creating a typedef in the right
DeclContext, but it was not actually adding it as a child of the
context. The resulting inconsistent state meant that we would be unable
to reference the typedef from an expression directly, but we could use
them if they end up being pulled in by some previous subexpression
(because the ASTImporter will set up the correct links in the expression
ast).

This patch adds the typedef to the decl context it is created in.

Differential Revision: https://reviews.llvm.org/D86140
2020-08-19 14:57:43 +02:00
Raphael Isemann c1b1868f35 [lldb] Make error messages in TestQueues more helpfull 2020-08-19 13:30:31 +02:00
Muhammad Omair Javaid bd791e97f8 [LLDB] Minor fix in TestSVERegisters.py for AArch64/Linux buildbot
This adds a minor test case fix to previously submitted AArch64 SVE
ptrace support. This was failing on LLDB/AArch64 Linux buildbot.

Differential Revision: https://reviews.llvm.org/D79699
2020-08-19 15:47:59 +05:00
Muhammad Omair Javaid 567ba6c468 [LLDB] Add ptrace register access for AArch64 SVE registers
This patch adds NativeRegisterContext_arm64 ptrace routines to access
AArch64 SVE register set. This patch also adds a test-case to test
AArch64 SVE register access and dynamic size configuration capability.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D79699
2020-08-19 15:11:01 +05:00
David Blaikie f7a49d2aa6 [WIP][DebugInfo] Lazily parse debug_loclist offsets
Parsing DWARFv5 debug_loclist offsets when a CU is parsed is weighing
down memory usage of symbolizers that don't need to parse this data at
all. There's not much benefit to caching these anyway - since they are
O(1) lookup and reading once you know where the offset list starts (and
can do bounds checking with the offset list size too).

In general, I think it might be time to start paying down some of the
technical debt of loc/loclist/range/rnglist parsing to try to unify it a
bit more.

eg:

* Currently DWARFUnit has: RangeSection, RangeSectionBase, LocSection,
  LocSectionBase, LocTable, RngListTable, LoclistTableHeader (be nice if
  these were all wrapped up in two variables - one for loclists, one for
  rnglists)

* rnglists and loclists are handled differently (see:
  LoclistTableHeader, but no RnglistTableHeader)

* maybe all these types could be less stateful - lazily parse what they
  need to, even reparsing rather than caching because it doesn't seem
  too expensive, for instance. (though admittedly so long as it's
  constantcost/overead per compilatiton that's probably adequate)

* Maybe implementing and using a DWARFDataExtractor that can be
  sub-ranged (so we could slice it up to just the single contribution) -
  though maybe that's not so useful because loc/ranges need to refer to
  it by absolute, not contribution-relative mechanisms

Differential Revision: https://reviews.llvm.org/D86110
2020-08-18 10:49:39 -07:00
Jan Kratochvil 7baed769c7 [lldb] [testsuite] Add split-file for check-lldb dependencies
D85968 started to use `split-file` and while buildbots run fine while
doing `make check-lldb` by hand I get:

.../llvm-monorepo-clangassert/tools/lldb/test/SymbolFile/DWARF/Output/DW_AT_declaration-with-children.s.script: line 2: split-file: command not found
failed:
  lldb-shell :: SymbolFile/DWARF/DW_AT_declaration-with-children.s

Differential Revision: https://reviews.llvm.org/D86144
2020-08-18 18:10:55 +02:00
Luboš Luňák dcd4589a0d [lldb][gui] use left/right in the source view to scroll
I intentionally decided not to reset the column automatically
anywhere, because I don't know where and if at all that should happen.
There should be always an indication of being scrolled (too much)
to the right, so I'll leave this to whoever has an opinion.

Differential Revision: https://reviews.llvm.org/D85290
2020-08-18 13:25:01 +02:00
Jonas Devlieghere 9c5e25a696 [lldb] Skip test_launch_simple with reproducers
The test checks the inferior's output. During replay the binary doesn't
actually run and the output isn't captured by the reproducers.
2020-08-17 11:47:07 -07:00
Jonas Devlieghere 5a7b61b183 [lldb] Skip TestMultipleDebuggers on Windows 2020-08-17 11:34:25 -07:00
Jonas Devlieghere 24d3210e62 [lldb] Skip the Apple Simulator tests with reproducers 2020-08-17 11:29:37 -07:00
Jonas Devlieghere 6dabd267bd [lldb] Skip TestError.test with reproducers
This tests the driver, which is bypassed by the reproducer during
replay.
2020-08-17 10:42:58 -07:00
Jonas Devlieghere e9b0994012 [lldb] Replace unittest2.expectedFailure with expectedFailure (NFC)
Rename the existing expectedFailure to expectedFailureIfFn to better
describe its purpose and provide an overload for
unittest2.expectedFailure in decorators.py.
2020-08-17 10:05:49 -07:00
Raphael Isemann c6cc566c8a [lldb] Use os.path.sep in TestInvalidArgsLog.py to fix Windows bot 2020-08-17 19:03:27 +02:00
Jonas Devlieghere 8b67b707b0 [lldb] Add missing signal include for TestMultipleDebuggers.py
Fixes multi-process-driver.cpp:221:19: error: use of undeclared
identifier 'SIG_IGN'
2020-08-17 09:41:45 -07:00
Jonas Devlieghere a0a328ed4f [lldb] Fix and re-enable TestMultipleDebuggers
The comment says that TestMultipleDebuggers was XFAILed because it was
failing nondeterministically in which case it should be skipped not
failed (as XPASS will cause the test suite to fail).

The reason it fails is because it was not marked as a no-debug-info test
case. I've ran the test in a loop and it has been passing consistently.
Let's enable it and see if the bots agree, if not we can skip it.
2020-08-17 09:20:20 -07:00
Jonas Devlieghere 75966ee241 [lldb] Get rid of helper CMake variables for Python
This patch is a big sed to rename the following variables:

  s/PYTHON_LIBRARIES/Python3_LIBRARIES/g
  s/PYTHON_INCLUDE_DIRS/Python3_INCLUDE_DIRS/g
  s/PYTHON_EXECUTABLE/Python3_EXECUTABLE/g
  s/PYTHON_RPATH/Python3_RPATH/g

I've also renamed the CMake module to better express its purpose and for
consistency with FindLuaAndSwig.

Differential revision: https://reviews.llvm.org/D85976
2020-08-17 08:47:52 -07:00
Raphael Isemann f5f22f0448 [lldb] Skip TestSimulatorPlatform with sanitized builds
The test executable crashes when ran on a simulator. Skipping until this is
fixed.

rdar://67238668
2020-08-17 15:06:48 +02:00
Raphael Isemann 42b9a68352 [lldb][NFC] Use expect_expr in more tests 2020-08-17 13:14:57 +02:00
Raphael Isemann 6b97fa0bfe [lldb] Remove OS-specific string from TestInvalidArgsLog
This is the error message from the OS, so we shouldn't check against the
OS-specific part of the string.

Fixes the test on Windows which returns a different error message.
2020-08-17 11:57:43 +02:00
Pavel Labath 2d89a3ba12 [lldb] Forcefully complete a type when adding nested classes
With -flimit-debug-info, we can run into cases when we only have a class
as a declaration, but we do have a definition of a nested class. In this
case, clang will hit an assertion when adding a member to an incomplete
type (but only if it's adding a c++ class, and not C struct).

It turns out we already had code to handle a similar situation arising
in the -gmodules scenario. This extends the code to handle
-flimit-debug-info as well, and reorganizes bits of other code handling
completion of types to move functions doing similar things closer
together.

Differential Revision: https://reviews.llvm.org/D85968
2020-08-17 11:09:13 +02:00
Raphael Isemann 867c347c32 [lldb] Fix that log enable's -f parameter causes LLDB to crash when it can't open the log file
We didn't do anything with the llvm::Error we get from `Open`, so when we end up in the
error case we just crash due to the llvm::Error sanity check. Also add the missing newline
behind the error message so it no longer messes with the next (lldb) prompt.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D85970
2020-08-17 10:43:00 +02:00
Raphael Isemann 7208cb1ac4 [lldb] Remove XFAIL from now passing TestPtrRefs/TestPtreRefsObjC
8fcfe2862f and
0cceb54366 fixed those tests.
2020-08-15 08:14:44 +02:00
Davide Italiano 0cceb54366 [TestPtrRefsObjC] Prefer `command script import`. 2020-08-14 15:31:02 -07:00
Davide Italiano 8fcfe2862f [TestPtrRefs] Prefer `command script import`. 2020-08-14 15:30:31 -07:00
Jim Ingham b6db0a544d Add python enumerators for SBTypeEnumMemberList, and some tests for this API.
Differential Revision: https://reviews.llvm.org/D85951
2020-08-14 09:57:46 -07:00
Jonas Devlieghere 37ec83fcfc [lldb] Use file to synchronize TestDeepBundle and TestBundleWithDotInFilename
Currently these two tests use an arbitrary wait of 5 seconds for the
inferior to finish setting up. When the test machine is under heavy load
this sometimes is insufficient leading to spurious test failures. This
patch adds synchronization trough a token on the file system. In
addition to making the test more reliable it also makes it much faster
because we no longer have to wait the full 5 seconds if the setup was
completed faster than that.

Differential revision: https://reviews.llvm.org/D85915
2020-08-14 08:32:21 -07:00
Raphael Isemann bb4efab9a4 [lldb] Use SBProcess::Continue instead of 'run' command in TestTargetAPI.py
This test is flaky on Green Dragon as it often fails when the process state
is "Invalid" in the assert:
    self.assertEqual(process.GetState(), lldb.eStateExited)
It seems this is related to just doing "run" which apparently invalidates
the Target's process in case it's still running and needs to be restarted.
Just doing 'continue' on the process (and ignoring the error in case it already
finished) prevents that and makes this consistently pass for me.

Just pushing this out to get Green Dragon back online.
2020-08-14 13:12:52 +02:00
Pavel Labath fdc6aea3fd [lldb] Check Decl kind when completing -flimit-debug-info types
The search for the complete class definition can also produce entries
which are not of the expected type. This can happen for instance when
there is a function with the same name as the class we're looking up
(which means that the class needs to be disambiguated with the
struct/class tag in most contexts).

Previously we were just picking the first Decl that the lookup returned,
which later caused crashes or assertion failures if it was not of the
correct type. This patch changes that to search for an entry of the
correct type.

Differential Revision: https://reviews.llvm.org/D85904
2020-08-14 12:31:37 +02:00
Shu Anzai de9e85026f [lldb] Display autosuggestion part in gray if there is one possible suggestion
This is relanding D81001. The patch originally failed as on newer editline
versions it seems CC_REFRESH will move the cursor to the start of the line via
\r and then back to the original position. On older editline versions like
the one used by default on macOS, CC_REFRESH doesn't move the cursor at all.
As the patch changed the way we handle tab completion (previously we did
REDISPLAY but now we're doing CC_REFRESH), this caused a few completion tests
to receive this unexpected cursor movement in the output stream.
This patch updates those tests to also accept output that contains the specific
cursor movement commands (\r and then \x1b[XC). lldbpexpect.py received an
utility method for generating the cursor movement escape sequence.

Original summary:

I implemented autosuggestion if there is one possible suggestion.
I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called.
Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k.
Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it.

Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now.

Reviewed By: teemperor, JDevlieghere, #lldb

Differential Revision: https://reviews.llvm.org/D81001
2020-08-14 11:37:49 +02:00
Raphael Isemann bbe3c479a6 [lldb] Fix a crash when tab-completion an empty line in a function with only one local variable
When LLDB sees only one possible completion for an input, it will add a trailing
space to the completion to signal that to the user. If the current argument is
quoted, that also means LLDB needs to add the trailing quote to finish the
current argument first.

In case the user is in a function with only one local variable and is currently
editing an empty line in the multiline expression editor, then we are in the
unique situation where we can have a unique completion for an empty input line.
(In a normal LLDB session this would never occur as empty input would just list
all the possible commands).

In this special situation our check if the current argument needs to receive a
trailing quote will crash LLDB as there is no current argument and the
completion code just unconditionally tries to access the current argument. This
just adds the missing check if we even have a current argument before we check
if we need to add a terminating quote character.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D85903
2020-08-14 09:06:52 +02:00
shafik 25bbceb047 [LLDB] Fix how ValueObjectChild handles bit-fields stored in a Scalar in UpdateValue()
When bit-field data was stored in a Scalar in ValueObjectChild during UpdateValue()
it was extracting the bit-field value. Later on in lldb_private::DumpDataExtractor(…)
we were again attempting to extract the bit-field. Which would then not obtain the
correct value. This will remove the extra extraction in UpdateValue().
We hit this specific case when values are passed in registers, which we could only
reproduce in an optimized build.

Differential Revision: https://reviews.llvm.org/D85376
2020-08-13 11:53:14 -07:00
Jonas Devlieghere 2ddba09e06 [lldb] Set the launch flags to GetLaunchInfo().GetLaunchFlags()
Instead of clearing the launch flags, always pass the target's current
launch flags.
2020-08-13 10:24:35 -07:00
Jonas Devlieghere 180d6ed667 [lldb] Skip TestStepScripted with reproducers
Some of the test methods were already skipped because of an unexpected
packet. The test started failing after it was expanded. Skip the whole
test with reproducers so we don't have to add the decorator for every
method.
2020-08-13 09:46:52 -07:00
Raphael Isemann cff880b0c9 Revert "[lldb] Display autosuggestion part in gray if there is one possible suggestion"
This reverts commit 246afe0cd1. This broke
the following tests on Linux it seems:
  lldb-api :: commands/expression/multiline-completion/TestMultilineCompletion.py
  lldb-api :: iohandler/completion/TestIOHandlerCompletion.py
2020-08-12 13:52:03 +02:00
Shu Anzai 246afe0cd1 [lldb] Display autosuggestion part in gray if there is one possible suggestion
I implemented autosuggestion if there is one possible suggestion.
I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called.
Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k.
Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it.

Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now.

Reviewed By: teemperor, JDevlieghere, #lldb

Differential Revision: https://reviews.llvm.org/D81001
2020-08-12 13:11:20 +02:00
Raphael Isemann dd0fdf8030 [lldb] Add support for checking children in expect_expr
expect_expr currently can't verify the children of the result SBValue.

This patch adds the ability to check them. The idea is to have a CheckValue
class where one can specify what attributes of a SBValue should be checked.
Beside the properties we already check for (summary, type, etc.) this also
has a list of children which is again just a list of CheckValue object (which
can also have children of their own).

The main motivation is to make checking the children no longer based
on error-prone substring checks that allow tests to pass just because
for example the error message contains the expected substrings by accident.

I also expect that we can just have a variant of `expect_expr` for LLDB's
expression paths (aka 'frame var') feature.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D83792
2020-08-12 12:11:24 +02:00
Adrian McCarthy 479f5bfdb0 [LLDB] Improve PDB discovery
When loading a PE/COFF target, the associated PDB file often wasn't
found.  The executable module contains a path for the associated PDB
file, but people often debug from a different directory than the one
their build system uses.  (This is especially common in post-mortem
and cross platform debugging.)

Suppose the COFF executable being debugged is `~/proj/foo.exe`, but
it was built elsewhere and refers to `D:\remote\build\env\foobar.pdb`,
LLDB wouldn't find it.

With this change, if no file exists at the PDB path, LLDB will look
in the executable directory for a PDB file that matches the name of
the one it expected (e.g., `~/proj/foobar.pdb`).  If found, the PDB
is subject to the same matching criteria (GUIDs and age) as would
have been used had it been in the original location.

This same-directory-as-the-binary rule is commonly used by debuggers
on Windows.

Differential Review: https://reviews.llvm.org/D84815
2020-08-11 13:44:14 -07:00
Jonas Devlieghere 254e0abf5b [lldb] Fix the last remaining tests not inheriting TCC permissions
After this patch all test should have the inferior inheriting the TCC
permissions from its parent.
2020-08-11 12:50:36 -07:00
Jonas Devlieghere 7adf5bd181 [lldb] Look beyond the first line to find the PID in TestAppleSimulatorOSType
The current code fails when the first stderr line doesn't match the
given regex to parse the PID. This patch changes the code to read the
first 10 lines before giving up. It also adds tracing for the simctl
commands.
2020-08-11 11:07:04 -07:00
Raphael Isemann 950f1bf976 [lldb] Add SubstTemplateTypeParm to RemoveWrappingTypes
Like the other type sugar removed by RemoveWrappingTypes, SubstTemplateTypeParm
is just pure sugar that should be ignored. If we don't ignore it (as we do now),
LLDB will fail to read values from record fields that have a
SubstTemplateTypeParm type.

Only way to produce such a type in LLDB is to either use the `import-std-module`
setting to get a template into the expression parser or just create your own
template directly in the expression parser which is what we do in the test.

Reviewed By: jarin

Differential Revision: https://reviews.llvm.org/D85132
2020-08-11 14:31:47 +02:00
Gongyu Deng 4f3559db1f [lldb] watchpoint ID common completion for commands `watchpoint delete/enable/disable/modify/ignore`
1. Added a common completion WatchPointIDs to complete with a list of the IDs of the current watchpoints;
2. Applied the completion to these commands: watchpoint delete/enable/disable/modify/ignore;
3. Added a correlated test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84104
2020-08-11 14:25:09 +02:00
Gongyu Deng a952fe236f [lldb] thread index common completion for commands like `thread select/step-over`
1. Added a common completion completing with a list of the threads of the current process;
2. Apply the common completion above to these commands: thread
   continue/info/exception/select/step-in/step-inst/step-inst-over/step-out/step-over/step-script​
3. Correlated test case test_common_completion_thread_index.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84088
2020-08-11 13:27:13 +02:00
Gongyu Deng b2b7dbb47a [lldb] stop-hook ID common completion for commands `target stop-hook enable/disable/delete'
1. Added a common completion StopHookIDs to provide completion with a list of stop hook ids;
2. Applied the common completion to commands: `target stop-hook delete/enable/disable';
3. Added an related test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84123
2020-08-11 13:14:27 +02:00
Gongyu Deng 419f1be7b5 [lldb] tab completion for `target modules load -u`
1. Added a common completion ModuleUUIDs to provide a list of the UUIDs of modules for completion;
2. Added a new enumeration item eArgTypeModuleUUID to CommandArgumentType which is set as the option argument type of OptionGroupUUID;
3. Applied the module UUID completion to the argument of the type eArgTypeModuleUUID in lldb/source/Interpreter/CommandObject.cpp;
4. Added an related test case in lldb/test/API/functionalities/completion/TestCompletion.py.
2020-08-11 12:35:36 +02:00
Gongyu Deng 66fa73fa27 [lldb] move the frame index completion into a common completion and apply it to `thread backtrace -s`
Commands frame select and thread backtrace -s can be completed in the same way.
Moved the dedicated completion of frame select into a common completion and
apply it to the both commands, along with the test modified.
2020-08-11 12:25:39 +02:00
Gongyu Deng 24bc8afd4b [lldb] tab completion for `target modules search-paths insert​`
Dedicated completion for the command `target modules search-paths insert​` with a test case.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D83309
2020-08-11 11:58:14 +02:00
Gongyu Deng 3ce57e0121 [lldb] type language common completion
1. Added a new common completion TypeLanguages to provide a list of supporting languages;
2. Bound the completion to eArgTypeLanguage;
3. Added a related test case.
2020-08-11 11:07:19 +02:00
Gongyu Deng 31fd64ac57 [lldb] tab completion for 'command delete/unalias'
Provided dedicated tab completions for `command delete/unalias`.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D81128
2020-08-11 10:27:04 +02:00
Gongyu Deng f99a18bbaa [lldb] tab completion for `thread plan discard`
Dedicated completion for the command `thread plan discard` with a corresponding
test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D83234
2020-08-11 10:08:16 +02:00
Gongyu Deng 8a5e296975 [lldb] tab completion for `disassemble -F`
1.Added a new common completion DisassemblyFlavors;

2. Bound DisassemblyFlavors to argument of type eArgTypeDisassemblyFlavor in
CommandObject.cpp;

3. Added a related test case.
2020-08-11 10:01:45 +02:00
Gongyu Deng 2e653327e3 [lldb] tab completion for `watchpoint set variable`
1. Applied the common completion `eVariablePathCompletion` to command
`watchpoint set variable`;

2. Added a related test case.

Reviewed By: teemperor, JDevlieghere

Differential Revision: https://reviews.llvm.org/D84177
2020-08-11 09:51:55 +02:00
Gongyu Deng e3820570d4 [lldb] tab completion for `platform target-install`
1. Applied the common completion `eDiskFileCompletion` to the first argument of
the command `platform target-install`.
2. Added a related test case.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D84179
2020-08-10 20:14:46 +02:00
Jonas Devlieghere 3162c6aa45 [lldb] Skip TestSimulatorPlatform with out-of-tree debugserver 2020-08-10 10:00:45 -07:00
Jonas Devlieghere b8ff0daeac [lldb] Fix NSArray0 data formatter and add test
Fixes PR47089
2020-08-10 09:38:37 -07:00
Jonas Devlieghere a97dfdc30b [lldb] Assert the process has exited before we gets its output. 2020-08-07 15:06:38 -07:00
Jim Ingham d3dfd8cec4 Add a setting to force stepping to always run all threads.
Also allow ScriptedThreadPlans to set & get their StopOthers
state.

<rdar://problem/64229484>

Differential Revision: https://reviews.llvm.org/D85265
2020-08-07 14:47:31 -07:00
Jonas Devlieghere dbf44b8330 [LLDB] Mark test_launch_simple as a no-debug-info test
No need to run this test with the multiple variants.
2020-08-06 23:18:37 -07:00
Adrian Prantl 0fa520af67 Unify the code that updates the ArchSpec after finding a fat binary
with how it is done for a lean binary

In particular this affects how target create --arch is handled — it
allowed us to override the deployment target (a useful feature for the
expression evaluator), but the fat binary case didn't.

rdar://problem/66024437

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

(cherry picked from commit 470bdd3caaab0b6e0ffed4da304244be40b78668)
2020-08-06 13:30:17 -07:00
Adrian Prantl f406a90a08 Add missing override to Makefile 2020-08-06 13:07:16 -07:00
Jonas Devlieghere ba37b144e6 [LLDB] Skip test_launch_simple from TestTargetAPI.py when remote 2020-08-06 13:03:18 -07:00
Adrian Prantl 05df9cc703 Correctly detect legacy iOS simulator Mach-O objectfiles
The code in ObjectFileMachO didn't disambiguate between ios and
ios-simulator object files for Mach-O objects using the legacy
ambiguous LC_VERSION_MIN load commands. This used to not matter before
taught ArchSpec that ios and ios-simulator are no longer compatible.

rdar://problem/66545307

Differential Revision: https://reviews.llvm.org/D85358
2020-08-06 12:40:45 -07:00
Jonas Devlieghere 86aa8e6363 [lldb] Use target.GetLaunchInfo() instead of creating an empty one.
Update tests that were creating an empty LaunchInfo instead of using the
one coming from the target. This ensures target properties are honored.
2020-08-06 11:51:26 -07:00
Fangrui Song a6db64ef4a [ELF] Allow sections after a non-SHF_ALLOC section to be covered by PT_LOAD
GNU ld allows sections after a non-SHF_ALLOC section to be covered by PT_LOAD
(PR37607) and assigns addresses to non-SHF_ALLOC output sections (similar to
SHF_ALLOC NOBITS sections. The location counter is not advanced).

This patch tries to fix PR37607 (remove a special case in
`Writer<ELFT>::createPhdrs`). To make the created PT_LOAD meaningful, we cannot
reset dot to 0 for a middle non-SHF_ALLOC output section. This results in
removal of two special cases in LinkerScript::assignOffsets. Non-SHF_ALLOC
non-orphan sections can have non-zero addresses like in GNU ld.

The zero address rule for non-SHF_ALLOC sections is weakened to apply to orphan
only. This results in a special case in createSection and findOrphanPos, respectively.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85100
2020-08-06 08:27:15 -07:00
David Spickett e82866d5d9 [lldb][AArch64] Correct compile options for Neon corefile
SVE is not required, it has its own test. Note that
there is no "+neon" so "+simd" is used instead.

Also rename the file to match the name of the corefile
it produces.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D85134
2020-08-06 13:39:09 +01:00
Muhammad Omair Javaid 94a5919946 [LLDB] Skip test_launch_simple from TestTargetAPI.py on Arm/AArch64 Linux
Recently added TestTargetAPI.py test "test_launch_simple" is failing on
Arm/AArch64 Linux targets. Putting them to skip until fixed.

Differential Revision: https://reviews.llvm.org/D85235
2020-08-06 17:38:20 +05:00
Luboš Luňák fc0e8fb787 [lldb][gui] truncate long lines/names if needed
Without this, sources with long lines or variable names may overwrite
panel frames, or even overrun to the following line. There's currently
no way to scroll left/right in the views, so that should be added
to handle these cases.
This commit includes fixing constness of some Window functions,
and also makes PutCStringTruncated() consistent with the added
printf-like variant to take the padding as the first argument (can't
add it after the format to the printf-like function).

Differential Revision: https://reviews.llvm.org/D85123
2020-08-06 08:40:42 +02:00
Jim Ingham 08063f85a7 "|" used when "||" was meant in SBTarget::FindFunctions 2020-08-05 19:02:00 -07:00
Jonas Devlieghere 3a538de653 [lldb] Make UBSan tests remote ready
Add missing call to registerSanitizerLibrariesWithTarget.
2020-08-05 18:31:43 -07:00
Jonas Devlieghere 927afdffbb [lldb] Skip test_launch_simple on Windows
Because stdio manipulation unsupported on Windows.
2020-08-05 15:38:07 -07:00