Commit Graph

2323 Commits

Author SHA1 Message Date
Alex Langford 1079978b3c [lldb][Core] Remove dead codepath in Mangled
Summary:
Objective-C names are stored in m_demangled, not in m_mangled. The
method in the condition will never return true.

Differential Revision: https://reviews.llvm.org/D79823
2020-05-26 17:12:20 -07:00
Raphael Isemann bca378f68a [lldb][NFC] Overload raw_ostream operator << for ConstString
Summary: We are not doing this very often, but sometimes it's convenient when I can just << ConstStrings into llvm::errs() during testing.

Reviewers: labath, JDevlieghere

Reviewed By: labath, JDevlieghere

Subscribers: JDevlieghere

Differential Revision: https://reviews.llvm.org/D80310
2020-05-22 11:24:48 +02:00
Nico Weber bc1c3655bf Give microsoftDemangle() an outparam for how many input bytes were consumed.
Demangling Itanium symbols either consumes the whole input or fails,
but Microsoft symbols can be successfully demangled with just some
of the input.

Add an outparam that enables clients to know how much of the input was
consumed, and use this flag to give llvm-undname an opt-in warning
on partially consumed symbols.

Differential Revision: https://reviews.llvm.org/D80173
2020-05-20 16:17:31 -04:00
Med Ismail Bennani 0eba9de71e [lldb/Dataformatter] Add support to CF{Dictionary,Set}Ref types
This patch improves data formatting for CFDictionaryRef and CFSetRef.
It uses the same data-formatter as NSCFDictionaries and NSCFSets introduced
previously but did require some adjustments in Core::ValueObject.

Since the "Ref" types are opaque pointers to the actual CF containers, if the
value object has a synthetic value, lldb will use the opaque pointer's pointee
type to create the new ValueObjectChild needed to dereference the ValueObject.
This allows the "Ref" types to behaves the same as CF containers when used with
the `frame variable` command, the SBAPI or in Xcode's variable inspector.

This patch also adds support for incomplete types in ValueObject.

rdar://53104287

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-05-15 22:14:39 +02:00
Pavel Labath 3a16829748 [lldb] Switch Section-dumping code to raw_ostream
Also, add a basic test for dumping sections.
2020-05-14 11:59:18 +02:00
Fred Riss d9166ad272 [lldb/Driver] Support terminal resizing
Summary:
The comment in the Editine.h header made it sound like editline was
just unable to handle terminal resizing. We were not ever telling
editline that the terminal had changed size, which might explain why
it wasn't working.

This patch threads a `TerminalSizeChanged()` callback through the
IOHandler and invokes it from the SIGWINCH handler in the driver. Our
`Editline` class already had a `TerminalSizeChanged()` method which
was invoked only when editline was configured.

This patch also changes `Editline` to not apply the changes right away
in `TerminalSizeChanged()`, but instead defer that to the next
character read. During my testing, it happened once that the signal
was received while our `ConnectionFileDescriptor::Read` was allocating
memory. As `el_resize` seems to allocate memory too, this crashed.

Reviewers: labath, teemperor

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D79654
2020-05-12 11:55:25 -07:00
Raphael Isemann 7b1f1cf1cf [lldb] Remove 'use_synthetic' parameters in ValueObject code
Summary:
`CalculateSyntheticValue` and `GetSyntheticValue` have a `use_synthetic` parameter
that makes the function do nothing when it's false. We obviously always pass true
to the function (or check that the value we pass is true), because there really isn't
any point calling with function with a `false`. This just removes all of this.

Reviewers: labath, JDevlieghere, davide

Reviewed By: davide

Subscribers: davide

Differential Revision: https://reviews.llvm.org/D79568
2020-05-08 21:17:32 +02:00
Raphael Isemann d7c2c2ed79 [lldb][NFC] Also initialize language_flags in ValueObject::Dereference
We currently rely on the TypeSystem implementation to initialize this value
with 0 in the GetChildCompilerTypeAtIndex call below. Let's just initialize
this variable like the rest.
2020-05-07 17:52:12 +02:00
Adrian Prantl f0c08b7eac Move the Xcode SDK path caching to HostInfo
When debugging a remote platform, the platform you get from
GetPlatformForArchitecture doesn't inherit from PlatformDarwin.
HostInfoMacOSX seems like the right place to have a global store of
local paths.

Differential Revision: https://reviews.llvm.org/D79364
2020-05-06 13:43:50 -07:00
Adrian Prantl 5935227e11 Add an explicit API to read the Xcode SDK DWARF attribute from compile units
When debugging from a SymbolMap the creation of CompileUnits for the
individual object files is so lazy that RegisterXcodeSDK() is not
invoked at all before the Swift TypeSystem wants to read it. This
patch fixes this by introducing an explicit
SymbolFile::ParseXcodeSDK() call that can be invoked deterministically
before the result is required.

<rdar://problem/62532151+62326862>

https://reviews.llvm.org/D79273
2020-05-06 13:16:16 -07:00
Pavel Labath 9321255b88 [lldb/Core] Avoid more Communication::Disconnect races
Calling Disconnect while the read thread is running is racy because the
thread can also call Disconnect.  This is a follow-up to b424b0bf, which
reorders other occurences of Disconnect/StopReadThread I can find, and also
adds an assertion to guard against new occurences being introduced.
2020-04-23 16:36:21 +02:00
Emre Kultursay 865996ddf6 [lldb] Remove m_last_file_sp from SourceManager
Summary:
...and replace it with m_last_file_spec instead.

When Source Cache is enabled, the value stored in m_last_file_sp is
already in the Source Cache, and caching it again in SourceManager
brings no extra benefit. All we need is to "remember" the last used
file, and FileSpec can serve the same purpose.

When Source Cache is disabled, the user explicitly requested no caching
of source files, and therefore, m_last_file_sp should NOT be used.

Bug: llvm.org/PR45310

Depends on D76805.

Reviewers: labath, jingham

Reviewed By: jingham

Subscribers: labath, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76806
2020-04-20 16:27:19 +02:00
Emre Kultursay 1f820fa4fe [lldb] Fix SourceManager::SourceFileCache insertion
Summary:
Lookup and subsequent insert was done using uninitialized
FileSpec object, which caused the cache to be a no-op.

Bug: llvm.org/PR45310

Depends on D76804.

Reviewers: labath, JDevlieghere

Reviewed By: labath

Subscribers: mgorny, jingham, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76805
2020-04-20 16:25:54 +02:00
Emre Kultursay acae69d08c [lldb] Add new LLDB setting: use-source-cache
Summary:
LLDB memory-maps large source files, and at the same time, caches
all source files in the Source Cache.

On Windows, memory-mapped source files are not writeable, causing
bad user experience in IDEs (such as errors when saving edited files).
IDEs should have the ability to disable the Source Cache at LLDB
startup, so that users can edit source files while debugging.

Bug: llvm.org/PR45310

