Commit Graph

1546 Commits

Author SHA1 Message Date
David Spickett 7d8ec4dc44 [lldb] const a couple of getters on MemoryRegionInfo
GetDirtyPageList was being assigned to const & in most places anyway.
If you wanted to change the list you'd make a new one and call
SetDirtyPageList.

GetPageSize is just an int so no issues being const.

Differential Revision: https://reviews.llvm.org/D125786
2022-05-18 09:00:00 +00:00
Med Ismail Bennani 174cf2f747 [lldb/API] Turn SBCompileUnit::GetIndexForLineEntry into FindLineEntryIndex (NFC)
This patch renames the `SBCompileUnit::GetIndexForLineEntry` api to be
an overload of `SBCompileUnit::FindLineEntryIndex`

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-13 18:33:05 -07:00
Med Ismail Bennani a6926d5761 [lldb/API] Add SBCompileUnit::GetIndexForLineEntry method to SB API
This patch adds a new `GetIndexForLineEntry` method to the `SBCompileUnit`
class. As the name suggests, given an `SBLineEntry` object, this will
return the line entry index within a specific compile unit.

This method can take a `exact` boolean that will make sure that the
provided line entry matches perfectly another line entry in the compile unit.

rdar://47450887

Differention Revision: https://reviews.llvm.org/D125437

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-12 16:54:22 -07:00
Pavel Labath af921006d3 [lldb] Remove the global platform list
This patch moves the platform creation and selection logic into the
per-debugger platform lists. I've tried to keep functional changes to a
minimum -- the main (only) observable difference in this change is that
APIs, which select a platform by name (e.g.,
Debugger::SetCurrentPlatform) will not automatically pick up a platform
associated with another debugger (or no debugger at all).

I've also added several tests for this functionality -- one of the
pleasant consequences of the debugger isolation is that it is now
possible to test the platform selection and creation logic.

This is a product of the discussion at
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>.

Differential Revision: https://reviews.llvm.org/D120810
2022-04-13 14:41:13 +02:00
Jonas Devlieghere 8ece6b78c0
[lldb] Use getMainExecutable in SBDebugger::PrintStackTraceOnError
Implement Pavel's suggestion to use llvm::sys::fs::getMainExecutable to
find the executable name for llvm::sys::PrintStackTraceOnErrorSignal.
2022-04-07 13:53:23 -07:00
Jonas Devlieghere ee2d9b8723
[lldb] Add Python bindings to print stack traces on crashes.
As noticed in D87637, when LLDB crashes, we only print stack traces if
LLDB is directly executed, not when used via Python bindings. Enabling
this by default may be undesirable (libraries shouldn't be messing with
signal handlers), so make this an explicit opt-in.

I "commandeered" this patch from Jordan Rupprecht who put this up for
review originally.

Differential revision: https://reviews.llvm.org/D91835
2022-04-07 11:21:02 -07:00
Shafik Yaghmour 24f9a2f53d [LLDB] Applying clang-tidy modernize-use-equals-default over LLDB
Applied modernize-use-equals-default clang-tidy check over LLDB.

This check is already present in the lldb/.clang-tidy config.

Differential Revision: https://reviews.llvm.org/D121844
2022-03-31 13:21:49 -07:00
Pavel Labath 13a3b0bb4b [lldb] Remove usages of case-insensitive c-string functions
They are not portable (which meant we had a hand-rolled implementation
for windows), and llvm::StringRef provides equivalent functionality.
2022-03-29 17:59:17 +02:00
Jonas Devlieghere ff9e596b10
[lldb] Expose diagnostic events through the SB API
Expose diagnostic events through the SB API. Unlike the progress events,
I opted to use a SBStructuredData so that we can add fields in the
future.

Differential revision: https://reviews.llvm.org/D121818
2022-03-16 15:03:31 -07:00
Jim Ingham 33f9fc77d1 Don't report memory return values on MacOS_arm64 of SysV_arm64 ABI's.
They don't require that the memory return address be restored prior to
function exit, so there's no guarantee the value is correct.  It's better
to return nothing that something that's not accurate.

