Commit Graph

12911 Commits

Author SHA1 Message Date
Jan Kratochvil 1d11d5f624 [lldb] [NFC] Refactor GetDWARFDeclContext to return DWARFDeclContext
Suggested by Pavel Labath.

Differential Revision: https://reviews.llvm.org/D73787
2020-02-06 20:06:28 +01:00
Pavel Labath 31cf581998 [lldb] Explicitly qualify calls to std::static_pointer_cast
Due to a c++ quirk, these are found through ADL only when a function with that
name is found through regular lookup. We have one such function in SharingPtr.h,
but I am trying to remove it.
2020-02-06 10:55:16 -08:00
Med Ismail Bennani 17d0091d66 [lldb/Target] Remove extra semicolon in AssertFrameRecognizer (NFC)
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-06 19:46:32 +01:00
Med Ismail Bennani 7ebe9cc4fc [lldb/Target] Add Assert StackFrame Recognizer
When a thread stops, this checks depending on the platform if the top frame is
an abort stack frame. If so, it looks for an assert stack frame in the upper
frames and set it as the most relavant frame when found.

To do so, the StackFrameRecognizer class holds a "Most Relevant Frame" and a
"cooked" stop reason description. When the thread is about to stop, it checks
if the current frame is recognized, and if so, it fetches the recognized frame's
attributes and applies them.

rdar://58528686

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-06 18:27:48 +01:00
Martin Storsjö 5bbaf54358 [LLDB] Fix compilation with GCC 5
Differential Revision: https://reviews.llvm.org/D74084
2020-02-06 10:16:32 +02:00
Jonas Devlieghere 3da7dcf38a [lldb/Reproducers] Serialize empty string for char* methods.
For the methods taking a char* and a length that have a custom replayer,
ignore the incoming string in the instrumentation macro. This prevents
potentially reading garbage and blowing up the SB API log.
2020-02-05 21:55:36 -08:00
Pavel Labath e3aa062ae9 [lldb/DWARF] Don't assume that a SymbolFileDWARFDwo contains one compile unit
Summary:
This is a preparatory patch to re-enable DWP support in lldb (we already
have code claiming to do that, but it has been completely broken for a
while now).

The idea of the new approach is to make the SymbolFileDWARFDwo class
handle both dwo and dwo files, similar to how llvm uses one DWARFContext
to handle the two.

The first step is to remove the assumption that a SymbolFileDWARFDwo
holds just a single compile unit, i.e. the GetBaseCompileUnit method.
This requires changing the way how we reach the skeleton compile unit
(and the lldb_private::CompileUnit) from a dwo unit, which was
previously done via GetSymbolFile()->GetBaseCompileUnit() (and some
virtual dispatch).

The new approach reuses the "user data" mechanism of DWARFUnits, which
was used to link dwarf units (both skeleton and split) to their
lldb_private counterparts. Now, this is done only for non-dwo units, and
instead of that, the dwo units holds a pointer to the relevant skeleton
unit.

Reviewers: JDevlieghere, aprantl, clayborg

Reviewed By: JDevlieghere, clayborg

Subscribers: arphaman, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73781
2020-02-05 20:37:56 -08:00
Jonas Devlieghere 2f025bb87c [lldb/Reproducers] Implement custom replayers for (char *, size_t)
Some SB API methods returns strings through a char* and a length. This
is a problem for the deserializer, which considers a single type at a
time, and therefore cannot know how many bytes to allocate for the
character buffer.

We can solve this problem by implementing a custom replayer, which
ignores the passed-in char* and allocates a buffer of the correct size
itself, before invoking the original API method or function.

This patch adds three new macros to register a custom replayer for
methods that take a char* and a size_t. It supports arbitrary return
values (some functions return a bool while others return a size_t).
2020-02-05 19:59:38 -08:00
Pavel Labath 40efa65de8 Revert "[LLDB] Add DynamicLoaderWasmDYLD plugin for WebAssembly debugging"
This patch has a couple of outstanding issues. The test is not python3
compatible, and it also seems to fail with python2 (at least under some
circumstances) due to an overambitious assertion.

