Commit Graph

23709 Commits

Author SHA1 Message Date
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
Raphael Isemann d0ee1d8efe [lldb][NFC] Make GetShellSafeArgument simpler and faster
Escaping by inserting characters in the middle of a std::string isn't cheap.
It's much more verbose than just prepending a backslash in a loop.
2020-10-26 15:29:13 +01:00
Pavel Labath e4cc6e9bcd [lldb] Modernize PseudoTerminal::Fork 2020-10-26 12:01:20 +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 f5ca27569e [lldb] [Process/Linux] Reuse NativeRegisterContextWatchpoint_x86
Differential Revision: https://reviews.llvm.org/D90119
2020-10-26 11:55:22 +01:00
Michał Górny a890237665 [lldb] [Process/NetBSD] Set xs_xstate_bv correctly when setting regs
Ensure that xs_xstate_bv is set correctly before calling
WriteRegisterSet().  The bit can be clear if the relevant registers
were at their initial state when they were read, and it needs to be set
in order to apply changes from the XState structure.

Differential Revision: https://reviews.llvm.org/D90105
2020-10-26 11:54:40 +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
Michał Górny 7acf2e2e1e [lldb] [Process/FreeBSDRemote] Fix #include for i386 compat
Include <x86/fpu.h> rather than <machine/fpu.h>, as the latter is not
present on i386.

Differential Revision: https://reviews.llvm.org/D90128
2020-10-26 11:53:26 +01:00
Michał Górny d96cb52830 [lldb] [Process/NetBSD] Use XStateRegSet for all FPU registers
Unify the x86 regset API to use XStateRegSet for all FPU registers,
therefore eliminating the legacy API based on FPRegSet.  This makes
the code a little bit simpler but most notably, it provides future
compatibility for register caching.

Since the NetBSD kernel takes care of providing compatibility with
pre-XSAVE processors, PT_{G,S}ETXSTATE can be used on systems supporting
only FXSAVE or even plain FSAVE (and unlike PT_{G,S}ETXMMREGS, it
clearly indicates that XMM registers are not supported).

Differential Revision: https://reviews.llvm.org/D90034
2020-10-24 09:17:53 +02:00
Martin Storsjö 84ce6b9991 [lldb] Fix building with GCC 7. NFC. 2020-10-24 09:33:01 +03:00
David Blaikie 0b05732045 fix lldb for recent libDebugInfoDWARF API change 2020-10-23 19:20:38 -07:00
Walter Erquinigo 48d8af9825 [intel-pt] Disable/Enable tracing to guarantee the trace is correct
As mentioned in the comment inside the code, the Intel documentation
states that the internal CPU buffer is flushed out to RAM only when tracing is
disabled. Otherwise, the buffer on RAM might be stale.

This diff disables tracing when the trace buffer is going to be read. This is a
quite safe operation, as the reading is done when the inferior is paused at a
breakpoint, so we are not losing any packets because there's no code being
executed.

After the reading is finished, tracing is enabled back.

It's a bit hard to write a test for this now, but Greg Clayton and I will
refactor the PT support and writing tests for it will be easier. However
I tested it manually by doing a script that automates
the following flow

```
(lldb) b main
Breakpoint 1: where = a.out`main + 15 at main.cpp:4:7, address = 0x000000000040050f
(lldb) r
Process 3078226 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000000000040050f a.out`main at main.cpp:4:7
(lldb) processor-trace start
(lldb) b 5
Breakpoint 2: where = a.out`main + 22 at main.cpp:5:12, address = 0x0000000000400516
(lldb) c
Process 3078226 resuming
Process 3078226 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 2.1
frame #0: 0x0000000000400516 a.out`main at main.cpp:5:12
(lldb) processor-trace show-instr-log
thread #1: tid=3078226
0x40050f <+15>: movl $0x0, -0x8(%rbp)

>>> Before, some runs of the script up to this point lead to empty traces

(lldb) b 6
Breakpoint 3: where = a.out`main + 42 at main.cpp:6:14, address = 0x000000000040052a
(lldb) c
Process 3092991 resuming
Process 3092991 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 3.1
frame #0: 0x000000000040052a a.out`main at main.cpp:6:14
(lldb) processor-trace show-instr-log thread #1: tid=3092991
0x40050f <+15>: movl $0x0, -0x8(%rbp)
0x400516 <+22>: movl $0x0, -0xc(%rbp)
0x40051d <+29>: cmpl $0x2710, -0xc(%rbp) ; imm = 0x2710
0x400524 <+36>: jge 0x400546 ; <+70> at main.cpp
0x400524 <+36>: jge 0x400546 ; <+70> at main.cpp

