Commit Graph

1872 Commits

Author SHA1 Message Date
Pavel Labath 3d4f7655e7 Remove usage of usleep in generic code
This function is not portable, and there are only a handful of usages of
it anyway. Replacing it with std::this_thread::sleep_for enables us to
get rid of the compatibility code in PosixApi.h.

llvm-svn: 367814
2019-08-05 08:23:25 +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
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
Alex Langford 70402bfc46 [API] Remove use of ClangASTContext from SBTarget
Summary:
The methods to find types in a Target aren't clang specific and are
pretty generalizable to type systems. Additionally, to support some of
the use cases in SBTarget, I've added a "GetScratchTypeSystems" method
to Target to support getting all type systems for a target we are
debugging.

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

llvm-svn: 367480
2019-07-31 20:47:38 +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
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 463a48e416 [TableGen] Move target properties into a separate file (NFC)
With the plugins having their own tablgen file, it makes sense to split
off the target properties as well.

llvm-svn: 367139
2019-07-26 18:14:08 +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
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
Jonas Devlieghere d3607756dd [Target] Fix formatting and whitespace (NFC)
llvm-svn: 366522
2019-07-19 00:56:26 +00:00
Jonas Devlieghere 0288c26968 [Target] Return an llvm::Expected from GetEntryPointAddress (NFC)
Instead of taking a status and potentially returning an invalid address,
return an expected which is guaranteed to contain a valid address.

llvm-svn: 366521
2019-07-19 00:52:08 +00:00
Jason Molenda 956761adb0 Fall back to dyld's _dyld_start when no LC_MAIN / main() func can be found
The new DriverKit user-land kernel drivers in macOS 10.15 / Catalina 
do not have a main() function or an LC_MAIN load command.  lldb uses
the address of main() as the return address for inferior function
calls; it puts a breakpoint on main, runs the inferior function call,
and when the main() breakpoint is hit, lldb knows unambiguously that
the inferior function call ran to completion - no other function calls
main.

This change hoists the logic for finding the "entry address" from 
ThreadPlanCallFunction to Target.  It changes the logic to first
try to get the entry address from the main executable module,
but if that module does not have one, it will iterate through all
modules looking for an entry address.

The patch also adds code to ObjectFileMachO to use dyld's 
_dyld_start function as an entry address.

<rdar://problem/52343958> 

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

llvm-svn: 366493
2019-07-18 20:55:24 +00:00
Alex Langford fc1c8f5d7d [Target][NFCI] Remove commented out code
llvm-svn: 366295
2019-07-17 07:13:42 +00:00
Alex Langford e574f8b3d8 [Target][NFCI] Rename variable
This variable doesn't have anything to do with clang.

llvm-svn: 366292
2019-07-17 07:03:17 +00:00
Alex Langford 0d12127318 [Target] Remove unused method Target::GetDefaultClangModuleSearchPaths
llvm-svn: 366161
2019-07-16 01:02:32 +00:00
Alex Langford b5701710a4 [LanguageRuntime] Move ObjCLanguageRuntime into a plugin
Summary:
Following up to my CPPLanguageRuntime change, I'm moving
ObjCLanguageRuntime into a plugin as well.

Reviewers: JDevlieghere, compnerd, jingham, clayborg

Subscribers: mgorny, arphaman, lldb-commits

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

llvm-svn: 366148
2019-07-15 22:56:12 +00:00
Alex Langford e0678ca547 [LanguageRuntime] Move CPPLanguageRuntime into a plugin
Summary: This seems better suited to be in a plugin.

Reviewers: JDevlieghere, clayborg, jingham, compnerd, labath

Subscribers: mgorny, lldb-commits

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

llvm-svn: 365951
2019-07-12 20:09:32 +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
Alex Langford bab7e3d78b [Expression] Move IRDynamicChecks to ClangExpressionParser
Summary:
IRDynamicChecks in its current form is specific to Clang since it deals
with the C language family. It is possible that we may want to
instrument code generated for other languages, but we can factor in a
more general mechanism to do so at a later time.

This decouples ObCLanguageRuntime from Expression!

Reviewers: compnerd, clayborg, jingham, JDevlieghere

Subscribers: mgorny, lldb-commits

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