This reverts the patch as well as subsequent fixup attempts:
014ea93376,
f5f70d1c8f.
4697e701b8.
5c15e8e682.
3ec28da6d6.
2020-02-05 16:22:19 -08:00
Pavel Labath 98b273c893 Revert "[lldb/Target] Add Assert StackFrame Recognizer"
This reverts commit 2b7f32892b because of test
failures due to dangling pointers.
2020-02-05 15:51:38 -08:00
Derek Schuff f5f70d1c8f Add missing directory from 3ec28da6
Also revert 4697e701b8, restoring the original patch from
https://reviews.llvm.org/D72751
2020-02-05 15:49:48 -08:00
Jonas Devlieghere 4697e701b8 Partially revert "[LLDB] Add DynamicLoaderWasmDYLD plugin for WebAssembly debugging"
This temporarily and partially reverts 3ec28da6d6 because it's missing
a directory.
2020-02-05 15:32:54 -08:00
Med Ismail Bennani 42c906bcef [lldb/API] Fix non null-terminated stop-reason in SBThread::GetStopDescription
When trying to get the stop reason description using the SB API, the
buffer fetched was not null-terminated causing failures on the sanitized bot.

This patch should address those failures.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-06 00:20:33 +01:00
Jonas Devlieghere 5c15e8e682 [lldb/CMake] Remove non-existing wasm-DYLD subdir 2020-02-05 15:08:18 -08:00
Paolo Severini 3ec28da6d6 [LLDB] Add DynamicLoaderWasmDYLD plugin for WebAssembly debugging
Add a dynamic loader plug-in class for WebAssembly modules.

Differential Revision: https://reviews.llvm.org/D72751
2020-02-05 14:49:36 -08:00
Med Ismail Bennani 2b7f32892b [lldb/Target] Add Assert StackFrame Recognizer
When a thread stops, this checks depending on the platform if the top frame is
an abort stack frame. If so, it looks for an assert stack frame in the upper
frames and set it as the most relavant frame when found.

To do so, the StackFrameRecognizer class holds a "Most Relevant Frame" and a
"cooked" stop reason description. When the thread is about to stop, it checks
if the current frame is recognized, and if so, it fetches the recognized frame's
attributes and applies them.

rdar://58528686

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-05 17:49:13 +01:00
Raphael Isemann 7506ca3e8c [lldb][NFC] Remove some unnecessary curly braces 2020-02-05 13:47:09 +01:00
Michał Górny 5cc817be75 [lldb] Introduce i386 support in NetBSD Process plugin
Introduce support for i386 platform that is shared with amd64
in the same plugin.  The concept is partially based on the Linux
implementation.

The plugin tries to reuse as much code as possible.  As a result, i386
register enums are mapped into amd64 values and those are used in actual
code.  The code for accessing FPU and debug registers is shared,
although general-purpose register layouts do not match between the two
kernel APIs and need to be #ifdef-ed.

This layout will also make it possible to add support for debugging
32-bit programs on amd64 with minimal added code.

In order for this to work, I had to add missing data for debug registers
on i386.

Differential Revision: https://reviews.llvm.org/D73802
2020-02-05 13:31:06 +01:00
Raphael Isemann 5ff4f881a7 [lldb] Ignore type sugar in TypeSystemClang::GetPointerType
Summary:
Currently having a typedef for ObjC types is breaking member access in LLDB:
```
typedef NSString Str;
NSString *s; s.length; // OK
Str *s; s.length; // Causes: member reference base type 'Str *' (aka 'NSString *') is not a structure or union
```

This works for NSString as there the type building from `NSString` -> `NSString *` will correctly
build a ObjCObjectPointerType (which is necessary to make member access with a dot possible),
but for the typedef the `Str` -> `Str *` conversion will produce an incorrect PointerType. The reason
for this is that our check in TypeSystemClang::GetPointerType is not desugaring the base type,
which causes that `Str` is not recognised as a type to a `ObjCInterface` as the check only sees the
typedef sugar that was put around it. This causes that we fall back to constructing a PointerType
instead which does not allow member access with the dot operator.

This patch just changes the check to look at the desugared type instead.

Fixes rdar://17525603

Reviewers: shafik, mib

Reviewed By: mib

Subscribers: mib, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73952
2020-02-05 11:44:40 +01:00
Jonas Devlieghere b453caf111 [lldb/Reproducers] Change the way we instrument void* arguments
The reproducer instrumentation cannot automatically serialize and
deserialize void* arguments. Currently we deal with this by explicitly
preventing these methods from being instrumented. This has the undesired
side effect of breaking replay when that method returns a value later
used by another SB API call.

The solution is to change our approach and instrument these methods.
Instead of using the DUMMY macro, we just make (de)serialization of the
void pointer a NOOP and always return a nullptr.
2020-02-04 19:05:13 -08:00
Reid Kleckner 50d2d33b8e Fix BroadcasterManager::RemoveListener to really remove the listener
This appears to be a real bug caught by -Wunused-value. std::find_if
doesn't modify the underlying collection, it just returns an iterator
pointing to the matching element.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D74010
2020-02-04 17:19:44 -08:00
Jonas Devlieghere 7e02dc3f24 [lldb] Fix -Wdocumentation warnings 2020-02-04 16:44:38 -08:00
Adrian McCarthy fb0d2d455f Fix after c25938d
My refactor caused some changes in error reporting that TestAddDsymCommand.py
was checking, so this restores some of the changes to preserve the old
behavior and to un-xfail the affected test.

