Commit Graph

377 Commits

Author SHA1 Message Date
Tatyana Krasnukha 36de94cf54 Reland "[lldb] Make CommandInterpreter's execution context the same as debugger's one" 2021-02-08 15:09:09 +03:00
Jim Ingham bff389120f Fix a bug with setting breakpoints on C++11 inline initialization statements.
If they occurred before the constructor that used them, we would refuse to
set the breakpoint because we thought they were crossing function boundaries.

Differential Revision: https://reviews.llvm.org/D94846
2021-01-20 17:58:34 -08:00
Jonas Devlieghere f2e05855de [lldb] Access the ModuleList through iterators where possible (NFC)
Replace uses of GetModuleAtIndexUnlocked and
GetModulePointerAtIndexUnlocked with the ModuleIterable and
ModuleIterableNoLocking where applicable.

Differential revision: https://reviews.llvm.org/D94271
2021-01-07 21:06:36 -08:00
Pavel Labath 122a4ebde3 Revert "[lldb] Make CommandInterpreter's execution context the same as debugger's one."
This reverts commit a01b26fb51, because it
breaks the "finish" command in some way -- the command does not
terminate after it steps out, but continues running the target. The
exact blast radius is not clear, but it at least affects the usage of
the "finish" command in TestGuiBasicDebug.py. The error is *not*
gui-related, as the same issue can be reproduced by running the same
steps outside of the gui.

There is some kind of a race going on, as the test fails only 20% of the
time on the buildbot.
2020-12-17 17:47:53 +01:00
Tatyana Krasnukha a01b26fb51 [lldb] Make CommandInterpreter's execution context the same as debugger's one.
Currently, the interpreter's context is not updated until a command is executed.
This has resulted in the behavior of SB-interface functions and some commands
depends on previous user actions. The interpreter's context can stay uninitialized,
point to a currently selected target, or point to one of previously selected targets.

This patch removes any usages of CommandInterpreter::UpdateExecutionContext.
CommandInterpreter::HandleCommand* functions still may override context temporarily,
but now they always restore it before exiting. CommandInterpreter saves overriden
contexts to the stack, that makes nesting commands possible.

Added test reproduces one of the issues. Without this fix, the last assertion fails
because interpreter's execution context is empty until running "target list", so,
the value of the global property was updated instead of process's local instance.

Differential Revision: https://reviews.llvm.org/D92164
2020-12-12 16:40:59 +03:00
Raphael Isemann 8af160b0b8 [lldb][NFC] Use llvm::is_contained instead of std::find in a few places 2020-08-13 14:11:28 +02:00
Raphael Isemann 8119d6c146 [lldb][NFC] Remove dead code in BreakpointResolverAddress 2020-08-10 11:29:40 +02:00
Tatyana Krasnukha da0bba5c9a [lldb/Breakpoint] Rename StoppointLocation to StoppointSite and drop its relationship with BreakpointLocation
Both of BreakpointLocation and BreakpointSite were inherited from StoppointLocation. However, the only thing
they shared was hit counting logic. The patch encapsulates those logic into StoppointHitCounter, renames
StoppointLocation to StoppointSite, and stops BreakpointLocation's inheriting from it.

Differential Revision: https://reviews.llvm.org/D84527
2020-07-29 22:07:46 +03:00
Tatyana Krasnukha d5c1f686e3 [lldb/BreakpointSite] Handle all ways of control flow 2020-07-29 21:53:18 +03:00
Tatyana Krasnukha ebaa8b1c60 [lldb] Don't use hardware index to determine whether a breakpoint site is hardware
Most process plugins (if not all) don't set hardware index for breakpoints. They even
are not able to determine this index.

This patch makes StoppointLocation::IsHardware pure virtual and lets BreakpointSite
override it using more accurate BreakpointSite::Type.

It also adds assertions to be sure that a breakpoint site is hardware when this is required.

Differential Revision: https://reviews.llvm.org/D84257
2020-07-29 21:27:24 +03:00
Tatyana Krasnukha f7ec3e3be7 [lldb] Skip overlapping hardware and external breakpoints when writing memory
This fixes the assertion `assert(intersects);` in the Process::WriteMemory function.

Differential Revision: https://reviews.llvm.org/D84254
2020-07-29 21:27:23 +03:00
Jonas Devlieghere 7926143fb0 [lldb] Fix redundant newline in AppendError calls.
AppendError always appends a newline to the given argument, while
AppendErrorWithFormat does not. I've updated the calls to remove the
extra newline.
2020-07-20 23:11:56 -07:00
Jonas Devlieghere 8953376478 [lldb] Remove redundant WithFormat suffixes (NFC)
Replace calls to FooWithFormat() with calls to Foo() when only one
argument is provided and the given string doesn't need to be formatted.
2020-07-20 23:00:32 -07:00
Raphael Isemann 779432690f [lldb][NFC] Clarify that spaces can't be in breakpoint names
We already check for spaces but we don't mention it in the error message.
2020-07-05 10:55:02 +02:00
Jonas Devlieghere 06412dae82 [lldb] Use std::make_unique<> (NFC)
Update the rest of lldb to use std::make_unique<>. I used clang-tidy to
automate this, which probably missed cases that are wrapped in ifdefs.
2020-06-24 17:48:40 -07:00
Jonas Devlieghere de019b88dd [lldb/Interpreter] Support color in CommandReturnObject
Color the error: and warning: part of the CommandReturnObject output,
similar to how an error is printed from the driver when colors are
enabled.

Differential revision: https://reviews.llvm.org/D81058
2020-06-09 10:45:45 -07:00
Konrad Kleine 107200ae0a [lldb][nfc] early exit/continue
Summary:
This commit just tries to invert some `if`'s logic to
`return`/`continue` early.