Reviewers: labath, JDevlieghere, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76804
2020-04-20 16:24:25 +02:00
Pavel Labath a9406daaa6 [lldb] Add parts accidentally left out of 769d704: Recommit "[lldb/Core] Fix a race in the Communication class"
I went to a great length to explain the reason why these changes were
needed, but I did not actually ammend the patch to include them. :(
2020-04-09 14:45:23 +02:00
Pavel Labath 769d7041cc Recommit "[lldb/Core] Fix a race in the Communication class"
The synchronization logic in the previous had a subtle bug. Moving of
the "m_read_thread_did_exit = true" into the critical section made it
possible for some threads calling SynchronizeWithReadThread call to get
stuck. This could happen if there were already past the point where they
checked this variable. In that case, they would block on waiting for the
eBroadcastBitNoMorePendingInput event, which would never come as the
read thread was blocked on getting the synchronization mutex.

The new version moves that line out of the critical section and before
the sending of the eBroadcastBitNoMorePendingInput event, and also adds
some comments to explain why the things need to be in this sequence:
- m_read_thread_did_exit = true: prevents new threads for waiting on
  events
- eBroadcastBitNoMorePendingInput: unblock any current thread waiting
  for the event
- Disconnect(): close the connection. This is the only bit that needs to
  be in the critical section, and this is to ensure that we don't close
  the connection while the synchronizing thread is mucking with it.

Original commit message follows:

Communication::SynchronizeWithReadThread is called whenever a process
stops to ensure that we process all of its stdout before we report the
stop. If the process exits, we first call this method, and then close
the connection.

However, when the child process exits, the thread reading its stdout
will usually (but not always) read an EOF because the other end of the
pty has been closed. In response to an EOF, the Communication read
thread closes it's end of the connection too.

This can result in a race where the read thread is closing the
connection while the synchronizing thread is attempting to get its
attention via Connection::InterruptRead.

The fix is to hold the synchronization mutex while closing the
connection.

I've found this issue while tracking down a rare flake in some of the
vscode tests. I am not sure this is the cause of those failures (as I
would have expected this issue to manifest itself differently), but it
is an issue nonetheless.

The attached test demonstrates the steps needed to reproduce the race.
It will fail under tsan without this patch.

Reviewers: clayborg, JDevlieghere

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77295
2020-04-09 13:39:00 +02:00
Pavel Labath 76975c744d Revert "[lldb/Core] Fix a race in the Communication class"
This reverts commit ebb071345c -- it seems
to introduce a deadlock in some circumstances.
2020-04-09 12:49:56 +02:00
Pavel Labath ebb071345c [lldb/Core] Fix a race in the Communication class
Summary:
Communication::SynchronizeWithReadThread is called whenever a process
stops to ensure that we process all of its stdout before we report the
stop. If the process exits, we first call this method, and then close
the connection.

However, when the child process exits, the thread reading its stdout
will usually (but not always) read an EOF because the other end of the
pty has been closed. In response to an EOF, the Communication read
thread closes it's end of the connection too.

This can result in a race where the read thread is closing the
connection while the synchronizing thread is attempting to get its
attention via Connection::InterruptRead.

The fix is to hold the synchronization mutex while closing the
connection.

I've found this issue while tracking down a rare flake in some of the
vscode tests. I am not sure this is the cause of those failures (as I
would have expected this issue to manifest itself differently), but it
is an issue nonetheless.

The attached test demonstrates the steps needed to reproduce the race.
It will fail under tsan without this patch.

Reviewers: clayborg, JDevlieghere

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77295
2020-04-09 12:06:47 +02:00
Adrian Prantl 1e05d7b3d3 Remap the target (Xcode) SDK directory to the host SDK directory.
This is mostly useful for Swift support; it allows LLDB to substitute
a matching SDK it shipped with instead of the sysroot path that was
used at compile time.

The goal of this is to make the Xcode SDK something that behaves more
like the compiler's resource directory, as in that it ships with LLDB
rather than with the debugged program. This important primarily for
importing Swift and Clang modules in the expression evaluator, and
getting at the APINotes from the SDK in Swift.

For a cross-debugging scenario, this means you have to have an SDK for
your target installed alongside LLDB. In Xcode this will always be the
case.

rdar://problem/60640017

Differential Revision: https://reviews.llvm.org/D76471
2020-04-06 15:51:30 -07:00
Kazuaki Ishizaki e9264b746b [lldb] NFC: Fix trivial typo in comments, documents, and messages
Differential Revision: https://reviews.llvm.org/D77460
2020-04-07 01:06:16 +09:00
Konrad Kleine 9072df8ac1 [lldb][nfc] remove overriden funcs with default impl
Summary:
These `SearchFilter` methods all return `true` by their default
implementation:

```lang=c++
virtual bool ModulePasses(const FileSpec &spec);
virtual bool ModulePasses(const lldb::ModuleSP &module_sp);
virtual bool AddressPasses(Address &addr);
virtual bool CompUnitPasses(FileSpec &fileSpec);
virtual bool CompUnitPasses(CompileUnit &compUnit);
```

That's why I've documented the default behavior and remove the overrides
(except for `AddressPasses`) in these `SearchFilter`-subclasses which all just
repeated the default implementation: `SearchFilterByModule`,
`SearchFilterByModuleList`.

Reviewers: jankratochvil, labath

Reviewed By: jankratochvil, labath

Subscribers: labath, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77376
2020-04-06 10:05:59 -04:00
Pavel Labath 451741a9d7 [lldb] Change Communication::SetConnection to take a unique_ptr
The function takes ownership of the object. This makes that explicit,
and avoids unowned pointers floating around.
2020-04-02 14:42:25 +02:00
Benjamin Kramer e8f13f4f62 Replace std::string::find == 0 with StringRef::startswith
This is both more readable and faster. Found by clang-tidy's
abseil-string-find-startswith.
2020-03-31 21:01:09 +02:00
Jaroslav Sevcik 177dd63c8d Data formatters: fix detection of C strings
Summary:
Detection of C strings does not work well for pointers. If the value object holding a (char*) pointer does not have an address (e.g., if it is a temp), the value is not considered a C string and its formatting is left to DumpDataExtractor rather than the special handling in  ValueObject::DumpPrintableRepresentation. This leads to inconsistent outputs, e.g., in escaping non-ASCII characters. See the test for an example; the second test expectation is not met (without this patch). With this patch, the C string detection only insists that the pointer value is valid. The patch makes the code consistent with how the pointer is obtained in ValueObject::ReadPointedString.

Reviewers: teemperor

Reviewed By: teemperor

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D76650
2020-03-24 14:25:59 +01:00
Jim Ingham 67d67ebe8f Internal expressions shouldn't increment the result variable numbering.
There an option: EvaluateExpressionOptions::SetResultIsInternal to indicate
whether the result number should be returned to the pool or not.  It
got broken when the PersistentExpressionState was refactored.

This fixes the issue and provides a test of the behavior.

Differential Revision: https://reviews.llvm.org/D76532
2020-03-23 13:30:37 -07:00
Pavel Labath af3db4e9aa [lldb] Reduce duplication in the Disassembler class
Summary:
The class has two pairs of functions whose functionalities differ in
only how one specifies how much he wants to disasseble. One limits the
process by the size of the input memory region. The other based on the
total amount of instructions disassembled. They also differ in various
features (like error reporting) that were only added to one of the
versions.

There are various ways in which this could be addressed. This patch
does it by introducing a helper struct called "Limit", which is
effectively a pair specifying the value that you want to limit, and the
actual limit itself.

Reviewers: JDevlieghere

Subscribers: sdardis, jrtc27, atanasyan, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75730
2020-03-09 13:41:43 +01:00
Raphael Isemann 3b2c4e7178 [lldb] Remove some #ifdef LLDB_CONFIGURATION_DEBUG around asserts
Summary:
Otherwise this code won't run on the Release+Asserts builds we have on the CI.

Fixes rdar://problem/59867885 (partly)

Reviewers: aprantl

Reviewed By: aprantl

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75493
2020-03-06 11:21:00 -08:00
Pavel Labath 92c0cda928 [lldb/Disassembler] Move address resolution into the ParseInstructions function
The static Disassembler can be thought of as shorthands for three
operations:
- fetch an appropriate disassembler instance (FindPluginForTarget)
- ask it to dissassemble some bytes (ParseInstructions)
- ask it to dump the disassembled instructions (PrintInstructions)

The only thing that's standing in the way of this interpretation is that
the Disassemble function also does some address resolution before
calling ParseInstructions. This patch moves this functionality into
ParseInstructions so that it is available to users who call
ParseInstructions directly.
2020-03-06 11:23:41 +01:00
Pavel Labath 04592d5b23 [lldb] s/ExecutionContext/Target in Disassembler
Some functions in this file only use the "target" component of an
execution context. Adjust the argument lists to reflect that.

This avoids some defensive null checks and simplifies most of the
callers.
2020-03-05 14:46:39 +01:00
Pavel Labath ea68462ed1 [lldb] Make Disassembler::PrintInstructions a method
the previously static member function took a Disassembler* argument
anyway. This renames the argument to "this". The function also always
succeeds (returns true), so I change the return type to void.
2020-03-05 12:07:49 +01:00
Pavel Labath c6a38957a7 [lldb] Delete two overloads of Disassembler::Disassemble
by "inlining" them into their single caller (CommandObjectDisassemble).
The functions mainly consist of long argument lists and defensive
checks. These become unnecessary after inlining, so the end result is
less code. Additionally, this makes the implementation of
CommandObjectDisassemble more uniform (first figure out what you're
going to disassemble, then actually do it), which enables further
cleanups.
2020-03-05 11:00:37 +01:00
Pavel Labath 1d6fa41f40 [lldb] Have Disassembler::ParseInstructions take a Target&
Instead of a ExecutionContext*. All it needs is the target so it can
read the memory.

This removes some defensive checks from the function. I've added
equivalent checks to the callers in cases where a non-null target
pointer was not guaranteed to be available.
2020-03-03 13:58:56 +01:00
Pavel Labath 4deea65249 [lldb] Make sure we don't drop asynchronous output when sourcing files
Summary:
If a command from a sourced file produces asynchronous output, this
output often does not make its way to the user. This happens because the
asynchronous output machinery relies on the iohandler stack to ensure
the output does not interfere with the things the iohandler is doing.

However, if this happens near the end of the command stream then by the
time the asynchronous output is produced we may already have already
started tearing down the sourcing session. Specifically, we may already
pop the relevant iohandler, leaving the stack empty.

This patch makes sure this kind of output gets printed by adding a
fallback to IOHandlerStack::PrintAsync to print the output directly if
the stack is empty. This is safe because if we have no iohandlers then
there is nothing to synchronize.

Reviewers: JDevlieghere, clayborg

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D75454
2020-03-03 11:18:41 +01:00
Paolo Severini 256e61699b [LLDB] Fix AddressSanitizer failure in MemoryCache
The lldb sanitizer bot is flagging a container-overflow error after we
introduced test TestWasm.py. MemoryCache::Read didn't behave correctly
in case of partial reads that can happen with object files whose size is
smaller that the cache size. It should return the actual number of bytes
read and not try to fill the buffer with random memory.
Module::GetMemoryObjectFile needs to be modified accordingly, to resize
its buffer to only the size that was read.

Differential Revision: https://reviews.llvm.org/D75200
2020-02-27 11:17:10 -08:00
Jonas Devlieghere 841be9854c [lldb] Color the line marker
Highlight the color marker similar to what we do for the column marker.
The default color matches the color of the current PC marker (->) in the
default disassembly format.

Differential revision: https://reviews.llvm.org/D75070
2020-02-24 15:40:31 -08:00
Jonas Devlieghere c4093db3da [lldb] Color the current PC marker
Differential revision: https://reviews.llvm.org/D75073
2020-02-24 12:51:01 -08:00
Jonas Devlieghere 77a2744fa5 [lldb/Debugger] Remove macros formerly used by property definitions
The DEFAULT_ were used in property definitions which have since been
moved to CoreProperties.td.
2020-02-24 12:48:31 -08:00
Pavel Labath 7b59ff2fa0 [lldb] Add boilerplate to recognize the .debug_tu_index section
It's just like debug_cu_index, only for type units.
2020-02-20 13:44:21 +01:00
Jonas Devlieghere df590f51b6 [lldb/Core] Remove locking in the PluginManager
Remove locking as all the plugin registration takes place from a single
thread. Addresses Pavel's feedback in D74816.
2020-02-19 10:04:05 -08:00
Pavel Labath 8131cb6e18 [lldb/DWARF] Add support for location lists in package files
The only thing needed was to account for the offset from the
debug_cu_index section when searching for the location list.

This patch also fixes a bug in the Module::ParseAllDebugSymbols
function, which meant that we would only parse the variables of the
first compile unit in the module. This function is only used from
lldb-test, so this does not fix any real issue, besides preventing me
from writing a test for this patch.
2020-02-19 14:33:58 +01:00
Jonas Devlieghere 80b2e3cc53 [lldb/Core] Remove more duplicate code in PluginManager (NFCI)
The PluginManager contains a lot of duplicate code. I already removed a
bunch of it by introducing the templated PluginInstance class, and this
is the next step. The PluginInstances class combines the mutex and the
vector and implements the common operations.

To accommodate plugin instances with additional members it is possible
to access the underlying vector and mutex. The methods to query these
fields make use of that.

Differential revision: https://reviews.llvm.org/D74816
2020-02-18 23:58:29 -08:00
Jonas Devlieghere d7db094ef7 [lldb] Move ArchitectureCreateInstance into ldb-private-interfaces
There's no reason this should be the only one living in the
PluginManager itself.
2020-02-18 20:19:54 -08:00
Jonas Devlieghere bad1389f12 [lldb/Core] Remove dead Get*PluginCreateCallbackForPluginName (NFC)
The plugin manager had dedicated Get*PluginCreateCallbackForPluginName
methods for each type of plugin, and only a small subset of those were
used. This removes the dead duplicated code.
2020-02-18 17:36:26 -08:00
Jonas Devlieghere 7b76767dbc [lldb/Core] Remove blatant code duplication by using a template (NFC)
Remove a bunch of duplicate code by using a templated base class.
2020-02-18 17:19:47 -08:00
Tatyana Krasnukha 7fb06796ab [lldb][NFC] Remove unused parameter
Rename search-filter's CopyForBreakpoint to CreateCopy, since they don't
do anything with breakpoints.
2020-02-18 13:49:08 +03:00
Tatyana Krasnukha b624b7dfd0 [lldb] Make shared_from_this-related code safer
Pass TargetSP to filters' CreateFromStructuredData, don't let them guess
whether target object is managed by a shared_ptr.

Make Breakpoint sure that m_target.shared_from_this() is safe by passing TargetSP
to all its static Create*** member-functions. This should be enough, since Breakpoint's
constructors are private/protected and never called directly (except by Target itself).
2020-02-18 13:49:07 +03:00
Pavel Labath 0863f67579 [lldb] Remove DataExtractor::GetPointer
This function is equivalent to GetAddress, but getAddress is also
present on the llvm version of the data extractor.
2020-02-18 10:38:41 +01:00
Raphael Isemann f9568a9549 [lldb][NFC] Make all CompilerDeclContext parameters references instead of pointers
Summary:
All of our lookup APIs either use `CompilerDeclContext &` or `CompilerDeclContext *` semi-randomly it seems.
This leads to us constantly converting between those two types (and doing nullptr checks when going from
pointer to reference). It also leads to the confusing situation where we have two possible ways to express
that we don't have a CompilerDeclContex: either a nullptr or an invalid CompilerDeclContext (aka a default
constructed CompilerDeclContext).