llvm-svn: 365853
2019-07-12 00:58:02 +00:00
Alex Langford 2c3c045dcb [Target] Replace Plugin headers with non-plugin headers
llvm-svn: 365843
2019-07-11 23:45:35 +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
Jim Ingham 8864b4360a Make sure the thread list is updated before you set the stop reason
on a thread.  When talking to some older gdb-remote stubs, We were getting
a stop reason from the stop reply packet and setting it on the relevant
thread before we updated the full stop list.  That would get discarded when
the full list was updated.

Also, if you already have a thread list when you go to see if there is an
Operating System plugin, and you do indeed load a new OS plugin, you have to
re-fetch the thread list or it will only show the raw threads.

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

llvm-svn: 364666
2019-06-28 17:57:19 +00:00
Adrian Prantl 510f4098ae Add a defensive check for nullptr as in the block above.
Unfortunately I had to work backwards from a crash log,
so I don't have a good testcase at this point in time.

rdar://problem/51874647

llvm-svn: 364344
2019-06-25 19:50:12 +00:00
Pavel Labath 7ada1c5300 Remove core loading timeout
Summary:
If target.preload-symbols is false, waiting for the process to "stop"
can take an arbitrarily long amount of time, because it will cause all
the debug info to be parsed (to compute the stop message showing the
function, its arguments, etc).

We were previously waiting for 10 seconds for the stop even to arrive,
which is a pretty long time, but it's not that hard to overcome with
huge debug info.

Since any arbitrary limit can be theoretically overcome with huge
debug_info and/or slow machine, and the stop even was sent 3 lines above
the wait, if we ever do not receive the stop even means we've got a bug
in lldb. Therefore, I remove the timeout on this wait completely.

No test because I don't know how to reproduce this without a
multi-gigabyte symbol file.

Reviewers: jingham, clayborg

Subscribers: aprantl, lldb-commits

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

llvm-svn: 364276
2019-06-25 07:14:29 +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
Alex Langford 6691f1b6cd [LanguageRuntime] Simplify CreateExceptionSearchFilter in derived classes
llvm-svn: 363109
2019-06-11 22:52:08 +00:00
Antonio Afonso 943faef1fa Add support to read aux vector values
Summary:
This is the second patch to improve module loading in a series that started here (where I explain the motivation and solution): https://reviews.llvm.org/D62499

I need to read the aux vector to know where the r_debug map with the loaded libraries are.
The AuxVector class was made generic so it could be reused between the POSIX-DYLD plugin and NativeProcess*. The class itself ended up in the ProcessUtility plugin.

Reviewers: clayborg, xiaobai, labath, JDevlieghere

Reviewed By: clayborg, labath, JDevlieghere

Subscribers: emaste, JDevlieghere, mgorny, lldb-commits

Tags: #lldb

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

llvm-svn: 363098
2019-06-11 20:16:13 +00:00
Tatyana Krasnukha f62e23d901 [Target] Use llvm::scope_exit to restore m_suppress_stop_hooks value.
llvm-svn: 362985
2019-06-10 21:13:37 +00:00
Alex Langford e823bbe8d1 [Target] Remove Process::GetObjCLanguageRuntime
Summary:
In an effort to make Process more language agnostic, I removed
GetCPPLanguageRuntime from Process. I'm following up now with an equivalent
change for ObjC.

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

llvm-svn: 362981
2019-06-10 20:53:23 +00:00
Alex Langford ddcd5b0a0f [Target] Remove unused header from Process
I forgot to remove this when I removed GetCPPLanguageRuntime from
Process

llvm-svn: 362885
2019-06-08 19:07:05 +00:00
Alex Langford 056f6f1856 [LanguageRuntime] Introduce LLVM-style casts
Summary:
Using llvm-style rtti gives us stronger guarantees around casting
LanguageRuntimes.

As discussed in D62755

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

llvm-svn: 362884
2019-06-08 18:45:00 +00:00
Alex Langford 29975a2a5d [Target] Remove Process::GetCPPLanguageRuntime
Summary:
I want to remove this method because I think that Process should be
language agnostic, or at least, not have knowledge about specific language
runtimes. There is "GetLanguageRuntime()" which should be used instead. If the
caller a CPPLanguageRuntime, they should cast it as needed. Ideally, this
should only happen in plugins that need C++ specific knowledge.