Differential Revision: https://reviews.llvm.org/D74001
2020-02-04 16:37:22 -08:00
Reid Kleckner 0c86dfb86d Fix -Wunused-result warnings in LLDB
These try_lock usages intentionally ignore the result, as commented.

Similar to 4d23764ddd, which was reviewed
previously.
2020-02-04 15:58:38 -08:00
Alex Langford fc0ba63f86 [lldb] Rename Type::ResolveClangType to Type::ResolveCompilerType
This is not specific to clang types. It operates on CompilerTypes in
general.
2020-02-04 15:40:48 -08:00
Alex Langford 48b8e3be51 [lldb] Delete commented-out code 2020-02-04 15:33:06 -08:00
Jonas Devlieghere a5f1fff9dd [lldb/Reproducers] Add missing SBFile methods to the registry
SBFile::Read and SBFile::Write were missing from the registry.
2020-02-04 15:10:03 -08:00
Alex Langford 7c9ebdd3d6 [lldb] Remove clang classes from lldb-forward.h
Summary:
lldb-forward.h is convenient in many ways, but having clang-based
class forward declarations in there makes it easy to proliferate uses of clang
outside of plugins. Removing them makes you much more conscious of when
you're using something from clang and marks where we're using things
from clang in non-plugins.

Differential Revision: https://reviews.llvm.org/D73935
2020-02-04 14:23:58 -08:00
Jonas Devlieghere 2757f93a5a [lldb/Reproducers] Instrument SBFile
Currently SBFile isn't really instrumented, which was causing trouble
when capturing and replaying the Python test suite. The class is
particularly tricky because one of its constructors takes a FileSP which
isn't instrumented. Until we have proper shadowing in place, we'll
simply always record a nullptr.

Differential revision: https://reviews.llvm.org/D73992
2020-02-04 13:30:38 -08:00
Vedant Kumar e05af081bf [lldb/StackFrameList] Convert assert to defensive check in SynthesizeTailCallFrames
In order to synthesize tail call frames, the stack frame list must not
be empty (otherwise, there is no "previous" frame to infer a tail call
from).

This case is hard to hit. To trigger it, we must first fail to push
`unwind_frame_sp` because we either fail to get its SymbolContext, or
given its SymbolContext the GetParentOfInlineScope call fails. This
causes m_concrete_frames_fetched to be incremented while m_frames
remains empty. Then, the next frame in the stack may fail within
SynthesizeTailCallFrames. This crash arose during a kernel debugging
session.

rdar://59147051
2020-02-04 10:43:50 -08:00
Jan Kratochvil 88cd49e941 [lldb] Increase LINK_INTERFACE_MULTIPLICITY for Debug builds
On Fedora 30 x86_64 with
	cmake ../llvm-monorepo/llvm/ -DCMAKE_BUILD_TYPE=Debug  -DLLVM_USE_LINKER=gold -DLLVM_ENABLE_PROJECTS="lldb;clang;lld"  -DLLVM_USE_SPLIT_DWARF=ON -DCMAKE_C_COMPILER=clang  -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_ASSERTIONS=ON

It does not affect Release builds.

getting:
	lldb/source/Expression/IRInterpreter.cpp:1471: error: undefined reference to 'lldb_private::ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI(lldb_private::Thread&, lldb_private::Address const&, llvm::Type&, llvm::Type&, llvm::ArrayRef<lldb_private::ABI::CallArgument>, lldb_private::EvaluateExpressionOptions const&)'
	lldb/source/Expression/LLVMUserExpression.cpp:148: error: undefined reference to 'lldb_private::ThreadPlanCallUserExpression::ThreadPlanCallUserExpression(lldb_private::Thread&, lldb_private::Address&, llvm::ArrayRef<unsigned long>, lldb_private::EvaluateExpressionOptions const&, std::shared_ptr<lldb_private::UserExpression>&)'

Pavel Labath has suggest LINK_INTERFACE_MULTIPLICITY could be further
increased.