This moves all APIs to use references and gets rid of all the nullptr checks and conversions.

Reviewers: labath, mib, shafik

Reviewed By: labath, shafik

Subscribers: shafik, arphaman, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74607
2020-02-18 08:58:36 +01:00
Raphael Isemann 30ce956aec [lldb][NFC] Remove GetConstTypeName and GetConstQualifiedTypeName from CompilerType
Beside these two functions just being wrappers around GetTypeName they are also
just a leftover from migrating the CompilerType interface to ConstString.
2020-02-12 09:49:39 +01:00
Pavel Labath 363f05b83d [lldb] Delete the SharingPtr class
Summary:
The only use of this class was to implement the SharedCluster of ValueObjects.
However, the same functionality can be implemented using a regular
std::shared_ptr, and its little-known "sub-object pointer" feature, where the
pointer can point to one thing, but actually delete something else when it goes
out of scope.

This patch reimplements SharedCluster using this feature --
SharedClusterPointer::GetObject now returns a std::shared_pointer which points
to the ValueObject, but actually owns the whole cluster. The only change I
needed to make here is that now the SharedCluster object needs to be created
before the root ValueObject. This means that all private ValueObject
constructors get a ClusterManager argument, and their static Create functions do
the create-a-manager-and-pass-it-to-value-object dance.

Reviewers: teemperor, JDevlieghere, jingham

Subscribers: mgorny, jfb, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74153
2020-02-11 13:23:18 +01:00
Raphael Isemann 642bc15dd7 [lldb][NFC] Remove several inefficient ConstString -> const char * -> StringRef conversions
StringRef will call strlen on the C string which is inefficient (as ConstString already
knows the string lenght and so does StringRef). This patch replaces all those calls
with GetStringRef() which doesn't recompute the length.
2020-02-11 09:14:41 +01:00
Pavel Labath 8033161072 [lldb] Delete ValueObjectRegisterContext class
It is unused.
2020-02-07 09:20:22 -08: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
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
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
Alex Langford 48b8e3be51 [lldb] Delete commented-out code 2020-02-04 15:33:06 -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
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
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
Alex Langford 22b044877d [lldb][NFCI] Remove unused LanguageType parameters
These parameters are unused in these methods, and some of them only had a
LanguageType parameter to pipe to other methods that don't use it
either.
2020-01-30 21:57:23 -08:00
Alex Langford 31905c2bbb [lldb][NFCI] Delete commented out code 2020-01-30 18:02:36 -08:00
Alex Langford e1451a724d [lldb][NFCI] Rename variable in ValueObject 2020-01-30 16:53:01 -08:00
Alex Langford 71b022ee55 [lldb] Remove unused header from ValueObject.cpp
In commit 5eaf44f99f I removed the last
instance of TypeSystemClang from ValueObject, so the header is no longer
needed.
2020-01-28 16:13:21 -08:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Alex Langford 5eaf44f99f [lldb] Delete ValueObject::GetBaseClassPath
Summary:
This method has exactly one call site, which is only actually executed
if `ValueObject::IsBaseClass` returns false. However, the first thing
that `ValueObject::GetBaseClassPath` does is check if `ValueObject::IsBaseClass`
is true. Because this can never be the case, this method always returns false
and is therefore effectively dead.

Differential Revision: https://reviews.llvm.org/D73517
2020-01-28 14:11:53 -08:00
Med Ismail Bennani 954d04295b Revert "[lldb/Target] Add Assert StackFrame Recognizer"
This reverts commit 03a6b858fd.

The test doesn't pass on Debian.
2020-01-28 18:40:08 +01:00
Med Ismail Bennani 03a6b858fd [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-01-28 18:21:29 +01:00
Raphael Isemann 808142876c [lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).

This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).

Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:52:55 +01:00
Raphael Isemann 6e3b0cc2fb [lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).

I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.

Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai

Reviewed By: clayborg, labath, xiaobai

Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 10:09:14 +01:00
Fred Riss 0478eadf73 [lldb/DataFormatters] Fix the `$$deference$$` synthetic child
Summary:
The ValueObject code checks for a special `$$dereference$$` synthetic
child to allow formatter providers to implement a natural
dereferencing behavior in `frame variable` for objects like smart
pointers.

This support was broken when used directly throught the Python API and
not trhough `frame variable`. The reason is that
SBFrame.FindVariable() will return by default the synthetic variable
if it exists, while `frame variable` will not do this eagerly. The
code in `ValueObject::Dereference()` accounted for the latter but not
for the former. The fix is trivial. The test change includes
additional covergage for the already-working bahevior as it wasn't
covered by the testsuite before.

This commit also adds a short piece of documentatione explaining that
it is possible (even advisable) to provide this synthetic child
outstide of the range of the normal children.

Reviewers: jingham

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73053
2020-01-21 13:35:55 -08:00
Jonas Devlieghere 04de24e690 [lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.

Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.

While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.

Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.

I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.

Differential revision: https://reviews.llvm.org/D72748
2020-01-20 11:17:55 -08:00
Pavel Labath 27df2d9f55 [lldb] Don't process symlinks deep inside DWARFUnit
Summary:
This code is handling debug info paths starting with /proc/self/cwd,
which is one of the mechanisms people use to obtain "relocatable" debug
info (the idea being that one starts the debugger with an appropriate
cwd and things "just work").

Instead of resolving the symlinks inside DWARFUnit, we can do the same
thing more elegantly by hooking into the existing Module path remapping
code. Since llvm::DWARFUnit does not support any similar functionality,
doing things this way is also a step towards unifying llvm and lldb
dwarf parsers.

Reviewers: JDevlieghere, aprantl, clayborg, jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71770
2020-01-20 13:05:00 +01:00
Jonas Devlieghere 2671df9bd6 [lldb/Debugger] Rename ExecuteIOHandlers to RunIOHandlers (NFC)
This improves consistency among the related methods.
2020-01-16 16:45:47 -08:00
Jonas Devlieghere 7ce2de2ce4 [lldb/Debugger] Rename IO handler methods to be more meaningful (NFC)
Make it clear form the method names whether they are synchronous or
asynchronous.
2020-01-15 14:58:16 -08:00
Pavel Labath 4b5bc38802 [lldb/DWARF] Move location list sections into DWARFContext
These are the last sections not managed by the DWARFContext object. I
also introduce separate SectionType enums for dwo section variants, as
this is necessary for proper handling of single-file split dwarf.
2020-01-14 15:19:29 +01:00
Alex Langford a63af91528 [lldb] Remove various dead Compare functions 2020-01-08 18:05:33 -08:00
Raphael Isemann 65fdb34219 [lldb][NFC] Use static_cast instead of reinterpret_cast where possible
Summary: There are a few places in LLDB where we do a `reinterpret_cast` for conversions that we could also do with `static_cast`. This patch moves all this code to `static_cast`.

Reviewers: shafik, JDevlieghere, labath

Reviewed By: labath

Subscribers: arphaman, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72161
2020-01-07 13:03:56 +01:00
Jonas Devlieghere f38234ed8b [lldb/CMake] Fix variable naming in FindLibEdit
The current FOUND_VAR for FindLibEdit is libedit_FOUND but wasn't set by
find_package_handle_standard_args. However this isn't valid for the
package name.

  The argument for FOUND_VAR is "libedit_FOUND", but only "LibEdit_FOUND" and
  "LIBEDIT_FOUND" are valid names.

This fixes all the variables set by FindLibEdit to match the desired
naming scheme.
2020-01-02 13:39:57 -08:00
Jonas Devlieghere 1562511275 [lldb/ScriptInterpreter] Remove can_reload which is always true (NFC)
The `-r` option for `command script import` is there for legacy
compatibility, however the can_reload flag is always set to true. This
patch removes the flag and any code that relies on it being false.
2019-12-22 21:36:03 -08:00
Jonas Devlieghere bbf70c0467 [lldb/Core] Support asking the debugger for a specific script interpreter
Rather than holding on to one script interpreter, it should be possible
to request a script interpreter for a specific scripting language. The
GetScriptInterpreter method now takes an optional scripting language
argument.

(NFC)
2019-12-21 17:11:12 -08:00
Jan Kratochvil df6879ec02 [lldb] Fix ARM32 inferior calls
echo -e '#include <unistd.h>\nint main(void){\nsync();return 0;}'|./bin/clang -g -x c -;./bin/lldb -o 'file ./a.out' -o 'b main' -o r -o 'p (void)sync()'

Actual:

  error: Expression can't be run, because there is no JIT compiled function

Expected:

  <nothing, sync() has been executed>

This patch has been checked by:
  D71707: clang-tidy: new bugprone-pointer-cast-widening
  https://reviews.llvm.org/D71707

Casting from 32-bit `void *` to `uint64_t` requires an intermediate `uintptr_t` cast otherwise the pointer gets sign-extended:

  echo -e '#include <stdio.h>\n#include <stdint.h>\nint main(void){void *p=(void *)0x80000000;unsigned long long ull=(unsigned long long)p;unsigned long long ull2=(unsigned long
long)(uintptr_t)p;printf("p=%p ull=0x%llx ull2=0x%llx\\n",p,ull,ull2);return 0;}'|gcc -Wall -m32 -x c -;./a.out
  <stdin>: In function ‘main’:
  <stdin>:3:66: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  p=0x80000000 ull=0xffffffff80000000 ull2=0x80000000

With debug output:
Actual:

  IRMemoryMap::WriteMemory (0xb6ff8640, 0xffffffffb6f82158, 0x112) went to [0xb6ff8640..0xb6ff86b3)
  Code can be run in the target.
  Found function, has local address 0xffffffffb6f84000 and remote address 0xffffffffffffffff
  Couldn't disassemble function : Couldn't find code range for function _Z12$__lldb_exprPv
  Sections:
  [0xb6f84000+0x3c]->0xb6ff9020 (alignment 4, section ID 0, name .text)
  ...
  HandleCommand, command did not succeed
  error: Expression can't be run, because there is no JIT compiled function