The next step I would like to do is remove "GetObjCLanguageRuntime()" as well.
There are a lot more instances of that function being used, so I wanted to
upload this one first to get the general reception to this idea.

Reviewers: compnerd, davide, JDevlieghere, jingham, clayborg, labath, aprantl

Subscribers: lldb-commits

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

llvm-svn: 362544
2019-06-04 20:14:33 +00:00
Alex Langford b978f72058 [Target] Generalize some behavior in Target::SymbolsDidLoad
Summary:
SymbolsDidLoad is currently only implemented for ObjCLanguageRuntime,
but that doesn't mean that it couldn't be useful for other Langauges. Although
this change seems like it's generalizing for the sake of purity, this removes
Target's dependency on ObjCLanguageRuntime.

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

llvm-svn: 362461
2019-06-03 23:12:11 +00:00
Alex Langford 591ede411d [Target] Adjust header in Thread
llvm-svn: 362318
2019-06-02 06:03:05 +00:00
Alex Langford 4dc0acc915 [Target] Remove ABI's dependence on ExpressionParser
llvm-svn: 362259
2019-05-31 20:17:21 +00:00
Alex Langford e5a7a858f5 [Target] Generalize language-specific behavior in ThreadPlanStepThrough
Summary:
When creating a ThreadPlan to step through a trampoline, we ask the
ObjC language runtime and the CPP language runtime to come up with such a thread
plan if the dynamic loader fails to give us one. I don't see why this behavior
can't be language agnostic.

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

llvm-svn: 362164
2019-05-30 22:00:18 +00:00
Alex Langford 41dc5526a6 [Target] Generalize Process::IsPossibleDynamicValue
llvm-svn: 362154
2019-05-30 21:03:53 +00:00
Alex Langford 7d3e97fbe6 [Target] Sink some asserts into Process::GetLanguageRuntime
llvm-svn: 362032
2019-05-29 21:07:53 +00:00
Alex Langford 03e1a82f52 [Target] Introduce Process::GetLanguageRuntimes
Summary:
Currently there's not really a good way to iterate over the language runtimes a
process has. This is sometimes desirable (as seen in my change to Thread).
Additionally, there's not really a good reason to iterate over every available
language, but rather only over languages for which we have a plugin loaded.

Reviewers: JDevlieghere, davide, jingham

Subscribers: lldb-commits

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

llvm-svn: 361999
2019-05-29 18:08:22 +00:00
Alex Langford 96f02a8db8 [Process] Clean up some logic around LanguageRuntimes
llvm-svn: 361666
2019-05-24 19:39:50 +00:00
Jonas Devlieghere 09ad8c8f73 Fix integer literals which are cast to bool
This change replaces built-in types that are implicitly converted to
booleans.

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

llvm-svn: 361580
2019-05-24 00:44:33 +00:00
Jonas Devlieghere edb52e2e7d [Process] Fix another thread_result_t & nullptr incompatibility.
llvm-svn: 361548
2019-05-23 20:25:49 +00:00
Konrad Kleine 248a13057a [lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]

This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.

This is the command I ran and I to fix and format the code base:

```
run-clang-tidy.py \
	-header-filter='.*' \
	-checks='-*,modernize-use-nullptr' \
	-fix ~/dev/llvm-project/lldb/.* \
	-format \
	-style LLVM \
	-p ~/llvm-builds/debug-ninja-gcc
```

NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.

NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.

Reviewers: martong, espindola, shafik, #lldb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits

Tags: #lldb, #llvm

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

llvm-svn: 361484
2019-05-23 11:14:47 +00:00
Alex Langford 74eb76f6c3 [Target] Protect Processes' language runtimes map with a mutex
Summary:
From what I understand, it's possible for multiple threads to request
a specific language runtime (e.g. CPPLanguageRuntime). This leads to a data
race.

Reviewers: jingham, JDevlieghere, compnerd, clayborg

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

llvm-svn: 361442
2019-05-22 23:01:18 +00:00
Alex Langford d2284128a9 [Target] Stop linking against lldbPluginObjCLanguage
llvm-svn: 360945
2019-05-16 22:01:25 +00:00