>>> The trace was re-enabled correctly and includes the instruction of the
first reading.
```
Those instructions correspond to these lines
```
3 int main() {
4 int z = 0;
5 for (int i = 0; i < 10000; i++) {
6 z += fun(z)
...
```

Differential Revision: https://reviews.llvm.org/D85241
2020-10-23 16:36:42 -07: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 a4459feca4 [lldb] Fix use of undefined type 'lldb_private::UtilityFunction'
We were returning the default constructed unique_pointer from
TypeSystem.h for which the compiler does not have a definition. Move the
implementation into the cpp file.
2020-10-23 11:48:11 -07:00
Jonas Devlieghere de346cf2ac [lldb] Redesign Target::GetUtilityFunctionForLanguage API
This patch redesigns the Target::GetUtilityFunctionForLanguage API:

 - Use a unique_ptr instead of a raw pointer for the return type.
 - Wrap the result in an llvm::Expected instead of using a Status object as an I/O parameter.
 - Combine the action of "getting" and "installing" the UtilityFunction as they always get called together.
 - Pass std::strings instead of const char* and std::move them where appropriate.

There's more room for improvement but I think this tackles the most
prevalent issues with the current API.

Differential revision: https://reviews.llvm.org/D90011
2020-10-23 10:00:23 -07:00
Michał Górny dae7b10034 [lldb] Split out NetBSD/x86 watchpoint impl for unification
Split the current NetBSD watchpoint implementation for x86 into Utility,
and revamp it to improve readability.  This code is meant to be used
as a common class for all x86 watchpoint implementation, particularly
these on FreeBSD and Linux.

The code uses global watchpoint enable bits, as required by the NetBSD
kernel.  If it ever becomes necessary for any platform to use local
enable bits instead, this can be trivially abstracted out.

The code also postpones clearing DR6 until a new different watchpoint
is being set in place of the old one.  This is necessary since LLDB
repeatedly reenables watchpoints on all threads, by clearing
and restoring them.  When DR6 is cleared as a part of that, then pending
events on other threads can no longer be associated with watchpoints
correctly.

Differential Revision: https://reviews.llvm.org/D89874
2020-10-23 12:20:15 +02:00
Jonas Devlieghere 3590a8319a [lldb] Fix bug instroduced by a00acbab45
g_expression_prefix, as the name implies, must be perfixed, not
suffixed.
2020-10-22 22:17:11 -07:00
Jonas Devlieghere a00acbab45 [lldb] Fix missing initialization in UtilityFunction ctor (NFC)
The UtilityFunction ctor was dropping the text argument. Probably for
that reason ClangUtilityFunction was setting the parent's member
directly instead of deferring to the parent ctor. Also change the
signatures to take strings which are std::moved in place.
2020-10-22 21:12:27 -07:00
Raphael Isemann 5dc70332d5 Revert "[lldb] Explicitly use the configuration architecture when building test executables"
This reverts commit 41185226f6.

Causes TestQuoting to fail on Windows.
2020-10-22 18:42:19 +02:00
Med Ismail Bennani efe62b637d [lldb/DWARF] Add support for DW_OP_implicit_value
This patch completes https://reviews.llvm.org/D83560. Now that the
compiler can emit `DW_OP_implicit_value` into DWARF expressions, lldb
needed to learn reading these opcodes for variable inspection and
expression evaluation.

This implicit location descriptor specifies an immediate value with two
operands: the length (ULEB128) followed by a block representing the value
in the target memory representation.

rdar://67406091

Differential revision: https://reviews.llvm.org/D89842

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-10-22 18:02:44 +02: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
Raphael Isemann 41185226f6 [lldb] Explicitly use the configuration architecture when building test executables
The Darwin builder currently assumes in `getArchCFlags` that the passed `arch`
value is an actual string it can string.join with vendor/os/version/env strings:

```
   triple = '-'.join([arch, vendor, os, version, env])
```

However this is not true for most tests as we just pass down the `arch=None`
default value from `TestBase.build`. This causes that if we actually end up in
this function we just error out when concatenating `None` with the other actual
strings of vendor/os/version/env. What we should do instead is check that if
there is no test-specific architecture that we fall back to the configuration's
architecture value.

It seems we already worked around this in `builder.getArchSpec` by explicitly
falling back to the architecture specified in the configuration.

This patch just moves this fallback logic to the top `build` function so that it
affects all functions called from `TestBase.build`.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D89056
2020-10-22 15:30:25 +02:00
Raphael Isemann bb1d702e25 [lldb][NFC] Make GetShellSafeArgument return std::string and unittest it. 2020-10-22 14:47:10 +02:00
Pavel Labath d900b755ed [lldb] Fix windows build for fa5fa63fd1 2020-10-21 17:51:11 +02:00
Christopher Tetreault 26459e6d8e Fix "Unknown arguments specified" to if in lldb
Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D89807
2020-10-21 07:24:53 -07: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
Sylvestre Ledru 0784e17f1b Remove .svn from exclude list as we moved to git
Reviewed By: emaste

Differential Revision: https://reviews.llvm.org/D89859
2020-10-21 16:09:21 +02:00
Jan Kratochvil 7bf066a20f [nfc] [lldb] Fix harmless slicing of DWARFDIE
Differential Revision: https://reviews.llvm.org/D89875
2020-10-21 15:49:53 +02:00
Jonas Devlieghere c565f09f4b [lldb] Don't strip LLDB.framework on install
The framework build will run dsymutil after LLDB.framework is installed.
2020-10-20 18:16:36 -07:00
Jonas Devlieghere de6f3d1c71 [lldb] Add a page to the docs with (external) links on how to use LLDB
In a discussion with Jim last week we came to the realization that often
we get asked about things that might not be documented on the website,
but that have been pretty well explained elsewhere. In those situations
it's often easier to quickly answer the question than searching for that
presentation you gave 3 years ago if you remember at all.

This often results in us having to answer the same questions over and
over again. We could add the questions and their answer to the website,
but that means we (1) have to duplicate the work and (2) now have to
maintain it.

A more efficient solution is to add a page with external resources with
the caveat that they might be outdated. That's exactly the purpose of
this patch.

I've added a few links that came to mind, but I don't want to be the
arbiter of what should and should not be included. I'd hope that over
time the community can crowd-source the best resources.

Differential revision: https://reviews.llvm.org/D89215
2020-10-20 11:43:31 -07:00
Duncan P. N. Exon Smith b333d6e129 lldb: Migrate to MemoryBufferRef for createFileID (after 51d1d585e5)
I missed these two lldb users before deleting the `UnownedTag` API for
`createFileID` in 51d1d585e5. This should
fix the build.
2020-10-20 13:52:39 -04:00
Jason Molenda c932266c8d Add a nul byte to packet str before logging, increase default size.
Add a nul byte to the stream in CommunicationKDP::CheckForPacket
before we send the GetData() to a Log::Printf as a c-str.  Avoids
a crash when logging kdp communications and memory layout isn't
in your favor.
2020-10-20 01:43:31 -07:00
Duncan P. N. Exon Smith f96e16bc15 lldb: Update for change in `clang::Lexer`'s constructor
b3eff6b7bb updated `Lexer::Lexer` to take
`clang::MemoryBufferRef` instead of `clang::MemoryBuffer*`. Update LLDB
to fix the bots.
2020-10-19 20:09:27 -04:00
Walter Erquinigo 8a203bb22d [trace] rename ThreadIntelPT into TraceTrace
Renamed ThreadIntelPT to TreaceThread, making it a top-level class. I noticed that this class can and shuld work for any trace plugin and there's nothing intel-pt specific in it.
With that TraceThread change, I was able to move most of the json file parsing logic to the base class TraceSessionFileParser, which makes adding new plug-ins easier.

This originally was part of https://reviews.llvm.org/D89283

Differential Revision: https://reviews.llvm.org/D89408
2020-10-19 15:15:02 -07:00
Alexandre Ganea 89b72209ad [LLDB][TestSuite] Improve skipIfWindowsAndNonEnglish in decorators.py
Differential Revision: https://reviews.llvm.org/D89716
2020-10-19 14:28:08 -04:00
Jan Kratochvil 0e5248be86 [nfc] [lldb] Move LookupAddress to DWARFCompileUnit
LookupAddress makes no sense for DWARFTypeUnit.
Also make GetNonSkeletonUnit to preserve the called type.

Differential Revision: https://reviews.llvm.org/D89646
2020-10-19 12:44:33 +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
Jan Kratochvil 224caaf69b [nfc] [lldb] Delete an empty trailing line.
A patchset being prepared shows needless diffs.
2020-10-18 10:16:00 +02:00
Dave Lee ae4fe1984f [lldb] Enable cmake policy CMP0077 for option()
In lldb, explicitly set the "option() honors normal variables" CMake policy. This applies for
standalone lldb builds and matches what llvm, clang, etc do. This prevents potentially unwanted
clearing of variables like `LLVM_ENABLE_WARNINGS`, and also prevents unnecessary build warnings.

See: https://cmake.org/cmake/help/latest/policy/CMP0077.html

Differential Revision: https://reviews.llvm.org/D89614
2020-10-17 00:16:24 -07:00
Jason Molenda 32021eeff0 Un-indent the section on 'Writing Target Stop-Hooks in Python'
it was ending up in a code block from the previous section,
instead of being its own section.
2020-10-16 23:23:25 -07: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
Dave Lee f16cecf375 [lldb] Implement ObjCExceptionThrowFrameRecognizer::GetName()
Implement `GetName` for `ObjCExceptionThrowFrameRecognizer`. Otherwise, `frame recognizer list` shows "(internal)" for the name.

Differential Revision: https://reviews.llvm.org/D89589
2020-10-16 14:24:03 -07:00
Adrian Prantl cf24508651 Add support for more OS types to AddClangModuleCompilationOptionsForSDKType()
This patch also avoids hardcoding the clang options, which makes it
less likely for them to become out-of-date.

rdar://problem/63791367+66927829

Differential Revision: https://reviews.llvm.org/D89428
2020-10-16 11:43:22 -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
Pavel Labath daae4a8482 [lldb] Modernize PseudoTerminal::OpenSecondary 2020-10-16 15:22:55 +02:00
Pavel Labath e338ca7bce [lldb] Fix FreeBSD build for ea3a547 2020-10-16 13:50:53 +02:00