Expected:

  IRMemoryMap::WriteMemory (0xb6ff8640, 0xb6faa15c, 0x128) went to [0xb6ff8640..0xb6ff86c3)
  IRExecutionUnit::GetRemoteAddressForLocal() found 0xb6fac000 in [0xb6fac000..0xb6fac040], and returned 0xb6ff9020 from [0xb6ff9020..0xb6ff9060].
  Code can be run in the target.
  Found function, has local address 0xb6fac000 and remote address 0xb6ff9020
  Function's code range is [0xb6ff9020+0x40]
  ...
  Function data has contents:
  0xb6ff9020: 10 4c 2d e9 08 b0 8d e2 08 d0 4d e2 00 40 a0 e1
  ...
  Function disassembly:
  0xb6ff9020: 0xe92d4c10   push   {r4, r10, r11, lr}

Differential revision: https://reviews.llvm.org/D71498
2019-12-21 11:12:17 +01:00
Jonas Devlieghere 94b1bc0fb8 Re-land "[lldb/CMake] Change how we deal with optional dependencies"
Recently there has been some discussion about how we deal with optional
dependencies in LLDB. The approach in LLVM is to make things work out of
the box. If the dependency isn't there, we move on silently.

That's not true for LLDB. Unless you explicitly disable the dependency
with LLDB_ENABLE_*, you'll get a configuration-time error. The
historical reason for this is that LLDB's dependencies have a much
broader impact, think about Python for example which is required to run
the test suite.

The current approach can be frustrating from a user experience
perspective. Sometimes you just want to ensure LLDB builds with a change
in clang.

This patch changes the optional dependencies (with the exception of
Python) to a new scheme. The LLDB_ENABLE_* now takes three values: On,
Off or Auto, with the latter being the default. On and Off behave the
same as today, forcing the dependency to be enabled or disabled. If the
dependency is set to On but is not found, it results in a configuration
time warning. For Auto we detect if the dependency is there and either
enable or disable it depending on whether it's found.

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

PS: The reason Python isn't included yet is because it's so pervasive
that I plan on doing that in a separate patch.
2019-12-20 20:05:04 -08:00
Pavel Labath 32a3428959 [lldb] Fix an unused variable warning 2019-12-20 16:51:25 +01:00
Jim Ingham 434905b97d Run all threads when extending a next range over a call.
If you don't do this you end up running arbitrary code with
only one thread allowed to run, which can cause deadlocks.

<rdar://problem/56422478>

Differential Revision: https://reviews.llvm.org/D71440
2019-12-16 17:45:21 -08:00
Jonas Devlieghere 4e26cf2cfb [lldb/CMake] Rename LLDB_DISABLE_PYTHON to LLDB_ENABLE_PYTHON
This matches the naming scheme used by LLVM and all the other optional
dependencies in LLDB.

Differential revision: https://reviews.llvm.org/D71482
2019-12-13 13:41:11 -08:00
Med Ismail Bennani 7eaae939b9 [FormatEntity] Add mangled function name support
Summary:
Add `function.mangled-name` key for FormatEntity to show the mangled
function names in backtraces.

rdar://54088244

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Subscribers: lldb-commits

Tags: #lldb

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2019-12-12 10:22:57 -08:00
Jonas Devlieghere babbd554b8 [lldb/Core] Add missing include
This got flagged by the modules build.
2019-12-12 09:55:11 -08:00
Jonas Devlieghere 62456e579e [lldb/CMake] Rename LLDB_DISABLE_LIBEDIT to LLDB_ENABLE_LIBEDIT
This matches the naming scheme used by LLVM.

Differential revision: https://reviews.llvm.org/D71380
2019-12-12 09:23:06 -08:00
Jonas Devlieghere a4304f96d6 [lldb/CMake] Rename LLDB_DISABLE_CURSES to LLDB_ENABLE_CURSES
This matches the naming scheme used by LLVM.

Differential revision: https://reviews.llvm.org/D71377
2019-12-12 09:13:31 -08:00
Jonas Devlieghere ff82315d4e [lldb/CMake] Simplify linking against curses
Centralize the logic to determine what libraries to link against for
curses in the CMake file where it is actually being used. Use
target_include_directories instead of include_directories.
2019-12-11 14:36:32 -08:00
Adrian Prantl ee64dfd953 Remove TypeValidators (NFC in terms of the testsuite)
This is a half-implemented feature that as far as we can tell was
never used by anything since its original inclusion in 2014. This
patch removes it to make remaining the code easier to understand.

Differential Revision: https://reviews.llvm.org/D71310
2019-12-11 09:27:12 -08:00
Jonas Devlieghere 59998b7b7f [lldb/Host] Use Host/Config.h entries instead of a global define.
As suggested by Pavel in a code review:

> Can we replace this (and maybe python too, while at it) with a
> Host/Config.h entry? A global definition means that one has to
> recompile everything when these change in any way, whereas in
> practice only a handful of files need this..

Differential revision: https://reviews.llvm.org/D71280
2019-12-10 11:16:52 -08:00
Raphael Isemann 777d1f7272 [lldb] Migrate VMRange::Dump to raw_ostream 2019-12-06 10:19:20 +01:00
Raphael Isemann 4dac97eb1e [lldb][NFC] Migrate FileSpec::Dump to raw_ostream 2019-12-06 09:40:42 +01:00
Konrad Kleine 51ce067a44 [lldb] NFC: less nesting in SearchFilter.cpp
I was working on SearchFilter.cpp and felt it a bit too complex in some cases in terms of nesting and logic flow.

Reviewers: teemperor, JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71022
2019-12-06 08:38:33 +01:00
Raphael Isemann 1462f5a4c1 [lldb][NFC] Move Address and AddressRange functions out of Stream and let them take raw_ostream
Summary:
Yet another step on the long road towards getting rid of lldb's Stream class.

We probably should just make this some kind of member of Address/AddressRange, but it seems quite often we just push
in random integers in there and this is just about getting rid of Stream and not improving arbitrary APIs.

I had to rename another `DumpAddress` function in FormatEntity that is dumping the content of an address to make Clang happy.

Reviewers: labath

Reviewed By: labath

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71052
2019-12-05 14:41:33 +01:00
Eric Christopher 5312139f77 Add a default copy-assignment or copy-constructor for -Wdeprecated-copy warnings. 2019-12-04 20:35:32 -08:00
Pavel Labath 532290e69f [lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).

These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.

For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
    if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.

On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
    if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.

This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.

I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.

There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.

[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: emaste, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70851
2019-12-04 10:42:32 +01:00
Raphael Isemann c4c464f8a5 [lldb][NFC] Migrate to raw_ostream in Module::GetDescription 2019-12-04 09:35:50 +01:00
Raphael Isemann 7caa17caf8 [lldb][NFC] Move Curses interface implementation to own file
Summary:
The IOHandler class source file is currently around 4600 LOC. However only 200
of these lines are concerned with the actual IOHandler class and the rest are the
implementations for Editline, IOHandlerConfirm and the Curses interface. All these
large features also cause that the IOHandler (which is in Core) has a large set of dependencies
on other parts of LLDB.

This patch splits out the code for the curses interface into its own file. This way
the simple IOHandler code is no longer buried in-between much larger functionalities.

Next up is splitting out the other IOHandlers into their own files and then move them
to more appropriate parts of LLDB.

Reviewers: labath, clayborg, JDevlieghere

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70946
2019-12-03 14:01:18 +01:00
Raphael Isemann 315600f480 [lldb][NFC] Remove ThreadSafeSTLVector and ThreadSafeSTLMap and their use in ValueObjectSynthetic
Summary:
ThreadSafeSTLVector and ThreadSafeSTLMap are not useful for achieving any degree of thread safety in LLDB
and should be removed before they are used in more places. They are only used (unsurprisingly incorrectly) in
`ValueObjectSynthetic::GetChildAtIndex`, so this patch replaces their use there with a simple mutex with which
we guard the related data structures. This doesn't make ValueObjectSynthetic::GetChildAtIndex
any more thread-safe, but on the other hand it at least allows us to get rid of the ThreadSafeSTL* data structures
without changing the observable behaviour of ValueObjectSynthetic (beside that it is now a few bytes smaller).

Reviewers: labath, JDevlieghere, jingham

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70845
2019-12-03 09:18:44 +01:00
Pavel Labath 38870af859 [lldb] Remove FileSpec->CompileUnit inheritance
Summary:
CompileUnit is a complicated class. Having it be implicitly convertible
to a FileSpec makes reasoning about it even harder.

This patch replaces the inheritance by a simple member and an accessor
function. This avoid the need for casting in places where one needed to
force a CompileUnit to be treated as a FileSpec, and does not add much
verbosity elsewhere.

It also fixes a bug where we were wrongly comparing CompileUnit& and a
CompileUnit*, which compiled due to a combination of this inheritance
and the FileSpec*->FileSpec implicit constructor.

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70827
2019-11-29 11:44:45 +01:00
Konrad Kleine c671639af6 [lldb] NFC: refactor CompileUnit::ResolveSymbolContext
Summary:
I found the above named method hard to read because it had

a) many nested blocks,
b) one return statement at the end with some logic involved,
c) a duplicated while-loop with just small differences in it.

I decided to refactor this function by employing an early exit strategy.
In order to capture the logic in the return statement and to not have it
repeated more than once I chose to implement a very small lamda function
that captures all the variables it needs.
I also replaced the two while-loops with just one.

This is a non-functional change (NFC).

Reviewers: jdoerfert, teemperor

Reviewed By: teemperor

Subscribers: labath, teemperor, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70774
2019-11-28 21:37:31 +01:00
Raphael Isemann 50e2ffa18d Revert "[lldb] NFC: refactor CompileUnit::ResolveSymbolContext"
This reverts commit 373e2a4f69.

This broke breakpoint setting.
2019-11-28 14:25:46 +01:00
Konrad Kleine 373e2a4f69 [lldb] NFC: refactor CompileUnit::ResolveSymbolContext
Summary:
I found the above named method hard to read because it had

a) many nested blocks and
b) one return statement at the end with some logic involved.

I decided to refactor this function by employing an early exit strategy.
In order to capture the logic in the return statement and to not have it
repeated more than once I chose to implement a very small lamda function
that captures all the variables it needs.

This is a non-functional change (NFC).

Reviewers: jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70774
2019-11-28 14:00:38 +01:00
Pavel Labath 4023bd05fc [lldb] Add boilerplate to recognize the .debug_rnglists.dwo section 2019-11-26 13:58:26 +01:00
Raphael Isemann d1782133d9 [lldb][NFC] Allow range-based for-loops on VariableList
Summary:
Adds support for doing range-based for-loops on LLDB's VariableList and
modernises all the index-based for-loops in LLDB where possible.