Reviewers: jankratochvil, teemperor

Reviewed By: jankratochvil, teemperor

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77377
2020-04-03 14:50:08 +02:00
Tatyana Krasnukha b1324e74da [lldb][NFC] Move local variables near to their usage 2020-03-04 16:56:51 +03:00
Tatyana Krasnukha 6c17cc531f [lldb] Make BreakpointResolver hold weak_ptr instead of raw pointer to breakpoint
This prevents calling Breakpoint::shared_from_this of an object that is not owned by any shared_ptr.

Differential Revision: https://reviews.llvm.org/D74557
2020-03-04 16:56:50 +03: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
Tatyana Krasnukha 185ef697ef [lldb] Don't call CopyForBreakpoint from a Breakpoint's constructor
Some implementations (BreakpointResolverScripted) try calling the breakpoint's shared_from_this(),
that makes LLDB crash.
2020-02-18 13:49:07 +03: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 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
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
Jonas Devlieghere d8e0f4fae7 [lldb/Breakpoint] Include whether or not a breakpoint is a HW BP
Include whether or not a breakpoint is a hardware breakpoint in the
breakpoint location. This will show up in things like the breakpoint
list.

Differential revision: https://reviews.llvm.org/D73389
2020-01-24 19:24:25 -08:00
Jonas Devlieghere 2bc38ab3d0 [lldb/Breakpoint] Recogize hardware breakpoints as such
Recognize hardware breakpoints as breakpoints instead of just mach
exceptions. The mach exception is the same for watch and breakpoints, so
we have to try each to figure out which is which.

Differential revision: https://reviews.llvm.org/D73401
2020-01-24 19:24:25 -08: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 4dac97eb1e [lldb][NFC] Migrate FileSpec::Dump to raw_ostream 2019-12-06 09:40:42 +01:00
Joseph Tremoulet 95b2e516bd Change Target::FindBreakpointsByName to return Expected<vector>
Summary:
Using a BreakpointList corrupts the breakpoints' IDs because
BreakpointList::Add sets the ID, so use a vector instead, and
update the signature to return the vector wrapped in an
llvm::Expected which can propagate any error from the inner
call to StringIsBreakpointName.

Note that, despite the similar name, SBTarget::FindBreakpointsByName
doesn't suffer the same problem, because it uses a SBBreakpointList,
which is more like a BreakpointIDList than a BreakpointList under the
covers.

Add a check to TestBreakpointNames that, without this fix, notices the
ID getting mutated and fails.

Reviewers: jingham, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70907
2019-12-04 09:57:15 -05: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 4f728bfc13 [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription
Removing raw_ostream here is getting us closer to removing LLDB's Stream
class.
2019-12-02 13:27:21 +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
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
Jim Ingham 47b33dcc0d Implement serializing scripted breakpoints and their extra args.
Differential Revision: https://reviews.llvm.org/D68750

llvm-svn: 374394
2019-10-10 17:44:50 +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
Konrad Kleine 6d7fb29914 [lldb] Avoid resource leak
Summary:
Before the pointer variable `args_dict` was assigned the result of an
allocation with `new` and then `args_dict` is passed to
`GetValueForKeyAsDictionary` which immediatly and unconditionally
assigns `args_dict` to `nullptr`:

```
    bool GetValueForKeyAsDictionary(llvm::StringRef key,
                                    Dictionary *&result) const {
      result = nullptr;
```

This caused a memory leak which was found in my coverity scan instance
under CID 224753: https://scan.coverity.com/projects/kwk-llvm-project.

Reviewers: jankratochvil, teemperor

Reviewed By: teemperor

Subscribers: teemperor, lldb-commits

Tags: #lldb

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

llvm-svn: 374071
2019-10-08 15:56:02 +00:00
Raphael Isemann 0d9a201e26 [lldb][NFC] Remove ArgEntry::ref member
The StringRef should always be identical to the C string, so we
might as well just create the StringRef from the C-string. This
might be slightly slower until we implement the storage of ArgEntry
with a string instead of a std::unique_ptr<char[]>. Until then we
have to do the additional strlen on the C string to construct the
StringRef.

llvm-svn: 371842
2019-09-13 11:26:48 +00:00
Jan Kratochvil 5aa1d81969 Code cleanup: Change FormattersContainer::KeyType from SP to rvalue
There is now std::shared_ptr passed around which is expensive for manycore
CPUs. Most of the times (except for 3 cases) it is now just std::moved with no
CPU locks needed. It also makes it possible to sort the keys (which is now not
needed much after D66398).

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

llvm-svn: 370863
2019-09-04 09:47:18 +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
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 4c78b78825 [lldb][NFC] Allow for-ranges on StringList
llvm-svn: 369113
2019-08-16 14:27:35 +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
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
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
Alex Langford 79976b3790 [Breakpoint] Replace use of ClangASTContext with TypeSystem
llvm-svn: 366495
2019-07-18 20:58:24 +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
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
Fangrui Song b0e54cbcdf Fix file names in file headers. NFC
llvm-svn: 360554
2019-05-13 04:42:32 +00:00
Alex Langford 58a638b79f [Breakpoint] Make breakpoint language agnostic
Summary:
Breakpoint shouldn't need to depend on any specific details from a
programming language. Currently the only language-specific detail it takes
advantage of are the different qualified names an objective-c method name might
have when adding a name lookup. This is reasonably generalizable.

The current method name I introduced is "GetVariantMethodNames", which I'm not
particularly tied to. If you have a better suggestion, please do let me know.

Reviewers: JDevlieghere, jingham, clayborg

Subscribers: mgorny, lldb-commits

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

llvm-svn: 360509
2019-05-11 03:32:25 +00:00