Differential Revision: https://reviews.llvm.org/D73847
2020-02-04 14:30:27 +01:00
Raphael Isemann bf4d73e6f3 [lldb][NFC] Use correct Decl typedef in ClangASTSource
This is iterating over a DeclContext and not a TagDecl (even
though both iterators are the same underlying type).
2020-02-04 11:53:23 +01:00
Michał Górny 98594a44aa [lldb] [ObjectFile/ELF] Fix negated seg ids on 32-bit arches
Scale segment identifier up to user_id_t before negating it.  This fixes
the identifers being wrongly e.g. 0x00000000fffffffe instead of
0xfffffffffffffffe.  Fix suggested by Pavel Labath.

This fixes 5 tests failing on i386 (PR #44748):

  lldb-shell :: ObjectFile/ELF/PT_LOAD-overlap-PT_INTERP.yaml
  lldb-shell :: ObjectFile/ELF/PT_LOAD-overlap-PT_TLS.yaml
  lldb-shell :: ObjectFile/ELF/PT_LOAD-overlap-section.yaml
  lldb-shell :: ObjectFile/ELF/PT_LOAD.yaml
  lldb-shell :: ObjectFile/ELF/PT_TLS-overlap-PT_LOAD.yaml

Differential Revision: https://reviews.llvm.org/D73914
2020-02-04 05:50:56 +01:00
Vedant Kumar 63e6508221 [lldb/StringPrinter] Simplify StringPrinterBufferPointer, NFC
Remove its template arguments and delete its copy/assign methods.
2020-02-03 15:57:33 -08:00
Vedant Kumar bb6646ce0a [lldb/DataExtractor] Use an early return in GetMaxS64Bitfield, NFC
Shafik suggested this cleanup in https://reviews.llvm.org/D73913.
2020-02-03 15:57:32 -08:00
Vedant Kumar 7b90cdedd1 [lldb/DataExtractor] Fix UB shift in GetMaxS64Bitfield
DataExtractor::GetMaxS64Bitfield performs a shift with UB in order to
construct a bitmask when bitfield_bit_size is 64. The current
implementation actually does “work” in this case, because the assumption
that the shift result is 0 holds, and 0 minus 1 gives the all-ones value
(the correct mask). However, the more readable/maintainable approach
might be to use an off-the-shelf UB-free helper.

Fixes a UBSan issue:

  "col" : 37,
  "description" : "invalid-shift-exponent",
  "filename" : "/Users/vsk/src/llvm-project-master/lldb/source/Utility/DataExtractor.cpp",
  "instrumentation_class" : "UndefinedBehaviorSanitizer",
  "line" : 615,
  "memory_address" : 0,
  "summary" : "Shift exponent 64 is too large for 64-bit type 'uint64_t' (aka 'unsigned long long')",

rdar://59117758

Differential Revision: https://reviews.llvm.org/D73913
2020-02-03 15:57:32 -08:00
Adrian McCarthy 0e362d82b9 Improve help text for (lldb) target symbols add
There were some missing words and awkward syntax.  I think this is clearer.

Differential Revision: https://reviews.llvm.org/D73589
2020-02-03 14:22:05 -08:00
Adrian McCarthy c25938d57b Refactor CommandObjectTargetSymbolsAdd::AddModuleSymbols
* [NFC] Renamed local `matching_module_list` to `matching_modules` for
conciseness.

* [NFC] Eliminated redundant local variable `num_matches` to reduce the risk
that changes get it out of sync with `matching_modules.GetSize()`.

* Used an early return from case where the symbol file specified matches
multiple modules.  This is a slight behavior change, but it's an improvement:
It didn't make sense to tell the user that the symbol file simultaneously
matched multiple modules and no modules.

* [NFC] Used an early return from the case where no matches are found, to
better align with LLVM coding style.

* [NFC] Simplified call of `AppendWarningWithFormat("%s", stuff)` to
`AppendWarning(stuff)`.  I don't think this adds any copies.  It does
construct a StringRef, but it was going to have to scan the string for the
length anyway.

* [NFC] Removed unnecessary comments and reworded others for clarity.

* Used an early return if the symbol file could not be loaded.  This is a
behavior change because previously it could fail silently.

* Used an early return if the object file could not be retrieved from the
symbol file.  Again, this is a change because now there's an error message.

* [NFC] Eliminated a namespace alias that wasn't particularly helpful.

Differential Revision: https://reviews.llvm.org/D73594
2020-02-03 14:22:05 -08:00
Alex Langford 3014efe071 [lldb] Remove unused parameter from ValueObject::GetExpressionPath
I previously removed the code in ValueObject::GetExpressionPath that
took advantage of the parameter `qualify_cxx_base_classes`. As a result,
this is now unused and can be removed.
2020-02-03 10:50:38 -08:00
Alex Langford 5b0c8dd3a4 [lldb] Delete ClangForward.h
Summary:
I think that there are very few things from clang that actually need forward
declaration, so not having a ClangForward header makes sense.

Differential Revision: https://reviews.llvm.org/D73827
2020-02-03 10:43:12 -08:00
Raphael Isemann fad012bce1 Reland "[lldb] Increase the rate at which ConstString's memory allocator scales the memory chunks it allocates""
The parent revision is now passing the sanitizer bots and landed as 46e5603c8a,
so this can now actually land.
2020-02-03 14:59:55 +01:00
Martin Storsjö eb5ee9275d [LLDB] Add missing declarations for linking to psapi
This fixes building for mingw with BUILD_SHARED_LIBS. In static builds,
the psapi dependency gets linked in transitively from Support, but
when linking Support dynamically, it's revealed that these components
also need linking against psapi.

Differential Revision: https://reviews.llvm.org/D73839
2020-02-03 12:59:11 +02:00
Raphael Isemann 0afdc7bed8 Revert "[lldb] Increase the rate at which ConstString's memory allocator scales the memory chunks it allocates"
This reverts commit 500c324fa1 because its parent commit
b848b510a8 is failing on the sanitizer bots.
2020-02-03 11:09:45 +01:00
Raphael Isemann 500c324fa1 [lldb] Increase the rate at which ConstString's memory allocator scales the memory chunks it allocates
Summary:
We currently do far more malloc calls than necessary in the ConstString BumpPtrAllocator. This is due to the 256 BumpPtrAllocators
our ConstString implementation uses internally which end up all just receiving a small share of the total allocated memory
and therefore keep allocating memory in small chunks for far too long. This patch fixes this by increasing the rate at which we increase the
memory chunk size so that our collection of BumpPtrAllocators behaves in total similar to a single BumpPtrAllocator.

Reviewers: llunak

Reviewed By: llunak

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71699
2020-02-03 10:59:35 +01:00
Martin Storsjö 534aeb0b78 [LLDB] Fix GCC warnings about extra semicolon. NFC. 2020-02-03 09:55:02 +02:00
Alex Langford 2637769b9f [lldb] Remove LanguageRuntime::GetOverrideExprOptions
LanguageRuntime::GetOverrideExprOptions is specific to clang and was
only overridden in RenderScriptRuntime. LanguageRuntime in shouldn't
have any knowledge of clang, so remove it from LanguageRuntime and leave
it only in RenderScriptRuntime.
2020-01-31 22:05:23 -08:00
Jonas Devlieghere c62ffb1b19 [lldb/Reproducers] Include string length in string (de)serialization.
This allows us to differentiate between an empty string and a nullptr.

(cherry picked from commit 53e206284fa715886020d6a5553bf791582850a3)
2020-01-31 17:40:49 -08:00
Vedant Kumar 14394a4209 [lldb/TypeSystemClang] Use references in a static helper, NFC 2020-01-31 16:33:12 -08:00
Vedant Kumar 14135f50a0 [lldb/Value] Avoid reading more data than the host has available
Value::GetValueByteSize() reports the size of a Value as the size of its
underlying CompilerType. However, a host buffer that backs a Value may
be smaller than GetValueByteSize().

This situation arises when the host is only able to partially evaluate a
Value, e.g. because the expression contains DW_OP_piece.

The cleanest fix I've found to this problem is Greg's suggestion, which
is to resize the Value if (after evaluating an expression) it's found to
be too small. I've tried several alternatives which all (in one way or
the other) tried to teach the Value/ValueObjectChild system not to read
past the end of a host buffer, but this was flaky and impractical as it
isn't easy to figure out the host buffer's size (Value::GetScalar() can
point to somewhere /inside/ a host buffer, but you need to walk up the
ValueObject hierarchy to try and find its size).

This fixes an ASan error in lldb seen when debugging a clang binary.
I've added a regression test in test/functionalities/optimized_code. The
point of that test is not specifically to check that DW_OP_piece is
handled a particular way, but rather to check that lldb doesn't crash on
an input that it used to crash on.

Testing: check-lldb, and running the added tests using a sanitized lldb

--

Thanks to Jim for pointing out that an earlier version of this patch,
which simply changed the definition of Value::GetValueByteSize(), would
interact poorly with the ValueObject machinery.

Thanks also to Pavel who suggested a neat way to test this change
(which, incidentally, caught another ASan issue still present in the
original version of this patch).

rdar://58665925

Differential Revision: https://reviews.llvm.org/D73148
2020-01-31 16:33:12 -08:00
Vedant Kumar 009e3e53c1 [lldb/MCDisasm] Simplify predicates in MCDisasmInstance, NFC 2020-01-31 16:33:12 -08:00