Reviewers: labath, jdoerfert

Reviewed By: labath

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70668
2019-11-25 15:03:46 +01:00
Adrian Prantl 0304360a40 Add a testcase for Clang modules being updated within one LLDB session.
This actually works as expected, but wasn't explicitly tested before.
2019-11-15 16:27:14 -08:00
Jonas Devlieghere 95807cb039 [LLDB] Remove dead code from StreamFile 2019-11-13 15:08:51 -08:00
Adrian Prantl 3b73dcdc96 Performance: Add a set of visited SymbolFiles to the other FindFiles variant.
This is basically the same bug as in r260434.

SymbolFileDWARF::FindTypes has exponential worst-case when digging
through dependency DAG of .pcm files because each object file and .pcm
file may depend on an already-visited .pcm file, which may again have
dependencies. Fixed here by carrying a set of already visited
SymbolFiles around.

rdar://problem/56993424

Differential Revision: https://reviews.llvm.org/D70106
2019-11-12 09:38:37 -08:00
Pavel Labath 6aa60b0514 [lldb] Fix more -Wdeprecated-copy warnings
This warning triggers when a class defines a copy constructor but not a
copy-assignment operator (which then gets auto-generated by the
compiler). Fix the warning by deleting the other operator too, as the
default implementation works just fine.
2019-11-12 14:39:47 +01:00
shafik 83393d27af [LLDB] Fix handling for the clang name mangling extension for block invocations
Add support for clangs  mangling extension for block invocations.

Differential Revision: https://reviews.llvm.org/D69738
2019-11-06 14:20:00 -08:00
Adrian Prantl 3ac6863efb [ValueObject] Upstream early exit from swift-lldb. (NFC) 2019-11-05 12:43:00 -08:00
Adrian Prantl de5417f81d [ValueObject] Upstream initialization from swift-lldb.
This is a non-Swift-specific change in swift-lldb that seems to be
useful for remote debugging. If does in fact turn out to be redundant
we can remove it from llvm.org and then it will disappear in
swift-lldb, too.
2019-11-05 12:36:14 -08:00
Adrian Prantl 3606b56784 ValueObject: Upstream early-exit from swift-lldb. (NFC) 2019-11-05 10:53:57 -08:00
Raphael Isemann 80bf88d8bc [lldb] Add trailing dots to comments in Value.cpp
Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Subscribers: JDevlieghere, lldb-commits

Tags: #upstreaming_lldb_s_downstream_patches, #lldb

Differential Revision: https://reviews.llvm.org/D69717
2019-11-04 08:35:56 +01:00
Alex Langford db542455dc [Symbol] Change ClangASTContext::GetCXXClassName return type
Summary:
Instead of filling out a std::string and returning a bool to indicate
success, returning a std::string directly and testing to see if it's
empty seems like a cleaner solution overall.

Differential Revision: https://reviews.llvm.org/D69641
2019-10-31 11:57:37 -07:00
Pavel Labath 96601ec28b ValueObject: Fix a crash related to children address type computation
Summary:
This patch fixes a crash encountered when debugging optimized code. If some
variable has been completely optimized out, but it's value is nonetheless known,
the compiler can replace it with a DWARF expression computing its value. The
evaluating these expressions results in a eValueTypeHostAddress Value object, as
it's contents are computed into an lldb buffer. However, any value that is
obtained by dereferencing pointers in this object should no longer have the
"host" address type.

Lldb had code to account for this, but it was only present in the
ValueObjectVariable class. This wasn't enough when the object being described
was a struct, as then the object holding the actual pointer was a
ValueObjectChild. This caused lldb to dereference the contained pointer in the
context of the host process and crash.

Though I am not an expert on ValueObjects, it seems to me that this children
address type logic should apply to all types of objects (and indeed, applying
applying the same logic to ValueObjectChild fixes the crash). Therefore, I move
this code to the base class, and arrange it to be run everytime the value is
updated.

The test case is a reduced and simplified version of the original debug info
triggering the crash. Originally we were dealing with a local variable, but as
these require a running process to display, I changed it to use a global one
instead.

Reviewers: jingham, clayborg

Subscribers: aprantl, lldb-commits

Differential Revision: https://reviews.llvm.org/D69273
2019-10-25 17:49:06 +00:00
Adrian Prantl 1ad655e255 Modernize the rest of the Find.* API (NFC)
This patch removes the size_t return value and the append parameter
from the remainder of the Find.* functions in LLDB's internal API. As
in the previous patches, this is motivated by the fact that these
parameters aren't really used, and in the case of the append parameter
were frequently implemented incorrectly.

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

llvm-svn: 375160
2019-10-17 19:56:40 +00:00
Martin Storsjo 13993a6f86 [LLDB] Use the llvm microsoft demangler instead of the windows dbghelp api. NFCI.
Differential Revision: https://reviews.llvm.org/D68134

llvm-svn: 375034
2019-10-16 19:39:56 +00:00
Lawrence D'Anna b07823f3e2 update ScriptInterpreterPython to use File, not FILE*
Summary:
ScriptInterpreterPython needs to save and restore sys.stdout and
friends when LLDB runs a python script.

It currently does this using FILE*, which is not optimal.  If
whatever was in sys.stdout can not be represented as a FILE*, then
it will not be restored correctly when the script is finished.

It also means that if the debugger's own output stream is not
representable as a file, ScriptInterpreterPython will not be able
to redirect python's  output correctly.

This patch updates ScriptInterpreterPython to represent files with
lldb_private::File, and to represent whatever the user had in
sys.stdout as simply a PythonObject.

This will make lldb interoperate better with other scripts or programs
that need to manipulate sys.stdout.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374964
2019-10-16 01:58:15 +00:00
Lawrence D'Anna 62c9fe4273 uint32_t options -> File::OpenOptions options
Summary:
This patch re-types everywhere that passes a File::OpenOptions
as a uint32_t so it actually uses File::OpenOptions.

It also converts some OpenOptions related functions that fail
by returning 0 or NULL into llvm::Expected

split off from https://reviews.llvm.org/D68737

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374817
2019-10-14 20:15:34 +00:00
Lawrence D'Anna b3faa01ff9 IOHandler: fall back on File::Read if a FILE* isn't available.
Summary:
IOHandler needs to read lines of input from a lldb::File.
The way it currently does this using, FILE*, which is something
we want to avoid now.   I'd prefer to just replace the FILE* code
with calls to File::Read, but it contains an awkward and
delicate workaround specific to ctrl-C handling on windows, and
it's not clear if or how that workaround would translate to
lldb::File.

So in this patch, we use use the FILE* if it's available, and only
fall back on File::Read if that's the only option.

I think this is a reasonable approach here for two reasons.  First
is that interactive terminal support is the one area where FILE*
can't be avoided.   We need them for libedit and curses anyway,
and using them here as well is consistent with that pattern.

The second reason is that the comments express a hope that the
underlying windows bug that's being worked around will be fixed one
day, so hopefully when that happens, that whole path can be deleted.

Reviewers: JDevlieghere, jasonmolenda, labath, lanza

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374576
2019-10-11 17:43:32 +00:00
Raphael Isemann 95e264fc8a [lldb][NFC] Remove strange bool parameter from Searcher::SearchCallback
Summary:
The SearchCallback has a bool parameter that we always set to false, we never use in any callback implementation and that also changes its name
from one file to the other (either `containing` and `complete`). It was added in the original LLDB check in, so there isn't any history what
this was supposed to be, so let's just remove it.

Reviewers: jingham, JDevlieghere, labath

Reviewed By: jingham, labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374313
2019-10-10 11:26:51 +00:00
Lawrence D'Anna 5da2bc22ba remove a smattering of isolated, unnecessary uses of FILE*
Summary:
There a a few call sites that use FILE* which are easy to
fix without disrupting anything else.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: JDevlieghere, labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374239
2019-10-09 21:50:52 +00:00
Lawrence D'Anna 609010d063 protect libedit and LLDB gui from receiving null FILE* streams
Summary:
We now have valid files that will return NULL from GetStream().
libedit and the LLDB gui are the only places left that need FILE*
streams.  Both are doing curses-like user interaction that only
make sense with a real terminal anyway, so there is no need to convert
them off of their use of FILE*.   But we should check for null streams
before enabling these features.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: JDevlieghere, labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374197
2019-10-09 18:43:03 +00:00
Adrian Prantl 939411c1aa Remove the is_mangled flag from Mangled and Symbol
Testing whether a name is mangled or not is extremely cheap and can be
done by looking at the first two characters. Mangled knows how to do
it. On the flip side, many call sites that currently pass in an
is_mangled determination do not know how to correctly do it (for
example, they leave out Swift mangling prefixes).

This patch removes this entry point and just forced Mangled to
determine the mangledness of a string itself.

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

llvm-svn: 374180
2019-10-09 16:22:14 +00:00
Adrian Prantl 69a3b21a5c Mark constructor as default and remove implementation (NFC)
llvm-svn: 373968
2019-10-07 21:23:19 +00:00
Michal Gorny 9735739be7 [lldb] [cmake] Support linking against clang-cpp dylib
Link against clang-cpp dylib rather than split libs when
CLANG_LINK_CLANG_DYLIB is enabled.

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

llvm-svn: 373734
2019-10-04 12:03:03 +00:00
Lawrence D'Anna f913fd6eb0 factor out an abstract base class for File
Summary:
This patch factors out File as an abstract base
class and moves most of its actual functionality into
a subclass called NativeFile.   In the next patch,
I'm going to be adding subclasses of File that
don't necessarily have any connection to actual OS files,
so they will not inherit from NativeFile.

This patch was split out as a prerequisite for
https://reviews.llvm.org/D68188

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 373564
2019-10-03 04:31:46 +00:00
Lawrence D'Anna 96898eb6a9 SBDebugger::SetInputFile, SetOutputFile, etc.
Summary:
Add new methods to SBDebugger to set IO files as SBFiles instead of
as FILE* streams.

In future commits, the FILE* methods will be deprecated and these
will become the primary way to set the debugger I/O streams.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 373563
2019-10-03 04:04:48 +00:00
Adrian Prantl bf9d84c014 Remove size_t return parameter from FindTypes
In r368345 I accidentally introduced a regression that would
over-report the number of matches found by FindTypes if the
DeclContext Filter was hit.

This patch simply removes the size_t return parameter altogether —
it's not that useful.

rdar://problem/55500457

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

llvm-svn: 373344
2019-10-01 15:40:41 +00:00
Adrian Prantl d4d428ef92 Remove unused "append" parameter from FindTypes API
I noticed that SymbolFileDWARFDebugMap::FindTypes was implementing it
incorrectly (passing append=false in a for-loop to recursive calls to
FindTypes would yield only the very last set of results), but instead
of fixing it, removing it seemed like an even better option.