Differential Revision: https://reviews.llvm.org/D121348
2022-03-14 15:25:40 -07:00
Shafik Yaghmour 28c878aeb2 [LLDB] Applying clang-tidy modernize-use-default-member-init over LLDB
Applied modernize-use-default-member-init clang-tidy check over LLDB.
It appears in many files we had already switched to in class member init but
never updated the constructors to reflect that. This check is already present in
the lldb/.clang-tidy config.

Differential Revision: https://reviews.llvm.org/D121481
2022-03-14 13:32:03 -07:00
Jonas Devlieghere 5e65e79bac
[lldb] Move ProgressEventData out of debugger and into its own file (NFC)
Move ProgressEventData out of debugger and into its own file. This is in
preparation of adding a few new type of event data for diagnostics.

Differential revision: https://reviews.llvm.org/D121506
2022-03-14 09:24:17 -07:00
Pavel Labath d65e6ff2f1 Revert "[lldb] Remove the global platform list"
It makes module dependencies loopier.

This reverts commits 49cffe3c7f and
ffb9429b6f.
2022-03-09 18:13:45 +01:00
Dave Lee 704001e90b [lldb] Add SBType::IsAggregateType
Add `IsAggregateType` to the SB API.

I'd like to use this from tests, and there are numerous other `Is<X>Type`
predicates on `SBType`.

Differential Revision: https://reviews.llvm.org/D121252
2022-03-09 08:33:08 -08:00
Pavel Labath ffb9429b6f [lldb] Remove the global platform list
This patch moves the platform creation and selection logic into the
per-debugger platform lists. I've tried to keep functional changes to a
minimum -- the main (only) observable difference in this change is that
APIs, which select a platform by name (e.g.,
Debugger::SetCurrentPlatform) will not automatically pick up a platform
associated with another debugger (or no debugger at all).

I've also added several tests for this functionality -- one of the
pleasant consequences of the debugger isolation is that it is now
possible to test the platform selection and creation logic.

This is a product of the discussion at
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>.

Differential Revision: https://reviews.llvm.org/D120810
2022-03-09 16:11:16 +01:00
Jonas Devlieghere 8b3b66ea63
[lldb] Remove FileSystem::Initialize from FileCollector
This patch removes the ability to instantiate the LLDB FileSystem class
with a FileCollector. It keeps the ability to collect files, but uses
the FileCollectorFileSystem to do that transparently.

Because the two are intertwined, this patch also removes the
finalization logic which copied the files over out of process.
2022-03-03 13:22:38 -08:00
Pavel Labath d2edca6276 [lldb/Platform] Prepare decouple instance and plugin names
This patch changes the return value of Platform::GetName() to a
StringRef, and uses the opportunity (compile errors) to change some
callsites to use GetPluginName() instead. The two methods still remain
hardwired to return the same thing, but this will change once the ideas
in
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>
are implemented.

Differential Revision: https://reviews.llvm.org/D119146
2022-03-02 14:57:01 +01:00
Med Ismail Bennani 425880ed35
Reland "[lldb/test] Fix TestProgressReporting.py race issue with the event listener"
This patch relands commit 3e3e79a9e4, and
fixes the memory sanitizer issue described in D120284, by removing the
output arguments from the LLDB_INSTRUMENT_VA invocation.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-25 17:20:39 -08:00
Pavel Labath d0810779b1 [lldb] Modernize ThreadLauncher
Accept a function object instead of a raw pointer. This avoids a bunch
of boilerplate typically needed to pass arguments to the thread
functions.

Differential Revision: https://reviews.llvm.org/D120321
2022-02-23 14:25:59 +01:00
Pavel Labath 6c99a3469d [lldb] Add support for a "global" lldbinit file
This patch adds introduces a new kind of an lldbinit file. Unlike the
lldbinit in the home directory (useful for customizing lldb to the needs
of a particular user), or the cwd lldbinit file (useful for
project-specific settings), this file can be used to customize an entire
lldb installation to a particular environment.

The feature is enabled at build time, by setting the
LLDB_GLOBAL_INIT_DIRECTORY variable to a path to a directory which
should contain an "lldbinit" file. Lldb will then load the file at
startup, if it exists, and if automatic init loading has not been
disabled. Relative paths will be resolved (at runtime) relative to the
location of the lldb library (liblldb or LLDB.framework).