rdar://problem/54412692

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

llvm-svn: 373224
2019-09-30 16:42:28 +00:00
Martin Storsjo b1cd91815e Revert "[LLDB] Use the llvm microsoft demangler instead of the windows dbghelp api. NFC."
This reverts SVN r373144, as it changed the demangled output a little, see
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/9306.

llvm-svn: 373146
2019-09-28 10:25:22 +00:00
Martin Storsjo c20fd856d9 [LLDB] Use the llvm microsoft demangler instead of the windows dbghelp api. NFC.
If there's any testcases that only do demangling (I didn't find any),
they could be made available for all platforms now.

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

llvm-svn: 373144
2019-09-28 09:33:44 +00:00
Alex Langford 92f151738b [Core] Remove unused dependency on clangAST
llvm-svn: 373134
2019-09-28 00:27:24 +00:00
Jonas Devlieghere 9a39e7f0a3 [CMake] Depend on clang-tablegen-targets
The ClangDriverOptions target is not available for standalone builds.

Thanks Alex for pointing this out!

llvm-svn: 373112
2019-09-27 19:07:06 +00:00
Jonas Devlieghere e3fed89046 [CMake] Make Core depend on ClangDriverOptions (NFC)
ModuleList.cpp includes clang/Driver/Driver.h which depends on
clang/Driver/Options.inc. This patch adds the corresponding TableGen
target to Core.

llvm-svn: 373105
2019-09-27 17:55:49 +00:00
Lawrence D'Anna 7ca15ba73f remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.

My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects.   These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods.   Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.

In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch.  In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)

However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)

In order for SBFile to use shared_ptr<File>, everything else should
as well.

If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.

Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 373090
2019-09-27 14:33:35 +00:00
Pavel Labath 7b8f546522 [lldb/cmake] add lldbCore -> clangDriver dependency
ModuleList.cpp includes clang/Driver/Driver.h. Reflect that in the build
system. Not having this can cause build failures if ModuleList.cpp is
built before Driver.inc is generated.

llvm-svn: 373073
2019-09-27 12:10:12 +00:00
Lawrence D'Anna 2fce1137c7 Convert FileSystem::Open() to return Expected<FileUP>
Summary:
This patch converts FileSystem::Open from this prototype:

Status
Open(File &File, const FileSpec &file_spec, ...);

to this one:

llvm::Expected<std::unique_ptr<File>>
Open(const FileSpec &file_spec, ...);

This is beneficial on its own, as llvm::Expected is a more modern
and recommended error type than Status.  It is also a necessary step
towards https://reviews.llvm.org/D67891, and further developments
for lldb_private::File.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

llvm-svn: 373003
2019-09-26 17:54:59 +00:00
Jonas Devlieghere 4d4a8eed06 remove unused method ResetOutputFileHandle()
ResetOutputFileHandle() isn't being used by anything. Also it's using
FILE*, which is something we should be doing less of. Remove it.

Patch by: Lawrence D'Anna

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

llvm-svn: 372800
2019-09-25 01:29:41 +00:00
Jonas Devlieghere 948786c929 File::SetDescriptor() should require options
lvm_private::File::GetStream() can fail if m_options == 0

It's not clear from the header a File created with a descriptor will be
not be usable by many parts of LLDB unless SetOptions is also called,
but it is.

This is because those parts of LLDB rely on GetStream() to use the
file, and that in turn relies on calling fdopen on the descriptor. When
calling fdopen, GetStream relies on m_options to determine the access
mode. If m_options has never been set, GetStream() will fail.

This patch adds options as a required argument to File::SetDescriptor
and the corresponding constructor.

Patch by: Lawrence D'Anna

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

llvm-svn: 372652
2019-09-23 20:36:46 +00:00
Martin Storsjo 8b98f12a7a [LLDB] Check for _WIN32 instead of _MSC_VER for code specific to windows in general
These ifdefs contain code that isn't specific to MSVC but useful for
any windows target, like MinGW.

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

llvm-svn: 372592
2019-09-23 12:03:56 +00:00
Haibo Huang 5c82608d20 Use _WIN32 instead of _MSC_VER
Summary: This way it works better with MinGW.

Subscribers: mstorsjo, lldb-commits

Tags: #lldb

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

llvm-svn: 372493
2019-09-22 01:21:34 +00:00
Adrian Prantl 9b23df63ec Implement DW_OP_convert
This patch adds basic support for DW_OP_convert[1] for integer
types. Recent versions of LLVM's optimizer may insert this opcode into
DWARF expressions. DW_OP_convert is effectively a type cast operation
that takes a reference to a base type DIE (or zero) and then casts the
value at the top of the DWARF stack to that type. Internally this
works by changing the bit size of the APInt that is used as backing
storage for LLDB's DWARF stack.

I managed to write a unit test for this by implementing a mock YAML
object file / module that takes debug info sections in yaml2obj
format.

[1] Typed DWARF stack. http://www.dwarfstd.org/ShowIssue.php?issue=140425.1

<rdar://problem/48167864>

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

llvm-svn: 371532
2019-09-10 16:17:38 +00:00
Alex Langford b482db6dfe [Core] Remove use of ClangASTContext in DumpDataExtractor
Summary:
DumpDataExtractor uses ClangASTContext in order to get the proper llvm
fltSemantics for the type it needs so that it can dump floats in a more
precise way. However, there's no reason that this behavior needs to be
specific ClangASTContext. Instead, I think it makes sense to ask
TypeSystems for the float semantics for a type of a given size.

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

llvm-svn: 371258
2019-09-06 21:05:21 +00:00
Jonas Devlieghere 0910e17d52 [Disassembler] Simplify a few methods (2/2) (NFC)
Use early returns to highlight preconditions and make the code easier to
follow.

llvm-svn: 370998
2019-09-04 23:05:32 +00:00
Jonas Devlieghere 4be6706eb6 [Disassembler] Simplify a few methods (NFC)
Use early returns to highlight preconditions and make the code easier to
follow.

llvm-svn: 370994
2019-09-04 22:38:20 +00:00
Adrian Prantl 2461061168 Upstream macCatalyst support in debugserver and the macOS dynamic loader
plugin.

Unfortunately the test is currently XFAILed because of missing changes
to the clang driver.

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

llvm-svn: 370931
2019-09-04 17:23:15 +00:00
Raphael Isemann e5814d78ce [lldb] Limit the amount of zeroes we use for padding when printing small floats
Summary:
We got a radar that printing small floats is not very user-friendly in LLDB as we print them with up to
100 leading zeroes before starting to use scientific notation. This patch changes this by already using
scientific notation when we hit 6 padding zeroes by default and moves this value into a target setting
so that users can just set this number back to 100 if they for some reason preferred the old behaviour.

This new setting is influencing how we format data, so that's why we have to reset the data visualisation
cache when it is changed.

Note that we have always been using scientific notation for large numbers because it seems that
the LLVM implementation doesn't support printing out the padding zeroes for them. I would have fixed
that if it was trivial, but looking at the LLVM implementation for this it seems that this is not as trivial
as it sounds. I would say we look into this if we ever get a bug report about someone wanting to have
a large amount of trailing zeroes in their numbers instead of using scientific notation.

Fixes rdar://39744137

Reviewers: #lldb, clayborg

Reviewed By: clayborg

Subscribers: JDevlieghere, lldb-commits

Tags: #lldb

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

llvm-svn: 370880
2019-09-04 11:41:23 +00:00
Alex Langford 3e45e3ba95 [Core] Use GetAPInt instead of constructing APInts in place
GetAPInt should be able to handle all cases. I have plans to generalize
the float dumping logic and this makes it easier to do later.

llvm-svn: 370255
2019-08-28 20:15:57 +00:00
Alex Langford 5e777e1ed2 [Core] GetAPInt should return an Optional
The current implementation returns a bool for indicating success and
whether or not the APInt passed by reference was populated. Instead of
doing that, I think it makes more sense to return an Optional<APInt>.

llvm-svn: 369970
2019-08-26 21:09:57 +00:00
Raphael Isemann d43d912b4b [lldb] Construct the dummy target when the first Debugger object is constructed
Summary:
We should always have a dummy target, so we might as well construct it directly when we create a Debugger object.

The idea is that if this patch doesn't cause any problems that we can get rid of all the logic
that handles situations where we don't have a dummy target (as all that code is currently
untested as there seems to be no way to have no dummy target in LLDB).

Reviewers: labath, jingham

Reviewed By: labath, jingham

Subscribers: jingham, abidh, lldb-commits

Tags: #lldb

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

llvm-svn: 369885
2019-08-26 09:20:59 +00:00
Adrian Prantl aa97a89d83 Extend FindTypes with CompilerContext to allow filtering by language.
This patch is also motivated by the Swift branch and is effectively NFC for the single-TypeSystem llvm.org branch.

In multi-language projects it is extremely common to have, e.g., a
Clang type and a similarly-named rendition of that same type in
another language. When searching for a type It is much cheaper to pass
a set of supported languages to the SymbolFile than having it
materialize every result and then rejecting the materialized types
that have the wrong language.

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

<rdar://problem/54471165>

This reapplies r369690 with a previously missing constructor for LanguageSet.

llvm-svn: 369710
2019-08-22 21:45:58 +00:00
Adrian Prantl b041602e3f Revert Extend FindTypes with CompilerContext to allow filtering by language.
This reverts r369690 (git commit aa3a564efa)

llvm-svn: 369702
2019-08-22 20:41:16 +00:00
Adrian Prantl aa3a564efa Extend FindTypes with CompilerContext to allow filtering by language.
This patch is also motivated by the Swift branch and is effectively NFC for the single-TypeSystem llvm.org branch.

In multi-language projects it is extremely common to have, e.g., a
Clang type and a similarly-named rendition of that same type in
another language. When searching for a type It is much cheaper to pass
a set of supported languages to the SymbolFile than having it
materialize every result and then rejecting the materialized types
that have the wrong language.

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

<rdar://problem/54471165>

llvm-svn: 369690
2019-08-22 19:24:55 +00:00
Raphael Isemann 1153dc9603 [lldb][NFC] NFC cleanup for the completion code
llvm-svn: 369632
2019-08-22 09:02:54 +00:00
Raphael Isemann ae34ed2c0d [lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:

* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.

I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.

A few words why those things should be removed/replaced:

* The return values are really cryptic, partly redundant and rarely documented.
  They are also completely ignored by Xcode, so whatever information they contain will end up
  breaking Xcode's completion mechanism. They are also partly impossible to even implement
  as we assign negative values special meaning and our completion API sometimes returns size_t.

  Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
  in some untested code path to expand the history repeat character to the full command, but
  I haven't figured out why that doesn't work at the moment.
  Completion functions return -1 to 'insert the completion character', but that isn't implemented
  (even though we seem to activate this feature in LLDB sometimes).
  All positive values have to match the number of results. This is obviously just redundant information
  as the user can just look at the result list to get that information (which is what Xcode does).

* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
  reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
  that we calculate this to make the life of the API caller easier, but obviously forcing people to have
  1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
  0-based like Xcode has to do).

* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
  idea is that we let the top-level API know that we just provided a full completion. Interestingly we
  `WordComplete` is just a single bool that somehow represents all N completions. And we always
  provide full completions in LLDB, so in theory it should always be true.
  The only use it currently serves is providing redundant information about whether we have a single
  definitive completion or not (which we already know from the number of results we get).

This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.

For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).

I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Subscribers: arphaman, abidh, lldb-commits

Tags: #lldb

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

llvm-svn: 369624
2019-08-22 07:41:23 +00:00
Jonas Devlieghere 4b3c0fd5da [NFC] Remove lldb_utility namespace.
While generating the Doxygen I noticed this lone namespace that has one
class and one function in it. This moves them into lldb_private.

llvm-svn: 369485
2019-08-21 00:50:46 +00:00
Jan Kratochvil f9d90bc5f6 [lldb] D66174 `RegularExpression` cleanup
I find as a good cleanup to drop the Compile method. As I do not find TIMTOWTDI
as an advantage and there is already constructor parameter to compile the
regex.

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

llvm-svn: 369352
2019-08-20 09:24:20 +00:00
Matthias Gehre 8b0d15e43f Fix use-after-free
Summary:
The warning
```
lldb/source/Core/FormatEntity.cpp:2350:25: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling]
```
is emitted after annotating `llvm::StringRef` with `[[gsl::Pointer]]`.

The reason is that in
```
 size_t FormatEntity::AutoComplete(CompletionRequest &request) {
  llvm::StringRef str = request.GetCursorArgumentPrefix().str();
```
the function `GetCursorArgumentPrefix()` returns a `StringRef`, and `StringRef::str()` returns
a temporary `std::string`.

Reviewers: jingham, JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 369304
2019-08-19 21:39:16 +00:00
Jonas Devlieghere 3af3f1e8e2 [Utility] Reimplement RegularExpression on top of llvm::Regex
Originally I wanted to remove the RegularExpression class in Utility and
replace it with llvm::Regex. However, during that transition I noticed
that there are several places where need the regular expression string.
So instead I propose to keep the RegularExpression class and make it a
thin wrapper around llvm::Regex.

This patch also removes the workaround for empty regular expressions.
The result is that we are now (more or less) POSIX conformant.

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

llvm-svn: 369153
2019-08-16 21:25:36 +00:00
Raphael Isemann 2fc20f652c [lldb][NFC] Refactor remaining completion logic to use CompletionRequests
This patch moves the remaining completion functions from the
old completion API (that used several variables) to just
passing a single CompletionRequest.

This is for the most part a simple change as we just replace
the old arguments with a single CompletionRequest argument.

There are a few places where I had to create new CompletionRequests
in the called functions as CompletionRequests itself are immutable
and don't expose their internal match list anymore. This means that
if a function wanted to change the CompletionRequest or directly
access the result list, we need to work around this by creating
a new CompletionRequest and a temporary match/description list.

Preparation work for rdar://53769355

llvm-svn: 369000
2019-08-15 13:14:10 +00:00
Jonas Devlieghere a8f3ae7c9c [LLDB] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

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

llvm-svn: 368933
2019-08-14 22:19:23 +00:00
Adrian Prantl d9cbd2acfa Remove unused and undocumented data_offset parameter (NFC)
Value::GetValueAsData() takes an undocumented parameter called
data_offset that is always 0.

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

llvm-svn: 368330
2019-08-08 19:22:32 +00:00
Pavel Labath 579d6d1aa5 Remove Module::GetSymbolVendor
Summary:
This patch removes the GetSymbolVendor function, and the various
mentions of the SymbolVendor in the Module class. The implementation of
GetSymbolVendor is "inlined" into the GetSymbolFile class which I
created earlier.

After this patch, the SymbolVendor class still exists inside the Module
object, but only as an implementation detail -- a fancy holder for the
SymbolFile. That will be removed in the next patch.

Reviewers: clayborg, JDevlieghere, jingham, jdoerfert

Subscribers: jfb, lldb-commits

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

llvm-svn: 368263
2019-08-08 07:34:07 +00:00
Adrian Prantl f81d6fe75c Adjust a ValueObjectChild's offset when the child is a bitfield
If a bitfield doesn't fit into the child_byte_size'd window at
child_byte_offset, move the window forward until it fits.  The problem
here is that Value has no notion of bitfields and thus the Value's
DataExtractor is sized like the bitfields CompilerType; a sequence of
bitfields, however, can be larger than their underlying type.

This was not in the big-endian-derived DWARF 2 bitfield attributes
because their offsets were counted from the end of the window, so they
always fit.

rdar://problem/53132189

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

llvm-svn: 368226
2019-08-07 22:40:05 +00:00
Jonas Devlieghere 171dd2e6e5 [Gardening] Remove more dead code from IOHandler
Remove more dead code and reformat the file.

llvm-svn: 368116
2019-08-07 01:50:03 +00:00
Pavel Labath 1177bc597d ObjectFileELF: permit thread-local sections with overlapping file addresses
Summary:
In an attempt to make file-address-based lookups more predictable, in D55998
we started ignoring sections which would result in file address
overlaps. It turns out this was too aggressive because thread-local
sections typically will have file addresses which apear to overlap
regular data/code. This does not cause a problem at runtime because
thread-local sections are loaded into memory using special logic, but it
can cause problems for lldb when trying to lookup objects by their file
address.

This patch changes ObjectFileELF to permit thread-local sections to
overlap regular ones by essentially giving them a separate address
space. It also makes them more symmetrical to regular sections by
creating container sections from PT_TLS segments.

Simultaneously, the patch changes the regular file address lookup logic
to ignore sections with the thread-specific bit set. I believe this is
what the users looking up file addresses would typically expect, as
looking up thread-local data generally requires more complex logic (e.g.
DWARF has a special opcode for that).

Reviewers: clayborg, jingham, MaskRay

Subscribers: emaste, aprantl, arichardson, lldb-commits

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

llvm-svn: 368010
2019-08-06 10:04:27 +00:00
Pavel Labath 465eae3669 SymbolVendor: Remove passthrough methods
After the recent refactorings the SymbolVendor passthrough no longer
serve any purpose. This patch removes those methods, and updates all
callsites to go to the symbol file directly -- in most cases that just
means calling GetSymbolFile()->foo() instead of
GetSymbolVendor()->foo().

llvm-svn: 368001
2019-08-06 09:12:42 +00:00
Jonas Devlieghere 3c3dce2545 [Gardening] Remove dead code from IOHandler (NFC)
These functions are not referenced.

llvm-svn: 367976
2019-08-06 04:45:55 +00:00
Pavel Labath d5d47a3574 Remove SymbolVendor::GetSymtab
Summary:
This patch removes the GetSymtab method from the SymbolVendor, which is
a no-op as it's implementation just forwards to the relevant SymbolFile.
Instead it creates a Module::GetSymtab, which calls the SymbolFile
method directly.

All callers have been updated to use the Module method directly instead
of a two phase GetSymbolVendor->GetSymtab search, which leads to reduced
intentation in a lot of deeply nested code.

Reviewers: clayborg, JDevlieghere, jingham

Subscribers: lldb-commits

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

llvm-svn: 367820
2019-08-05 09:21:47 +00:00
Fangrui Song d9b948b6eb Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC
F_{None,Text,Append} are kept for compatibility since r334221.

llvm-svn: 367800
2019-08-05 05:43:48 +00:00
Joseph Tremoulet 31e6dbe1c6 Fix PC adjustment in StackFrame::GetSymbolContext
Summary:
Update StackFrame::GetSymbolContext to mirror the logic in
RegisterContextLLDB::InitializeNonZerothFrame that knows not to do the
pc decrement when the given frame is a signal trap handler frame or the
parent of one, because the pc may not follow a call in these frames.
Accomplish this by adding a behaves_like_zeroth_frame field to
lldb_private::StackFrame, set to true for the zeroth frame, for
signal handler frames, and for parents of signal handler frames.

Also add logic to propagate the signal handler flag from UnwindPlan to
the FrameType on the RegisterContextLLDB it generates, and factor out a
helper to resolve symbol and address range for an Address now that we
need to invoke it in four places.

Reviewers: jasonmolenda, clayborg, jfb

Reviewed By: jasonmolenda

Subscribers: labath, dexonsmith, lldb-commits

Tags: #lldb

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

llvm-svn: 367691
2019-08-02 16:53:42 +00:00
Pavel Labath 23f70e8359 SymbolVendor: Introduce Module::GetSymbolFile
Summary:
This is the next step in avoiding funneling all SymbolFile calls through
the SymbolVendor. Right now, it is just a convenience function, but it
allows us to update all calls to SymbolVendor functions to access the
SymbolFile directly. Once all call sites have been updated, we can
remove the GetSymbolVendor member function.

This patch just updates the calls to GetSymbolVendor, which were calling
it just so they could fetch the underlying symbol file. Other calls will
be done in follow-ups.

Reviewers: JDevlieghere, clayborg, jingham

Subscribers: lldb-commits

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

llvm-svn: 367664
2019-08-02 08:16:35 +00:00
Jonas Devlieghere e063eccc19 Format OptionEnumValueElement (NFC)
Reformat OptionEnumValueElement to make it easier to distinguish between
its fields. This also removes the need to disable clang-format for these
arrays.

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

llvm-svn: 367638
2019-08-02 00:18:44 +00:00
Pavel Labath a9d58436af Fix issues with inferior stdout coming out of order
Summary:
We've had a bug where two pieces of code, executing on two threads were
attempting to write inferior output simultaneously. The first one was in
Debugger::HandleProcessEvent, which handled the cases where stdout was
coming while the process was running. The second was in
CommandInterpreter::IOHandlerInputComplete, which was ensuring that any
output is printed before the command which caused process to run
terminates.

Both of these things make sense, but the fact they were implemented as
two independent functions without any synchronization meant that race
conditions could occur (e.g. both threads call process->GetSTDOUT, get
two chunks of data, but then end up calling stream->Write in opposite
order). This was most apparent in situations where a process quickly
writes a bunch of output and then exits (as all our register tests do).

This patch adds a mutex to ensure that stdout forwarding happens
atomically. It also refactors a code somewhat in order to reduce code
duplication.

Reviewers: clayborg, jingham

Subscribers: jfb, mgorny, lldb-commits

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