The system-wide lldbinit file will be loaded first, before any
$HOME/.lldbinit and $CWD/.lldbinit files are processed, so that those
can override any system-wide settings.

More information can be found on the RFC thread at
<https://discourse.llvm.org/t/rfc-system-wide-lldbinit/59933>.

Differential Revision: https://reviews.llvm.org/D119831
2022-02-18 12:30:22 +01:00
Med Ismail Bennani 7f3fc2eee8 [lldb/API] Add a way to check if the CommandInterpreter is interactive
This patch adds the ability for the user to check if the command
interpreter's IOHandler is interactive.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-16 11:44:07 -08:00
Jim Ingham 635f03fe97 Add a repeat command option for "thread backtrace --count N".
This way if you have a long stack, you can issue "thread backtrace --count 10"
and then subsequent <Return>-s will page you through the stack.

This took a little more effort than just adding the repeat command, since
the GetRepeatCommand API was returning a "const char *".  That meant the command
had to keep the repeat string alive, which is inconvenient.  The original
API returned either a nullptr, or a const char *, so I changed the private API to
return an llvm::Optional<std::string>.  Most of the patch is propagating that change.

Also, there was a little thinko in fetching the repeat command.  We don't
fetch repeat commands for commands that aren't being added to history, which
is in general reasonable.  And we don't add repeat commands to the history -
also reasonable.  But we do want the repeat command to be able to generate
the NEXT repeat command.  So I adjusted the logic in HandleCommand to work
that way.

Differential Revision: https://reviews.llvm.org/D119046
2022-02-14 15:48:06 -08:00
Pavel Labath 96000f5c2b [lldb] Simplify SBCommandInterpreter::SourceInitFileInHomeDirectory
just have it delegate to the new overload.
2022-02-09 16:18:27 +01:00
Pavel Labath c34698a811 [lldb] Rename Logging.h to LLDBLog.h and clean up includes
Most of our code was including Log.h even though that is not where the
"lldb" log channel is defined (Log.h defines the generic logging
infrastructure). This worked because Log.h included Logging.h, even
though it should.

After the recent refactor, it became impossible the two files include
each other in this direction (the opposite inclusion is needed), so this
patch removes the workaround that was put in place and cleans up all
files to include the right thing. It also renames the file to LLDBLog to
better reflect its purpose.
2022-02-03 14:47:01 +01:00
Pavel Labath a007a6d844 [lldb] Convert "LLDB" log channel to the new API 2022-02-02 14:13:08 +01:00
Michał Górny ac666d1799 [lldb] [gdb-remote] Support getting siginfo via API
Add Thread::GetSiginfo() and SBThread::GetSiginfo() methods to retrieve
the siginfo value from server.

Differential Revision: https://reviews.llvm.org/D118055
2022-01-28 17:47:47 +01:00
Michał Górny 59a3f65f5e Revert "[lldb] [gdb-remote] Support getting siginfo via API"
This reverts commit 1a8f60f5f5.
The API requires further work.
2022-01-28 10:15:52 +01:00
Michał Górny 1a8f60f5f5 [lldb] [gdb-remote] Support getting siginfo via API
Add Thread::GetSiginfo() and SBThread::GetSiginfo() methods to retrieve
the siginfo value from server.

Differential Revision: https://reviews.llvm.org/D118055
2022-01-27 13:33:47 +01:00
Med Ismail Bennani ff52ef334b
[lldb/API] Add ability to check if module is backed by a file on disk
This patch introduces a new SBAPI method: `SBModule::IsFileBacked`

As the name suggests, it tells the user if the module's object file is
on disk or in memory.

rdar://68538278

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-26 20:40:24 +01:00
Jonas Devlieghere 1755f5b1d7 [lldb] Decouple instrumentation from the reproducers
Remove the last remaining references to the reproducers from the
instrumentation. This patch renames the relevant files and macros.

Differential revision: https://reviews.llvm.org/D117712
2022-01-20 18:06:14 -08:00
Pavel Labath 903424532f [lldb] Introduce SBPlatform::SetSDKRoot
It complements the existing SBDebugger::SetCurrentPlatformSDKRoot and
allows one to set the sysroot of a platform without making it current.