llvm-svn: 367418
2019-07-31 12:06:50 +00:00
Jonas Devlieghere b22860da61 [CompletionRequest] Remove unimplemented members.
Completion requests have two fields that are essentially unimplemented:
`m_match_start_point` and `m_max_return_elements`. This would've been
okay, if it wasn't for the fact that this caused a bunch of useless
parameters to be passed around. Occasionally there would be a comment or
assert saying that they are not supported. This patch removes them.

llvm-svn: 367385
2019-07-31 03:48:29 +00:00
Jonas Devlieghere 175f093090 [StringList] Change LongestCommonPrefix API
When investigating a completion bug I got confused by the API.
LongestCommonPrefix finds the longest common prefix of the strings in
the string list. Instead of returning that string through an output
argument, just return it by value.

llvm-svn: 367384
2019-07-31 03:26:10 +00:00
Alex Langford 0e252e38ef [Symbol] Use llvm::Expected when getting TypeSystems
Summary:
This commit achieves the following:
- Functions used to return a `TypeSystem *` return an
  `llvm::Expected<TypeSystem *>` now. This means that the result of a call
  is always checked, forcing clients to move more carefully.
- `TypeSystemMap::GetTypeSystemForLanguage` will either return an Error or a
  non-null pointer to a TypeSystem.

Reviewers: JDevlieghere, davide, compnerd

Subscribers: jdoerfert, lldb-commits

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

llvm-svn: 367360
2019-07-30 22:12:34 +00:00
Raphael Isemann e010f6bab3 [lldb] Fix crash when tab-completing in multi-line expr
Summary:
Tab completing inside the multiline expression command can cause LLDB to crash. The easiest way
to do this is to go inside a frame with at least one local variable and then try to complete:

    (lldb) expr
    1. a[tab]

Reason for this was some mixup when we calculate the cursor position. Obviously we should calculate
the offset inside the string by doing 'end - start', but we are doing 'start - end' (which causes the offset to
become -1 which will lead to some out-of-bounds reading).

Fixes rdar://51754005

I don't see any way to test this as the *multiline* expression completion is completely untested at the moment
and I don't think we have any existing code for testing infrastructure for it.

Reviewers: shafik, davide, labath

Reviewed By: labath

Subscribers: abidh, lldb-commits, davide, clayborg, labath

Tags: #lldb

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

llvm-svn: 367308
2019-07-30 12:31:24 +00:00
Jordan Rupprecht 6a253d378b [lldb] Qualify includes of Properties[Enum].inc files. NFC
Summary:
This is a bit more explicit, and makes it possible to build LLDB without
varying the -I lines per-directory.
(The latter is useful because many build systems only allow this to be
configured per-library, and LLDB is insufficiently layered to be split into
multiple libraries on stricter build systems).

(My comment on D65185 has some more context)

Reviewers: JDevlieghere, labath, chandlerc, jdoerfert

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

Patch by Sam McCall!

llvm-svn: 367241
2019-07-29 17:22:10 +00:00
Jonas Devlieghere a8ea595509 [lldb] Also include the array definition in Properties.inc
Right now our Properties.inc only generates the initializer for the
options list but not the array declaration boilerplate around it. As the
array definition is identical for all arrays, we might as well also let
the Properties.inc generate it alongside the initializers.

Unfortunately we cannot do the same for enums, as there's this magic
ePropertyExperimental, which needs to come at the end to be interpreted
correctly. Hopefully we can get rid of this in the future and do the
same for the property enums.

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

llvm-svn: 367238
2019-07-29 16:41:30 +00:00
Jonas Devlieghere d4044aad66 [TableGen] Fix stale include paths
This worked locally because the include files were not regenerated, but
fails when performing a clean build.

llvm-svn: 367152
2019-07-26 20:55:07 +00:00
Jonas Devlieghere 01f277e2db [TableGen] Move core properties into a separate file (NFC)
With the plugins having their own tablgen file, it makes sense to split
off the core properties as well.

llvm-svn: 367140
2019-07-26 18:14:12 +00:00
Jonas Devlieghere 971f9ca612 Let tablegen generate property definitions
Property definitions are currently defined in a PropertyDefinition array
and have a corresponding enum to index in this array. Unfortunately this
is quite error prone. Indeed, just today we found an incorrect merge
where a discrepancy between the order of the enum values and their
definition caused the test suite to fail spectacularly.

Tablegen can streamline the process of generating the property
definition table while at the same time guaranteeing that the enums stay
in sync. That's exactly what this patch does. It adds a new tablegen
file for the properties, building on top of the infrastructure that
Raphael added recently for the command options. It also introduces two
new tablegen backends: one for the property definitions and one for
their corresponding enums.

It might be worth mentioning that I generated most of the tablegen
definitions from the existing property definitions, by adding a dump
method to the struct. This seems both more efficient and less error
prone that copying everything over by hand. Only Enum properties needed
manual fixup for the EnumValues and DefaultEnumValue fields.

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

llvm-svn: 367058
2019-07-25 21:36:37 +00:00
Pavel Labath f46e8974de SymbolVendor: Remove the type list member
Summary:
Similarly to the compile unit lists, the list of types can also be
managed by the symbol file itself.

Since the only purpose of this list seems to be to maintain an owning
reference to all the types a symbol file has created (items are only
ever added to the list, never retrieved), I remove the passthrough
functions in SymbolVendor and Module. I also tighten the interface of
the function (return a reference instead of a pointer, make it protected
instead of public).

Reviewers: clayborg, JDevlieghere, jingham

Subscribers: lldb-commits

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

llvm-svn: 366994
2019-07-25 08:22:05 +00:00
Jonas Devlieghere 63e5fb76ec [Logging] Replace Log::Printf with LLDB_LOG macro (NFC)
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF
macro. The macro is similar to LLDB_LOG but supports printf-style format
strings, instead of formatv-style format strings.

So instead of writing:

  if (log)
    log->Printf("%s\n", str);

You'd write:

  LLDB_LOG(log, "%s\n", str);

This change was done mechanically with the command below. I replaced the
spurious if-checks with vim, since I know how to do multi-line
replacements with it.

  find . -type f -name '*.cpp' -exec \
  sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" +

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

llvm-svn: 366936
2019-07-24 17:56:10 +00:00
Jonas Devlieghere eaedc5ef8f [Logging] Fix format strings
Change format strings to use the `{}` syntax instead of the printf
syntax when using LLDB_LOG.

llvm-svn: 366824
2019-07-23 17:03:37 +00:00
Jonas Devlieghere b2a9cf7764 [Logging] Replace LogIfAnyCategoriesSet with LLDB_LOG.
This patch removes any remaining instances of LogIfAnyCategoriesSet and
replaces them with the LLDB_LOG macro. This in turn made it possible to
make Log::VAPrintf and Log::VAError private.

llvm-svn: 366768
2019-07-22 23:48:01 +00:00
Alex Langford 4de5d9d612 [Symbol] Improve Variable::GetLanguage
Summary:
When trying to ascertain what language a variable belongs to, just
checking the compilation unit is often not enough. In r364845 I added a way to
check for a variable's language type, but didn't put it in Variable itself.
Let's go ahead and put it in Variable.

Reviewers: jingham, clayborg

Subscribers: jdoerfert, lldb-commits

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

llvm-svn: 366733
2019-07-22 20:14:18 +00:00
Nathan Lanza cb30520555 check for interrupt from fgets on Windows
Windows does not have the error EINTR when a blocking syscall is
interrupted by a signal. The ReadFile API that fgets is implemented
with instead use ERROR_OPERATION_ABORTED. Check for that after fgets.

llvm-svn: 366520
2019-07-19 00:40:37 +00:00
Jonas Devlieghere f893d5bf0f [FileSpecList] Add EmplaceBack method (NFC)
Instead of having to write FileSpecList::Append(FileSpec(args)) you can
now call FileSpecList::EmplaceBack(args), similar to
std::vector<>::emplace_back.

llvm-svn: 366489
2019-07-18 20:19:24 +00:00
Nathan Lanza e71679082c add a workaround in GetLine to account for ReadFile not reporintg error
Summary:
ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED according
to the docs on MSDN. However, this has evidently been a known bug since
Windows 8. Therefore, we can't detect if a signal interrupted in the
fgets. So pressing ctrl-c causes the repl to end and the process to
exit. A temporary workaround is just to attempt to fgets twice until
this bug is fixed.

A possible alternative would be to set a flag in the `sigint_handler`
and simply check that flag in the true part of the if statement.
However, signal handlers on Windows are asynchronous and this would
require sleeping on the repl loop thread while still not necessarily
guarnateeing that you caught the sigint.

Reviewers: jfb

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

llvm-svn: 366281
2019-07-16 23:01:59 +00:00
Alex Langford 24604ec799 [Core] Generalize ValueObject::MaybeCalculateCompleteType
Summary:
Instead of hardcoding ClangASTContext and ObjCLanguageRuntime, we can
generalize this by creating the method GetRuntimeType in
LanguageRuntime and moving the current MaybeCalculateCompleteType
implementation into ObjCLanguageruntime::GetRuntimeType

Reviewers: jingham, clayborg, JDevlieghere

Subscribers: lldb-commits

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

llvm-svn: 365939
2019-07-12 18:34:37 +00:00
Jonas Devlieghere f39c2e188d Change LaunchThread interface to return an expected.
Change the interface to return an expected, instead of taking a Status
pointer.

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

llvm-svn: 365226
2019-07-05 17:42:08 +00:00
Alex Langford d7fcee62f1 [Core] Generalize ValueObject::IsRuntimeSupportValue
Summary:
Instead of falling back to ObjCLanguageRuntime, we should be falling
back to every loaded language runtime. This makes ValueObject more
language agnostic.

Reviewers: labath, compnerd, JDevlieghere, davide

Subscribers: lldb-commits

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

llvm-svn: 364845
2019-07-01 20:36:33 +00:00
Alex Langford 7f9c9f2264 [Target] Decouple ObjCLanguageRuntime from LanguageRuntime
Summary:
ObjCLanguageRuntime was being pulled into LanguageRuntime because of
Breakpoint Preconditions. If we move BreakpointPrecondition out of Breakpoint,
we can extend the LanguageRuntime plugin interface so that LanguageRuntimes
can give us a BreakpointPrecondition for exceptions.

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

llvm-svn: 364098
2019-06-21 19:43:07 +00:00
Jonas Devlieghere f9626f27c8 Add color to the default thread and frame format.
Now that we correctly ignore ASCII escape sequences when colors are
disabled (r362240), I'd like to change the default frame and thread
format to include color in their output, in line with the syntax
highlighting that Raphael added a while ago.

This patch adds highlighting for the stop reason, the file, line and
column number. With colors disabled, this of course is a no-op.

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

llvm-svn: 363608
2019-06-17 19:53:11 +00:00