Differential Revision: https://reviews.llvm.org/D117550
2022-01-19 12:49:47 +01:00
Pavel Labath b2a162e63b [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB
This macro was being used to select the proper import/export annotations
on SB classes. Non-windows clients do not have such requirements.

Instead introduce a new macro (LLDB_IN_LIBLLDB), which signals that
we're compiling liblldb itself (and should use dllexport). The default
(no macro) is to use dllimport. I've moved the macro definition to
SBDefines.h, since it only makes sense when building the API library.

Differential Revision: https://reviews.llvm.org/D117564
2022-01-19 12:49:47 +01:00
Jonas Devlieghere da4b7437f9 [lldb] Remove LLDB_RECORD_DUMMY_* macros 2022-01-10 12:05:54 -08:00
Jonas Devlieghere 69c55d6362 [lldb] Remove LLDB_RECORD_CHAR_PTR_* macros 2022-01-10 11:57:20 -08:00
Jonas Devlieghere d232abc33b [lldb] Remove LLDB_RECORD_RESULT macro 2022-01-09 22:54:17 -08:00
Jonas Devlieghere d51402ac6b [lldb] Remove reproducer instrumentation
This patch removes most of the reproducer instrumentation. It keeps
around the LLDB_RECORD_* macros for logging. See [1] for more details.

[1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html

Differential revision: https://reviews.llvm.org/D116847
2022-01-09 21:40:55 -08:00
Jonas Devlieghere 46a28a954e [lldb] Create a property to store the REPL language
Until the introduction of the C++ REPL, there was always a single REPL
language. Several places relied on this assumption through
repl_languages.GetSingularLanguage. Now that this is no longer the case,
we need a way to specify a selected/preferred REPL language. This patch
does that with the help of a debugger property, taking inspiration from
how we store the scripting language.

Differential revision: https://reviews.llvm.org/D116697
2022-01-05 15:03:46 -08:00
Kazu Hirata a3436f7340 [API] Remove redundant member initialization (NFC)
Identified with readability-redundant-member-init.
2022-01-02 22:44:16 -08:00
Kazu Hirata b8336280d8 [lldb] Use nullptr instead of 0 or NULL (NFC)
This is a re-submission of 24d2405588
without the hunks in HostNativeThreadBase.{h,cpp}, which break builds
on Windows.

Identified with modernize-use-nullptr.
2022-01-01 11:54:25 -08:00
Kazu Hirata 95f7112be8 Revert "[lldb] Use nullptr instead of 0 or NULL (NFC)"
This reverts commit 913457acf0.

It again broke builds on Windows:

  lldb/source/Host/common/HostNativeThreadBase.cpp(37,14): error:
  assigning to 'lldb::thread_result_t' (aka 'unsigned int') from
  incompatible type 'std::nullptr_t'
2022-01-01 11:15:14 -08:00
Kazu Hirata 913457acf0 [lldb] Use nullptr instead of 0 or NULL (NFC)
This is a re-submission of 24d2405588
without the hunk in HostNativeThreadBase.h, which breaks builds on
Windows.

Identified with modernize-use-nullptr.
2022-01-01 10:48:56 -08:00
Nico Weber 4f2eeb6a65 Revert "[lldb] Use nullptr instead of 0 or NULL (NFC)"
This reverts commit 24d2405588.
Breaks building on Windows:

    ../../lldb/include\lldb/Host/HostNativeThreadBase.h(49,36): error:
        cannot initialize a member subobject of type 'lldb::thread_result_t'
        (aka 'unsigned int') with an rvalue of type 'std::nullptr_t'
      lldb::thread_result_t m_result = nullptr;
                                       ^~~~~~~
    1 error generated.
2022-01-01 13:35:54 -05:00
Kazu Hirata 24d2405588 [lldb] Use nullptr instead of 0 or NULL (NFC)
Identified with modernize-use-nullptr.
2022-01-01 08:54:05 -08:00
Pavel Labath 2efc6892d8 [lldb/python] Avoid more dangling pointers in python glue code 2021-12-22 13:47:06 +01:00
Jonas Devlieghere fa1260697e [lldb] Remove reproducer replay functionality
This is part of a bigger rework of the reproducer feature. See [1] for
more details.

[1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html
2021-12-17 17:14:52 -08:00
Michał Górny 9c7fbc3f9b [lldb] Introduce a FreeBSDKernel plugin for vmcores
Introduce a FreeBSDKernel plugin that provides the ability to read
FreeBSD kernel core dumps.  The plugin utilizes libfbsdvmcore to provide
support for both "full memory dump" and minidump formats across variety
of architectures supported by FreeBSD.  It provides the ability to read
kernel memory, as well as the crashed thread status with registers
on arm64, i386 and x86_64.

Differential Revision: https://reviews.llvm.org/D114911
2021-12-14 22:07:20 +01:00
Pavel Labath 82de8df26f [lldb] Clarify StructuredDataImpl ownership
StructuredDataImpl ownership semantics is unclear at best. Various
structures were holding a non-owning pointer to it, with a comment that
the object is owned somewhere else. From what I was able to gather that
"somewhere else" was the SBStructuredData object, but I am not sure that
all created object eventually made its way there. (It wouldn't matter
even if they did, as we are leaking most of our SBStructuredData
objects.)

Since StructuredDataImpl is just a collection of two (shared) pointers,
there's really no point in elaborate lifetime management, so this patch
replaces all StructuredDataImpl pointers with actual objects or
unique_ptrs to it. This makes it much easier to resolve SBStructuredData
leaks in a follow-up patch.

Differential Revision: https://reviews.llvm.org/D114791
2021-12-13 21:04:51 +01:00
Med Ismail Bennani 72e25978f9 [lldb/API] Add SetDataWithOwnership method to SBData
This patch introduces a new method to SBData: SetDataWithOwnership.

Instead of referencing the pointer to the data, this method copies the
data buffer into lldb's heap memory.

This can prevent having the underlying DataExtractor object point to
freed/garbage-collected memory.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-12-13 11:05:06 -08:00
Jonas Devlieghere ccf1469a4c [lldb] Make lldbVersion a full fledged library
Because of its dependency on clang (and potentially other compilers
downstream, such as swift) lldb_private::GetVersion already lives in its
own library called lldbBase. Despite that, its implementation was spread
across unrelated files. This patch improves things by introducing a
Version library with its own directory, header and implementation file.

The benefits of this patch include:

 - We can get rid of the ugly quoting macros.
 - Other parts of LLDB can read the version number from
   lldb/Version/Version.inc.
 - The implementation can be swapped out for tools like lldb-server than
   don't need to depend on clang at all.

Differential revision: https://reviews.llvm.org/D115211
2021-12-08 15:14:34 -08:00
Levon Ter-Grigoryan f23b829a26 Fixed use of -o and -k in LLDB under Windows when statically compiled with vcruntime.
Right now if the LLDB is compiled under the windows with static vcruntime library, the -o and -k commands will not work.

The problem is that the LLDB create FILE* in lldb.exe and pass it to liblldb.dll which is an object from CRT.
Since the CRT is statically linked each of these module has its own copy of the CRT with it's own global state and the LLDB should not share CRT objects between them.

In this change I moved the logic of creating FILE* out of commands stream from Driver class to SBDebugger.
To do this I added new method: SBError SBDebugger::SetInputStream(SBStream &stream)

Command to build the LLDB:
cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lldb;libcxx"  -DLLVM_USE_CRT_RELEASE="MT" -DLLVM_USE_CRT_MINSIZEREL="MT" -DLLVM_USE_CRT_RELWITHDEBINFO="MT" -DP
YTHON_HOME:FILEPATH=C:/Python38 -DCMAKE_C_COMPILER:STRING=cl.exe -DCMAKE_CXX_COMPILER:STRING=cl.exe ../llvm

Command which will fail:
lldb.exe -o help

See discord discussion for more details: https://discord.com/channels/636084430946959380/636732809708306432/854629125398724628
This revision is for the further discussion.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D104413
2021-11-24 16:17:08 +00:00