Commit Graph

26034 Commits

Author SHA1 Message Date
Jonas Devlieghere 20e17323cd [lldb] Fix a few lldb-server tests on Apple Silicon
This fixes TestGdbRemoteSingleStep.py and TestGdbRemote_vCont.py. This
patch updates the test to account for the possibility that the constants
are already materialized. This appears to behave differently between
embedded arm64 devices and Apple Silicon.
2022-02-07 09:35:12 -08:00
Adrian Prantl d42765b3be Add llgs category to all tests in TestLldbGdbServer that attach to the process. 2022-02-07 08:26:48 -08:00
Jonas Devlieghere d63dfa14d6 [lldb] Update outdated comment in TestDyldTrieSymbols.py
After aed965d55d we no longer demangle and store the full name. The
test was updated accordingly but the comment still specified that we
should be able to find the symbol by its full demangled name.
2022-02-07 08:13:54 -08:00
Pavel Labath a53c5c66b3 [lldb/Platform] s/m_name/m_hostname
m_name is confusing, as there is a getter called GetName, but it returns
a completely different thing.
2022-02-07 14:58:55 +01:00
Kazu Hirata ee4b6cf538 [Breakpoint] Remove redundant member initialization (NFC)
Identified with readability-redundant-member-init.
2022-02-06 10:54:46 -08:00
Adrian Prantl 11d64edbf9 Revert "Disable TestLldbGdbServer on Dwarf2 and clang versions below 14"
This reverts commit 867fdec194.
2022-02-05 14:54:41 -08:00
Adrian Prantl a701dc8eda Revert "Fixed typos in TestLldbGdbServer.py"
This reverts commit cf93a08575.
2022-02-05 14:54:37 -08:00
Jonas Devlieghere ef3fade14b [lldb] Use mangled symbol name to look for __asan::AsanDie()
After aed965d we no longer demangle full symbol names while indexing the
symbol table which means we have to use the mangled name instead of the
demangled name to find the symbol for __asan::AsanDie().

This fixes the following two tests:

  lldb-api :: functionalities/asan/TestMemoryHistory.py
  lldb-api :: functionalities/asan/TestReportData.py
2022-02-05 09:50:31 -08:00
Jason Molenda a37c38176a Increase memory buffer for scanning objc classes on darwin systems
iOS systems are getting near this limit; double itfrom a 150kb
buffer to a 300kb buffer, which is freed after processing the
list of classes.

rdar://88454594
Differential Revision: https://reviews.llvm.org/D118972
2022-02-04 23:53:27 -08:00
Jonas Devlieghere edbb0f6df7 [lldb] Rename DemangleWithRichManglingInfo to GetRichManglingInfo (NFC)
This addresses Pavel's comment from D118814.
2022-02-04 10:40:33 -08:00
Jonas Devlieghere aed965d55d [lldb] Don't construct the demangled strings while indexing the symbol table
The symbol table needs to demangle all symbol names when building its
index. However, this doesn't require the full mangled name: we only need
the base name and the function declaration context. Currently, we always
construct the demangled string during indexing and cache it in the
string pool as a way to speed up future lookups.

Constructing the demangled string is by far the most expensive step of
the demangling process, because the output string can be exponentially
larger than the input and unless you're dumping the symbol table, many
of those demangled names will not be needed again.

This patch avoids constructing the full demangled string when we can
partially demangle. This speeds up indexing and reduces memory usage.

I gathered some numbers by attaching to Slack:

Before
------

  Memory usage: 280MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
    Time (mean ± σ):      4.829 s ±  0.518 s    [User: 4.012 s, System: 0.208 s]
    Range (min … max):    4.624 s …  6.294 s    10 runs

After
-----

  Memory usage: 189MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
    Time (mean ± σ):      4.182 s ±  0.025 s    [User: 3.536 s, System: 0.192 s]
    Range (min … max):    4.152 s …  4.233 s    10 runs

Differential revision: https://reviews.llvm.org/D118814
2022-02-04 10:17:39 -08:00
Jonas Devlieghere fa52788b7a [lldb] Improve RichManglingContext ergonomics (NFC)
Have the different ::Parse.* methods return the demangled string
directly instead of having to go through ::GetBufferRef.

Differential revision: https://reviews.llvm.org/D118953
2022-02-04 10:17:39 -08:00
Pavel Labath 13b58f9710 [lldb] Remove Log:Channel::GetLogIfAll
after the recent refactor, the function is unused.
2022-02-04 13:31:14 +01:00
Zequan Wu 8682947d24 [LLDB][NativePDB] terminal entry has lower precedence than new entry 2022-02-03 15:41:26 -08:00
Zequan Wu ac73e12ee0 [LLDB] remove an extra register enum on windows x64 2022-02-03 14:12:24 -08:00
Zequan Wu 607ffa5515 [LLDB] Fix window bot failure
This attempts to fix this bot failure: https://lab.llvm.org/buildbot/#/builders/83/builds/14736 caused by D118750 by un-xfail those expected failed tests.

Differential Revision: https://reviews.llvm.org/D118866
2022-02-03 11:27:48 -08:00
Pavel Labath 359a2deb6f [lldb] Fix windows&mac builds for c34698a811 2022-02-03 18:06:55 +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
Zequan Wu f3e1ba1d03 [LLDB] add sub regigter enums on x64 Windows
Differential Revision: https://reviews.llvm.org/D118750
2022-02-02 14:21:08 -08:00
Michał Górny 287ce6b516 [lldb] [Commands] Implement "thread siginfo"
Differential Revision: https://reviews.llvm.org/D118473
2022-02-02 19:31:44 +01:00
Pavel Labath a007a6d844 [lldb] Convert "LLDB" log channel to the new API 2022-02-02 14:13:08 +01:00
Pavel Labath b1127753b9 [lldb] Convert ProcessGDBRemoteLog to the new API 2022-02-01 14:36:29 +01:00
Jonas Devlieghere d329dfd0c8 [lldb] Use the build's python interpreter in the shell tests
Make sure that the shell tests use the same python interpreter as the
rest of the build instead of picking up `python` from the PATH.

It would be nice if we could use the _disallow helper, but that triggers
on invocations that specify python as the scripting language.
2022-01-31 16:53:42 -08:00
Jonas Devlieghere e1cad1303b [lldb] Support Rosetta registers in crashlog.py
Rosetta crashlogs can have their own thread register state. Unlike the
other registers which ware directly listed under "threadState", the
Rosetta registers are nested under their own key in the JSON, as
illustrated below:

  {
      "threadState":
      {
          "rosetta":
          {
              "tmp2":
              {
                  "value": 4935057216
              },
              "tmp1":
              {
                  "value": 4365863188
              },
              "tmp0":
              {
                  "value": 18446744073709551615
              }
          }
      }
  }
2022-01-31 10:50:16 -08:00
Pavel Labath c8fbf8037d [lldb] Convert Process KDP Log to the new API 2022-01-31 08:59:41 +01:00
Kazu Hirata 5423839929 [lldb] Forward-declare ClangExpressionParser (NFC)
ClangUserExpression.h is relying on the forward declaration of
ClangExpressionParser in ClangFunctionCaller.h.  This patch moves the
forward declaration to ClangUserExpression.h.
2022-01-30 12:32:53 -08:00
Simon Pilgrim b81b3ac668 [lldb] TypeSystemClang - use castAs/cast<> instead of getAs/dyn_cast<> to avoid dereference of nullptr
The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-29 15:34:26 +00:00
Simon Pilgrim 058c5dfc78 Raise the minimum Visual Studio version to VS2019
As raised here: https://lists.llvm.org/pipermail/llvm-dev/2021-November/153881.html

Now that VS2022 is on general release, LLVM is expected to build on VS2017, VS2019 and VS2022, which is proving hazardous to maintain due to changes in behaviour including preprocessor and constexpr changes. Plus of the few developers that work with VS, many have already moved to VS2019/22.

This patch proposes to raise the minimum supported version to VS2019 (16.x) - I've made the hard limit 16.0 or later, with the soft limit VS2019 16.7 - older versions of VS2019 are "allowed" (at your own risk) via the LLVM_FORCE_USE_OLD_TOOLCHAIN cmake flag.

Differential Revision: https://reviews.llvm.org/D114639
2022-01-29 10:56:41 +00:00
Stella Stamenova 738d73fbf4 [lldb] Update the lldb build instructions on Windows
The existing instructions for lldb on Windows can be more explicit. This adds a few details on how to install various components and the easiest way to get to a working build.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D118425
2022-01-28 10:18:19 -08: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
Augusto Noronha b414954a5f [lldb] Make ReadCStringFromMemory default to read from the file-cache.
Differential Revision: https://reviews.llvm.org/D118265
2022-01-28 13:08:30 -03:00
Pavel Labath 2d75f62722 [lldb] Convert DWARF log to the new API
This also deletes some dead log statements (log initialization commented
out).
2022-01-28 10:41:10 +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
David Spickett d1c124e6e7 [lldb][ARM/AArch64] Update dissembler to v9.3-a
This means sve2 is enabled by default and the v8.8 mops (memcpy
and memset acceleration instructions) and HBC (hinted conditional
branch) extensions can be disassembled.

v9.3-a is equivalent to v8.8-a except that in v9.0-a sve2 was
enabled by default so v9.3-a includes that too.

MTE remains an optional extension, only enabled for specific CPUs.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D118358
2022-01-28 09:10:04 +00:00
Jonas Devlieghere 4a64955c37 [lldb] Remove reproducers documentation 2022-01-27 19:35:28 -08:00
Shubham Sandeep Rastogi cf93a08575 Fixed typos in TestLldbGdbServer.py
Fixed more typos
2022-01-27 14:12:24 -08:00
Shubham Sandeep Rastogi 867fdec194 Disable TestLldbGdbServer on Dwarf2 and clang versions below 14
We have been noticing issues with the lldb bots on builds using versions below clang 14 and dwarf 2, so to make sure we can get clean builds for a while, we are disabling the tests for those versions

Differential Revision: https://reviews.llvm.org/D118395
2022-01-27 14:02:35 -08:00
Shubham Sandeep Rastogi ee54868a76 Revert "Disable TestLldbGdbServer on Dwarf2 and clang versions below 14"
This reverts commit cd31763770.
2022-01-27 13:36:21 -08:00
Shubham Sandeep Rastogi cd31763770 Disable TestLldbGdbServer on Dwarf2 and clang versions below 14
We have been noticing issues with the lldb bots on builds using versions below clang 14 and dwarf 2, so to make sure we can get clean builds for a while, we are disabling the tests for those versions

Differential Revision: https://reviews.llvm.org/D118395
2022-01-27 13:29:34 -08:00
Med Ismail Bennani 48c36a15a3 [lldb/test] Disable test_launch_scripted_process_stack_frames on x86_64
There seems to be an issue on x86_64 when launching a ScriptdProcess.
This disables temporarely the test that causes the bot to timeout until
I finish investigating the issue.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-27 18:42:08 +01:00
Pavel Labath 33eb3f14eb [lldb] Delete TestBacktraceAll.py
This test is completely nondeterministic, environment-dependent and does
not test what it was supposed to test (reverting the associated patch
does not make it fail).

I tried to figure out what the patch was meant to fix to see if I can
create a better test with the current tools, but I was not able to
understand the problem (it sounds like it has something to do with local
classes, but I don't understand the details).
2022-01-27 15:01:08 +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
Michał Górny 3053e143be [lldb] [Platform] Support synthesizing siginfo_t
Support synthesizing the siginfo_t type from the Platform plugin.
This type is going to be used by LLDB client to process the raw siginfo
data received from lldb-server without the necessity of relying
on target's debug info being present.

Differential Revision: https://reviews.llvm.org/D117707
2022-01-27 13:33:47 +01:00
Pavel Labath 4cd8877a34 [lldb/test] Fix gnu-style-compression.yaml
In the rush to get the bot green, I did not realize I was building the
file with -gsplit-dwarf, and therefore the yaml ended up referring to a
file I did not check it.

This rebuilds the file without split dwarf.
2022-01-27 10:23:21 +01:00
Pavel Labath 6730df4779 [lldb] Convert ProcessWindowsLog to the new API 2022-01-27 10:05:05 +01:00
Pavel Labath 7afd052112 [lldb/DWARF] Make manual dwarf index deterministic
Currently, running the test suite with LLVM_ENABLE_EXPENSIVE_CHECKS=On
causes a couple of tests to fail. This happens because they expect a
certain order of variables (all of them happen to use the "target
variable" command, but other lookup functions should suffer from the
same issues), all of which have the same name. Sort algorithms often
preserve the order of equivalent elements (in this case the entries in
the NameToDIE map), but that not guaranteed, and
LLVM_ENABLE_EXPENSIVE_CHECKS stresses that by pre-shuffling all inputs
before sorting.

While this could easily be fixed by relaxing the test expectations,
having a deterministic output seems like a worthwhile goal,
particularly, as this could have bigger consequences than just a
different print order -- in some cases we just pick the first entry that
we find, whatever that is. Therefore this patch makes the sort
deterministic by introducing another sort key -- UniqueCString::Sort
gets a value comparator functor, which can be used to sort elements with
the same name -- in the DWARF case we use DIERef::operator<, which
roughly equals the order in which the entries appear in the debug info,
and matches the current "accidental" order.

Using a extra functor seemed preferable to using stable_sort, as the
latter allocates extra O(n) of temporary memory.

I observed no difference in debug info parsing speed with this patch
applied.

Differential Revision: https://reviews.llvm.org/D118251
2022-01-27 10:05:05 +01:00
Pavel Labath aaa9f40e3f [lldb/test] Replace gnu-style-compression.cpp with a yaml file
In D117744, llvm removed writing support for this format, breaking the
test. We may eventually want to remove reading support as well, but for
now I have converted the test to a yaml file to maintain coverage.
2022-01-27 10:05:05 +01:00
Med Ismail Bennani aae3c4f2b4
[lldb/test] Skip TestSBModule unless darwin
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-27 01:05:12 +01:00
Med Ismail Bennani a6b5624372 Revert "[lldb/test] Try to fix TestSBModule failure"
This reverts commit 326516448c.
2022-01-27 01:04:38 +01:00
Med Ismail Bennani 326516448c [lldb/test] Try to fix TestSBModule failure
This should fix https://lab.llvm.org/buildbot/#/builders/68/builds/25571

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-27 01:00:29 +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 cbd0822f27 [lldb] Remove ConstString::StaticMemorySize
Remove ConstString::StaticMemorySize as it is unused and superseded by
GetMemoryStats. It is referenced in a bunch of doc comments but I don't
really understand why. My best guess it that the comments were
copy-pasted from ConstString::MemorySize() even though it didn't make
sense there either. The implementation of StaticMemorySize was being
called on the MemoryPool, not on the ConstString itself.

Differential revision: https://reviews.llvm.org/D118091
2022-01-26 09:13:46 -08:00
Pavel Labath dcd0926ad0 [lldb] Fix a couple of use-of-uninit-var errors in Materializer.cpp
These were probably not picked up before because they only run when
logging is enabled.
2022-01-26 17:01:53 +01:00
Benjamin Kramer f15014ff54 Revert "Rename llvm::array_lengthof into llvm::size to match std::size from C++17"
This reverts commit ef82063207.

- It conflicts with the existing llvm::size in STLExtras, which will now
  never be called.
- Calling it without llvm:: breaks C++17 compat
2022-01-26 16:55:53 +01:00
serge-sans-paille ef82063207 Rename llvm::array_lengthof into llvm::size to match std::size from C++17
As a conquence move llvm::array_lengthof from STLExtras.h to
STLForwardCompat.h (which is included by STLExtras.h so no build
breakage expected).
2022-01-26 16:17:45 +01:00
David Spickett 070090d08e [lldb] Add option to show memory tags in memory read output
This adds an option --show-tags to "memory read".

(lldb) memory read mte_buf mte_buf+32 -f "x" -s8 --show-tags
0x900fffff7ff8000: 0x0000000000000000 0x0000000000000000 (tag: 0x0)
0x900fffff7ff8010: 0x0000000000000000 0x0000000000000000 (tag: 0x1)

Tags are printed on the end of each line, if that
line has any tags associated with it. Meaning that
untagged memory output is unchanged.

Tags are printed based on the granule(s) of memory that
a line covers. So you may have lines with 1 tag, with many
tags, no tags or partially tagged lines.

In the case of partially tagged lines, untagged granules
will show "<no tag>" so that the ordering is obvious.
For example, a line that covers 2 granules where the first
is not tagged:

(lldb) memory read mte_buf-16 mte_buf+16 -l32 -f"x" --show-tags
0x900fffff7ff7ff0: 0x00000000 <...> (tags: <no tag> 0x0)

Untagged lines will just not have the "(tags: ..." at all.
Though they may be part of a larger output that does have
some tagged lines.

To do this I've extended DumpDataExtractor to also print
memory tags where it has a valid execution context and
is asked to print them.

There are no special alignment requirements, simply
use "memory read" as usual. All alignment is handled
in DumpDataExtractor.

We use MakeTaggedRanges to find all the tagged memory
in the current dump, then read all that into a MemoryTagMap.

The tag map is populated once in DumpDataExtractor and re-used
for each subsequently printed line (or recursive call of
DumpDataExtractor, which some formats do).

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D107140
2022-01-26 14:40:39 +00:00
David Spickett 8d714e4ad5 [lldb] Correct \params to \param in StackFrame Doxygen comments 2022-01-26 14:05:58 +00:00
David Spickett 5d2f90cbcd [lldb] Correct some uses of \b in Doxygen documentation 2022-01-26 14:05:58 +00:00
David Spickett 37c4bd0fdb [lldb] Add MemoryTagMap class
The tag map holds a sparse set of memory tags and allows
you to query ranges for tags.

Granules that do not have tags will be set to llvm::None.
to keep the ordering intact. If there are no tags for the
requested range we'll just return an empty result so that
callers don't need to check that all values are llvm::None.

This will be combined with MemoryTagManager's MakeTaggedRanges:
* MakeTaggedRanges
* Read from all those ranges
* Insert the results into the tag map
* Give the tag map to whatever needs to print tags

Which in this case will be "memory read"/DumpDataExtractor.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D112825
2022-01-26 13:55:48 +00:00
Pavel Labath 4fa1ad0521 [lldb] Convert POSIXLog to use the new API 2022-01-26 13:10:10 +01:00
David Spickett ee0c3820f8 [lldb][AArch64] Add MakeTaggedRanges to MemoryTagManager
This is to be used when you want to know what subranges
of a larger range have memory tagging. Like MakeTaggedRange
but memory without tags is skipped and you get a list of ranges back.

Will be used later by DumpDataExtractor to show memory tags.

MakeTaggedRanges assumes that the memory regions it is
given are sorted in ascending order and do not overlap.
For the current use case where you get regions from
GetMemoryRegions and are on some Linux like OS, this is
reasonable to assume.

I've used asserts to check those conditions. In future
any API binding will check them up front to prevent a crash.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D112824
2022-01-26 11:30:10 +00:00
Pavel Labath 2a1b7aa016 [lldb] Fix ProcessKDPLog for the logging refactor 2022-01-25 20:51:19 +01:00
Jonas Devlieghere c2cd7cc63c [lldb] Only include mach headers on Darwin 2022-01-25 09:58:47 -08:00
Jonas Devlieghere d7e183b225 [lldb] Use new dyld SPIs to query the shared cache local symbols
rdar://85492172
2022-01-25 09:36:48 -08:00
Pavel Labath 6b67e89b45 [lldb] Fix windows build for D117490
I forgot to update ProcessWindowsLog to the new API.
2022-01-25 13:51:53 +01:00
Pavel Labath 345d85e124 [lldb] Fix mac build for D117490
This is exactly that kind of a API misuse that the patch was meant to
detect.
2022-01-25 13:42:24 +01:00
Pavel Labath ce6903595b [lldb/test] Use abspath when searching for lldb.exe
realpath is too aggressive and does not produce the desired effect if
ones build folder is a symlink farm.
2022-01-25 12:13:49 +01:00
Pavel Labath 0f08db66db [lldb] Make logging machinery type-safe
This patch makes use of c++ type checking and scoped enums to make
logging statements shorter and harder to misuse.

Defines like LIBLLDB_LOG_PROCESS are replaces with LLDBLog::Process.
Because it now carries type information we do not need to worry about
matching a specific enum value with the right getter function -- the
compiler will now do that for us.

The main entry point for the logging machinery becomes the GetLog
(template) function, which will obtain the correct Log object based on
the enum type. It achieves this through another template function
(LogChannelFor<T>), which must be specialized for each type, and should
return the appropriate channel object.

This patch also removes the ability to log a message if multiple
categories are enabled simultaneously as it was unused and confusing.

This patch does not actually remove any of the existing interfaces. The
defines and log retrieval functions are left around as wrappers around
the new interfaces. They will be removed in follow-up patch.

Differential Revision: https://reviews.llvm.org/D117490
2022-01-25 12:13:49 +01:00
Jonas Devlieghere 16bff06790 [lldb] Make PythonDataObjects work with Python 2
I considered keeping this change strictly downstream. Since we still
have a bunch of places that check for Python 2, I figured it doesn't
harm to land it upstream and avoid the conflict when I eventually do
remove them (hopefully soon!).
2022-01-24 17:23:09 -08:00
Jonas Devlieghere cd8122b27f [lldb] Add ConstString memory usage statistics
Add statistics about the memory usage of the string pool. I'm
particularly interested in the memory used by the allocator, i.e. the
number of bytes actually used by the allocator it self as well as the
number of bytes allocated through the allocator.

Differential revision: https://reviews.llvm.org/D117914
2022-01-24 15:13:17 -08:00
Med Ismail Bennani c3ca2c6b14
[lldb/test] Fix `TestScriptedProcess.test_scripted_process_and_scripted_thread`
This patch updates `dummy_scripted_process.py` to report the dummy
thread correctly to reflect the changes introduced by `d3e0f7e`.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 21:48:31 +01:00
Med Ismail Bennani 91bb116190 [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)
This patch changes the `ScriptedInterface::ErrorWithMessage` method to
make it `static` which makes it easier to call.

The patch also updates its various call sites to reflect this change.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:54 +01:00
Med Ismail Bennani 45148bfe8a [lldb/Plugins] Fix ScriptedThread IndexID reporting
When listing all the Scripted Threads of a ScriptedProcess, we can see that all
have the thread index set to 1. This is caused by the lldb_private::Thread
constructor, which sets the m_index_id member using the provided thread id `tid`.

Because the call to the super constructor is done before instantiating
the `ScriptedThreadInterface`, lldb can't fetch the thread id from the
script instance, so it uses `LLDB_INVALID_THREAD_ID` instead.

To mitigate this, this patch takes advantage of the `ScriptedThread::Create`
fallible constructor idiom to defer calling the `ScriptedThread` constructor
(and the `Thread` super constructor with it), until we can fetch a valid
thread id `tid` from the `ScriptedThreadInterface`.

rdar://87432065

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:54 +01:00
Med Ismail Bennani cfa55bfe78 [lldb/Plugins] Enrich ScriptedThreads Stop Reasons with Exceptions
This patch adds Exceptions to the list of supported stop reasons for
Scripted Threads.

The main motivation for this is that breakpoints are triggered as a
special exception class on ARM platforms, so adding it as a stop reason
allows the ScriptedProcess to selected the ScriptedThread that stopped at
a breakpoint (or crashed :p).

rdar://87430376

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:54 +01:00
Med Ismail Bennani d3e0f7e150 [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess
This patch adds support of multiple Scripted Threads in a ScriptedProcess.

This is done by fetching the Scripted Threads info dictionary at every
ScriptedProcess::DoUpdateThreadList and iterate over each element to
create a new ScriptedThread using the object instance, if it was not
already available.

This patch also adds the ability to pass a pointer of a script interpreter
object instance to initialize a ScriptedInterface instead of having to call
the script object initializer in the ScriptedInterface constructor.

This is used to instantiate the ScriptedThreadInterface from the
ScriptedThread constructor, to be able to perform call on that script
interpreter object instance.

Finally, the patch also updates the scripted process test to check for
multiple threads.

rdar://84507704

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:53 +01:00
Med Ismail Bennani 1b86344fa8 [lldb/Plugins] Move ScriptedThreadInterface to ScriptedThread
Since we can have multiple Scripted Threads per Scripted Process, having
only a single ScriptedThreadInterface (with a single object instance)
will cause the method calls to be done on the wrong object.

Instead, this patch creates a separate ScriptedThreadInterface for each
new lldb_private::ScriptedThread to make sure we interact with the right
instance.

rdar://87427911

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:53 +01:00
Med Ismail Bennani 4858fe04a1 [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface
This patch adds a new method to the Scripted Process interface to
retrive a dictionary of Scripted Threads. It uses the thread ID as a key
and the Scripted Thread instance as the value.

This dictionary will be used to create Scripted Threads in lldb and
perform calls to the python scripted thread object.

rdar://87427126

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:53 +01:00
serge-sans-paille 25e8f5f827 Add missing STLExtras.h include from lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp 2022-01-24 15:03:11 +01:00
serge-sans-paille 5f290c090a Move STLFunctionalExtras out of STLExtras
Only using that change in StringRef already decreases the number of
preoprocessed lines from 7837621 to 7776151 for LLVMSupport

Perhaps more interestingly, it shows that many files were relying on the
inclusion of StringRef.h to have the declaration from STLExtras.h. This
patch tries hard to patch relevant part of llvm-project impacted by this
hidden dependency removal.

Potential impact:
- "llvm/ADT/StringRef.h" no longer includes <memory>,
  "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h"

Related Discourse thread:
https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-24 14:13:21 +01:00
David Spickett 7d19566c3b [lldb] Ignore non-address bits in "memory find" arguments
This removes the non-address bits before we try to use
the addresses.

Meaning that when results are shown, those results won't
show non-address bits either. This follows what "memory read"
has done. On the grounds that non-address bits are a property
of a pointer, not the memory pointed to.

I've added testing and merged the find and read tests into one
file.

Note that there are no API side changes because "memory find"
does not have an equivalent API call.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D117299
2022-01-24 10:42:49 +00:00
David Blaikie 8b280df504 Rough guess at fixing lldb tests to handle Clang defaulting to DWARFv5 2022-01-23 21:24:25 -08:00
Kazu Hirata abb0ed4495 [Commands] Remove redundant member initialization (NFC)
Identified with readability-redundant-member-init.
2022-01-23 11:07:14 -08:00
Simon Pilgrim 49d38b1d61 Fix "not all control paths return a value" warning. NFC. 2022-01-23 15:14:10 +00:00
Simon Pilgrim d13847bbe5 [lldb] TerminalState::Save - fix unused variable warning
Non-POSIX target builds don't use the file descriptor
2022-01-23 15:12:44 +00:00
Simon Pilgrim d7aa402b4b [lldb] PdbAstBuilder - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-23 15:11:08 +00:00
Simon Pilgrim c93491352c [lldb] CxxModuleHandler - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-23 15:10:33 +00:00
Dave Lee b95150418f [lldb] Allow aliases to aliases of raw input commands
Allow users to create aliases for aliases to raw input commands. That probably
sounds convoluted, so here's an example:

```
command alias some-setup env SOMEVAR=SOMEVALUE
```

This an alias based on `env`, which itself is an alias for `_regex-env`.
`_regex-env` is a `command regex` command, which takes raw input.

The above `some-setup` alias fails with:

```
error: Unable to create requested alias.
```

This change allows such aliases to be created. lldb already supports aliases to
aliases for parsed commands.

Differential Revision: https://reviews.llvm.org/D117259
2022-01-21 17:57:34 -08:00
Dave Lee 58ee14e29e [lldb] Fix timer logging inverted quiet condition
The logic of `g_quiet` was inverted in D26243. This corrects the issue.

Without this, running `log timers enable` produces a high volume of incremental
timer output.

Differential Revision: https://reviews.llvm.org/D117837
2022-01-21 15:34:07 -08:00
serge-sans-paille e9211e0393 Remove dependency from raw_ostream on <chrono>
The tryLockFor method from raw_fd_sotreamis the sole user of that
header, and it's not referenced in the mono repo. I still chose to keep
it (may be useful for downstream user) but added a transient type that's
forward declared to hold the duration parameter.

Notable changes:

- "llvm/Support/Duration.h" must be included in order to use tryLockFor.
- "llvm/Support/raw_ostream.h" no longer includes <chrono>

This sole change has an interesting impact on the number of processed
line, as measured by:

clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l

before: 7917500
after:  7835142

Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-21 15:17:39 +01:00
serge-sans-paille 75e164f61d [llvm] Cleanup header dependencies in ADT and Support
The cleanup was manual, but assisted by "include-what-you-use". It consists in

1. Removing unused forward declaration. No impact expected.
2. Removing unused headers in .cpp files. No impact expected.
3. Removing unused headers in .h files. This removes implicit dependencies and
   is generally considered a good thing, but this may break downstream builds.
   I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the
   modification in the second part of the commit.
4. Replacing header inclusion by forward declaration. This has the same impact
   as 3.

Notable changes:

- llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h
- llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h
- llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h
- llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h

You may need to add some of these headers in your compilation units, if needs be.

As an hint to the impact of the cleanup, running

clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l

before: 8000919 lines
after:  7917500 lines

Reduced dependencies also helps incremental rebuilds and is more ccache
friendly, something not shown by the above metric :-)

Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-21 13:54:49 +01:00
Jonas Devlieghere cac164ff9c [lldb] Update the modulemap 2022-01-20 18:28:23 -08:00
Jonas Devlieghere 156b997251 [lldb] Instrument SB API with signposts
Instrument the SB API with signposts on Darwin. This gives us a time
profile on whose behalf LLDB spends time (particularly when run via the
SBAPI from an IDE).

Differential revision: https://reviews.llvm.org/D117632
2022-01-20 18:06:14 -08: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
Jonas Devlieghere f811cb82a6 [lldb] Revive lldb-instr
I revived lldb-instr to update the macros for D117712. I think the new
macros are simple enough that we add them by hand, but this tool can do
it automatically for you.

Differential revision: https://reviews.llvm.org/D117748
2022-01-20 18:06:14 -08:00
Adrian Prantl 36cb29cbbe Work around a module build failure on the bots.
This patch works around what looks like a bug in Clang itself.

The error on the bot is:

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/40466/consoleText

In module 'LLVM_Utils' imported from /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h:18:
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/Support/Error.h:720:3: error: 'llvm::Expected<bool>::(anonymous)' from module 'LLVM_Utils.Support.Error' is not present in definition of 'llvm::Expected<bool>' in module 'LLVM_Utils.Support.Error'
  union {
  ^
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/Support/Error.h:720:3: note: declaration of '' does not match
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/Support/Error.h:720:3: note: declaration of '' does not match
1 error generated.

The intention is to revert this as soon as a proper fix has been identified!

rdar://87845391
2022-01-20 13:39:48 -08:00
Pavel Labath 57ebfea38c [lldb] Surround LLDB_API-defining code with #ifndef LLDB_API
This enables power-users to annotate lldb api functions with arbitrary
attributes. The motivation for this is being able to build liblldb as a
static library on windows (see discussion on D117564).

This should not be interpreted to mean that building liblldb is
supported in any way, but this does not cause any problems for us, and
can help users who really know what they are doing (or have no other
choice).
2022-01-20 20:50:35 +01:00
John Ericson df31ff1b29 [cmake] Make include(GNUInstallDirs) always below project(..)
Its defaulting logic must go after `project(..)` to work correctly,  but `project(..)` is often in a standalone condition making this
awkward, since the rest of the condition code may also need GNUInstallDirs.

The good thing is there are the various standalone booleans, which I had missed before. This makes splitting the conditional blocks less awkward.

Reviewed By: arichardson, phosek, beanz, ldionne, #libunwind, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D117639
2022-01-20 18:59:17 +00:00
Adrian Prantl c0957bd617 Add missing include to fix modular build 2022-01-20 08:35:33 -08:00
David Spickett 787f91b0bb [lldb] Remove non-address bits from addresses given to memory tag commands
Although the memory tag commands use a memory tag manager to handle
addresses, that only removes the top byte.

That top byte is 4 bits of memory tag and 4 free bits, which is more
than it should strictly remove but that's how it is for now.

There are other non-address bit uses like pointer authentication.
To ensure the memory tag manager only has to deal with memory tags,
use the ABI plugin to remove the rest.

The tag access test has been updated to sign all the relevant pointers
and require that we're running on a system with pointer authentication
in addition to memory tagging.

The pointers will look like:
<4 bit user tag><4 bit memory tag><signature><bit virtual address>

Note that there is currently no API for reading memory tags. It will
also have to consider this when it arrives.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D117672
2022-01-20 10:48:14 +00:00
David Spickett 585abe3ba5 [lldb] Rename MemoryTagManager RemoveNonAddressBits to RemoveTagBits
This better describes the intent of the method. Which for AArch64
is removing the top byte which includes the memory tags.

It does not include pointer signatures, for those we need to use
the ABI plugin. The rename makes this a little more clear.

It's a bit awkward that the memory tag manager is removing the whole
top byte not just the memory tags but it's an improvement for now.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D117671
2022-01-20 10:47:05 +00:00
Jonas Devlieghere 742bfb3581 [lldb] Fix LLDB_FULL_VERSION_STRING
Currently LLDB_FULL_VERSION_STRING is set to "LLDB_VERSION_STRING"
rather than the content of the CMake variable with that name.
2022-01-19 14:20:22 -08:00
Jonas Devlieghere eb5c0ea681 [lldb] Initialize Python exactly once
We got a few crash reports that showed LLDB initializing Python on two
separate threads. Make sure Python is initialized exactly once.

rdar://87287005

Differential revision: https://reviews.llvm.org/D117601
2022-01-19 09:56:55 -08:00
Pavel Labath 4f89157b9d [lldb] Make StatsDuration thread-safe
std::chrono::duration types are not thread-safe, and they cannot be
concurrently updated from multiple threads. Currently, we were doing
such a thing (only) in the DWARF indexing code
(DWARFUnit::ExtractDIEsRWLocked), but I think it can easily happen that
someone else tries to update another statistic like this without
bothering to check for thread safety.

This patch changes the StatsDuration type from a simple typedef into a
class in its own right. The class stores the duration internally as
std::atomic<uint64_t> (so it can be updated atomically), but presents it
to its users as the usual chrono type (duration<float>).

Differential Revision: https://reviews.llvm.org/D117474
2022-01-19 16:42:53 +01:00
TCWG 9c4e93c71a [LLDB] Adjust compiler-full-path.test for Windows/Arm64
This patch updates compiler-full-path.test to make sure it passes on
Windows Arm64 platform with MSVC.
2022-01-19 19:47:03 +05: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
Pavel Labath 8bfa7a6dcc [lldb] Fix NativeThreadLinux to build with older compilers 2022-01-19 12:49:47 +01:00
Pavel Labath 6ff4af8e18 [lldb] Fix D114722 for python<=3.6
_Py_IsFinalizing was called _Py_Finalizing back then (and it was a
variable instead of a function).
2022-01-19 12:49:46 +01:00
Jonas Devlieghere d230848a85 [lldb] Print an error message when we're reading libobjc.A.dylib from memory
Use libobjc.A.dylib as a sentinel to detect situations where we're
reading libraries from process memory instead of the shared cache.

Differential revision: https://reviews.llvm.org/D117623
2022-01-18 17:23:38 -08:00
Pavel Labath 7f4d66f23e [lldb] Delete TestStopReplyContainsThreadPcs
This was meant to be a replacement for the lldb-server sub-test suite of
the API tests, but it never got off the ground and it's making the
windows bot flaky.

Deleting it does not reduce test coverage as the original api test is
still around.
2022-01-18 14:17:33 +01:00
Pavel Labath afb196c357 [lldb] s/dyn_cast/isa in TypeSystemClang 2022-01-18 10:33:40 +01:00
Pavel Labath 04f13da677 [lldb] Fix compiler warning in CommunicationTest
"0x80 changes value when converted to char"
2022-01-18 10:31:37 +01:00
Pavel Labath c154f397ee [lldb/python] Use PythonObject in LLDBSwigPython functions
Return our PythonObject wrappers instead of raw PyObjects (obfuscated as
void *). This ensures that ownership (reference counts) of python
objects is automatically tracked.

Differential Revision: https://reviews.llvm.org/D117462
2022-01-18 10:28:58 +01:00
Michał Górny e69a3d18f4 [lldb] [gdb-remote] Support client fallback for servers without reg defs
Provide minimal register definition defaults for working with servers
that implement neither target.xml nor qRegisterInfo packets.  This is
useful e.g. when interacting with FreeBSD's kernel minimal gdbserver
that does not send target.xml but uses the same layout for its supported
register subset as GDB.

The prerequisite for this is the ability to determine the correct
architecture, e.g. from the target executable.

Differential Revision: https://reviews.llvm.org/D116896
2022-01-17 22:31:49 +01:00
Ralf Grosse-Kunstleve a6598575f4 [LLDB] Fix Python GIL-not-held issues
The GIL must be held when calling any Python C API functions. In multithreaded applications that use callbacks this requirement can easily be violated by accident. A general tool to ensure GIL health is not available, but patching Python Py_INCREF to add an assert provides a basic health check:

```
+int PyGILState_Check(void); /* Include/internal/pystate.h */
+
 #define Py_INCREF(op) (                         \
+    assert(PyGILState_Check()),                 \
     _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
     ((PyObject *)(op))->ob_refcnt++)

 #define Py_DECREF(op)                                   \
     do {                                                \
+        assert(PyGILState_Check());                     \
         PyObject *_py_decref_tmp = (PyObject *)(op);    \
         if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
         --(_py_decref_tmp)->ob_refcnt != 0)             \
```

Adding this assertion causes around 50 test failures in LLDB. Adjusting the scope of things guarded by `py_lock` fixes them.

More background: https://docs.python.org/3/glossary.html#term-global-interpreter-lock

Patch by Ralf Grosse-Kunstleve

Differential Revision: https://reviews.llvm.org/D114722
2022-01-17 10:32:19 +01:00
Dave Lee 696f9706f3 [lldb] Set result error state in 'frame variable'
Ensure that errors in `frame variable` are reflected in result object.

The statistics for `frame variable` show invocations as being successful, even
when executing one of the error paths.

This change replaces `result.GetErrorStream()` with `result.AppendError()`,
which also sets the status to `eReturnStatusFailed`.

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

Recommitting after D116901 and D116863.

(cherry picked from commit 2c7d10c412)
2022-01-15 14:20:12 -08:00
Jonas Devlieghere 0b010ef7b6 [lldb] Use PlatformMacOSX for Mac Catalyst
Use PlatformMacOSX for Mac Catalyst apps on both Intel (x86) and Apple
Silicon (arm64).
2022-01-15 11:42:29 -08:00
paperchalice 62af3eb259 [CMake][LLDB] Resolve install conflict when `LLDB_BUILD_FRAMEWORK=ON`
Try to fix https://github.com/llvm/llvm-project/issues/108

Install python scripts into canonical resource path

Differential revision: https://reviews.llvm.org/D116853
2022-01-15 10:43:05 -08:00
Jonas Devlieghere a6469cdbc4 [lldb] Correctly display the number of types found
Correctly display the number of types found for `target modules lookup
--type` and add a test.

Fixes #53219
2022-01-15 10:31:49 -08:00
Dave Lee a7e7f541c0 [lldb] Remove anon struct from frame-var-anon-unions test
This test for anonymous unions seems off. It tests the following:

```
union {
  // fields
};

struct {
  // fields
} var{...};
```

Both are anonymous types, but the first does not declare a variable and the
second one does. The test then checks that `frame var` can directly access the
fields of the anonymous union, but can't directly access the fields of the
anonymous struct variable.

The second test, to directly access the members of the struct variable, seems
pointless as similar code would not compile. A demonstration:

```
struct {
  int a;
  int z;
} a_z{23, 45};

printf("%d\n", a_z.a); // fine
printf("%d\n", a); // this does not compile
```

Since we can't directly access the fields in code, I'm not sure there's a
reason to test that lldb also can't directly access them (other than perhaps as
a regression test).

Differential Revision: https://reviews.llvm.org/D116863
2022-01-15 10:20:52 -08:00
Jonas Devlieghere ff85dcb1c5 [lldb] Remove PlatformDarwin::GetCompatibleArch helper
This also removes the corresponding unit tests. I wrote them to sanity
check my original refactoring and checked them in because why not. The
current implementation, without the added complexity of indices, is
simple enough that we can do without it.
2022-01-15 09:51:16 -08:00
Med Ismail Bennani 258cd02c6a [lldb/doc] Rephrase tutorial paragraph (NFC)
Fixes #52694

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-14 16:23:26 -08:00
Jonas Devlieghere a10692c734 [lldb] Only promote -Wignored-attributes to an error
Avoid other warnings from failing the test, such as
-Wunused-command-line-argument in the downstream Swift fork.
2022-01-14 16:19:16 -08:00
Jonas Devlieghere 8faca2ed6a [lldb] Fix platform selection on Apple Silicon
Currently, when connecting to a remote iOS device from the command line
on Apple Silicon, we end up using the host platform (PlatfromMacOSX)
instead of remote-ios (PlatformRemoteiOS). This happens because
PlatfromMacOSX includes arm64-apple-ios and arm64e-apple-ios as
compatible architectures, presumably to support debugging iOS Apps on
Apple Silicon [1].

This is a problem for debugging remote ios devices, because the host
platform doesn't look for an expanded shared cache on disk and as a
result we end up reading everything from memory, incurring a significant
performance hit.

The crux of this patch is to make PlatfromMacOSX *not* compatible with
arm64(e)-apple-ios. This also means that we now use remote-ios
(PlatformRemoteiOS) as the platform for debugging iOS apps on Apple
Silicon. This has the (unintended) side effect that unlike we do for the
host platform, we no longer check our local shared cache, and incur a
performance hit on debugging these apps.

To avoid that, PlatformRemoteiOS now also check the local cache to
support this use case, which is cheap enough to do unconditionally for
PlatformRemoteiOS.

[1] https://support.apple.com/guide/app-store/iphone-ipad-apps-mac-apple-silicon-fird2c7092da/mac

Differential revision: https://reviews.llvm.org/D117340
2022-01-14 16:03:49 -08:00
Muhammad Omair Javaid df13239c11 [LLDB] Skip TestIOHandlerPythonREPLSigint.py on AArch64/Linux
TestIOHandlerPythonREPLSigint.py is running falky on AArch64/Linux
buildbot failing randomly. Skipping it for AArch64/Linux as well.
2022-01-15 03:24:26 +05:00
Coelacanthus 1dab5f6c83
[LLDB][NFC] Fix a typo in comment
fix typo in comment: libcstd++ -> libstdc++

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D117288
2022-01-14 22:01:18 +08:00
Muhammad Omair Javaid 3dc858f984 [LLDB] Skip TestIOHandlerPythonREPLSigint.py on Arm/Linux
TestIOHandlerPythonREPLSigint.py is failing on Arm/Linux buildbot. I am
marking it as skip for now.
2022-01-14 15:46:54 +05:00
Dave Lee 1441ffe6a6 [lldb] Use __lldb_init_module instead of "if lldb.debugger" idiom
Update examples and docs to demonstrate using `__lldb_init_module` instead of
the idiom that checks for `lldb.debugger` at the top-level.

```
if __name__ == '__main__':
    ...
elif lldb.debugger:
    ...
```

Is replaced with:

```
if __name__ == '__main__':
    ...

def __lldb_init_module(debugger, internal_dict):
    ...
```

This change is for two reasons. First, it's generally encouraged not to only
use the convenience singletons (`lldb.{debugger,process,target,etc}`)
interactively from the `script` command. Second, there's a bug where
registering a python class as a command (using `command script add -c ...`),
result in the command not being runnable. Note that registering function-backed
commands does not have this bug.

Differential Revision: https://reviews.llvm.org/D117237
2022-01-13 16:37:49 -08:00
Jonas Devlieghere 049ae93097 [lldb] Fix that the embedded Python REPL crashes if it receives SIGINT
When LLDB receives a SIGINT while running the embedded Python REPL it
currently just crashes in ScriptInterpreterPythonImpl::Interrupt with an
error such as the one below:

  Fatal Python error: PyThreadState_Get: the function must be called
  with the GIL held, but the GIL is released (the current Python thread
  state is NULL)

The faulty code that causes this error is this part of
ScriptInterpreterPythonImpl::Interrupt:

  PyThreadState *state = PyThreadState_GET();
  if (!state)
    state = GetThreadState();
  if (state) {
    long tid = state->thread_id;
    PyThreadState_Swap(state);
    int num_threads = PyThreadState_SetAsyncExc(tid, PyExc_KeyboardInterrupt);

The obvious fix I tried is to just acquire the GIL before this code is
running which fixes the crash but the KeyboardInterrupt we want to raise
immediately is actually just queued and would only be raised once the
next line of input has been parsed (which e.g. won't interrupt Python
code that is currently waiting on a timer or IO from what I can see).
Also none of the functions we call here is marked as safe to be called
from a signal handler from what I can see, so we might still end up
crashing here with some bad timing.

Python 3.2 introduced PyErr_SetInterrupt to solve this and the function
takes care of all the details and avoids doing anything that isn't safe
to do inside a signal handler. The only thing we need to do is to
manually setup our own fake SIGINT handler that behaves the same way as
the standalone Python REPL signal handler (which raises a
KeyboardInterrupt).

From what I understand the old code used to work with Python 2 so I kept
the old code around until we officially drop support for Python 2.

There is a small gap here with Python 3.0->3.1 where we might still be
crashing, but those versions have reached their EOL more than a decade
ago so I think we don't need to bother about them.

Differential revision: https://reviews.llvm.org/D104886
2022-01-13 15:27:38 -08:00
Zequan Wu f00cd23cae Revert "Revert "[LLDB][NativePDB] Add support for inlined functions""
This reland 945aa520ef with fixes.

This reverts commit 10bc3362a1.
2022-01-13 14:00:24 -08:00
Dave Lee cb5ea132d2 [lldb] Add long help to `crashlog`
Convert the `crashlog` command to be implemented as a class. The `Symbolicate`
function is switched to a class, to implement `get_long_help`. The text for the
long help comes from the help output generated by `OptionParser`. That is, the
output of `help crashlog` is the same as `crashlog --help`.

Differential Revision: https://reviews.llvm.org/D117165
2022-01-13 11:09:40 -08:00
David Spickett cf7bfd6d05 [lldb][AArch64] Remove armv8.3-a flag from tagged memory read test
This was left over from when I had used some pointer authentication
instructions to sign the pointer. Then I realised that simply setting
the top byte is enough to prove the ABI plugin is being called.

Top byte ignore is a feature of the armv8-a architecure and doesn't
need any extra compiler flags.
2022-01-13 14:25:18 +00:00
Michał Górny 1e74e5e9e3 [lldb] [llgs] Implement qXfer:siginfo:read
Implement the qXfer:siginfo:read that is used to read the siginfo_t
(extended signal information) for the current thread.  This is currently
implemented on FreeBSD and Linux.

Differential Revision: https://reviews.llvm.org/D117113
2022-01-13 11:24:36 +01:00
Walter Erquinigo 1f53dd1f23 [CODE OWNERS] Add wallace as code owner 2022-01-12 12:36:30 -08:00
Stella Stamenova 8fec756c0b [lldb] Disable one more watchpoint test on Windows
This should be the last remaining flaky watchpoint test on Windows
2022-01-12 08:55:48 -08:00
Stella Stamenova 10bc3362a1 Revert "[LLDB][NativePDB] Add support for inlined functions"
This reverts commit 945aa520ef.

This commit broke the windows lldb bot.
2022-01-12 08:53:19 -08:00
Michał Górny 9a1ce35d7e [lldb] [Process/FreeBSD] Set current thread ID on events
Set the current thread ID to the thread where an event happened.
As a result, e.g. when a signal is delivered to a thread other than
the first one, the respective T packet refers to the signaled thread
rather than the first thread (with no stop reason).  While this doesn't
strictly make a difference to the LLDB client, it is the expected
behavior.

Differential Revision: https://reviews.llvm.org/D117103
2022-01-12 15:40:13 +01:00
David Spickett 3fd9c90bdc [lldb][AArch64] Correct top nibble setting in memory tag read tests
Due to a missing cast the << 60 always resulted in zero leaving
the top nibble empty. So we weren't actually testing that lldb
ignores those bits in addition to the tag bits.

Correct that and also set the top nibbles to ascending values
so that we can catch if lldb only removes one of the tag bits
and top nibble, but not both.

In future the tag manager will likely only remove the tag bits
and leave non-address bits to the ABI plugin but for now make
sure we're testing what we claim to implement.
2022-01-12 12:28:13 +00:00
David Spickett 091e760cd3 [lldb] Don't print "Command Options Usage:" for an alias with no options
"shell" is an alias to "platform shell -h --". Previously you would get this
help text:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell <shell-command>

Command Options Usage:

'shell' is an abbreviation for 'platform shell -h   --'

Since the code doesn't handle the base command having options
but the alias removing them. With these changes you get:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell <shell-command>

'shell' is an abbreviation for 'platform shell -h   --'

Note that we already handle a non-alias command having no options,
for example "quit":

(lldb) help quit
Quit the LLDB debugger.

Syntax: quit [exit-code]

Reviewed By: JDevlieghere, jingham

Differential Revision: https://reviews.llvm.org/D117004
2022-01-12 10:07:38 +00:00
Dave Lee 06c7bdc8f1 [lldb] Specify LLVM target requirements in TestLaunchProcessPosixSpawn 2022-01-11 19:00:47 -08:00
Zequan Wu 945aa520ef [LLDB][NativePDB] Add support for inlined functions
This adds inline function support to NativePDB by parsing S_INLINESITE records
to retrieve inlinee line info and add them into line table at `ParseLineTable`.

Differential Revision: https://reviews.llvm.org/D116845
2022-01-11 16:10:39 -08:00
Shafik Yaghmour c0e4154711 Fix clang-tidy bugprone-argument-comment that was mixed up
Several of the comments were annotating the wrong argument.

I caught this while reviewing this clean-up: 8afcfbfb8f

which was changing booleans to use true and false and in the this case the comment and the type looked mismatched.

Differential Revision: https://reviews.llvm.org/D116982
2022-01-11 11:12:28 -08:00
David Spickett 88fdce5be6 [lldb] Remove non address bits from memory read arguments
Addresses on AArch64 can have top byte tags, memory tags and pointer
authentication signatures in the upper bits.

While testing memory tagging I found that memory read couldn't
read a range if the two addresses had different tags. The same
could apply to signed pointers given the right circumstance.

(lldb) memory read mte_buf_alt_tag mte_buf+16
error: end address (0x900fffff7ff8010) must be greater than the start
address (0xa00fffff7ff8000).

Or it would try to read a lot more memory than expected.

(lldb) memory read mte_buf mte_buf_alt_tag+16
error: Normally, 'memory read' will not read over 1024 bytes of data.
error: Please use --force to override this restriction just once.
error: or set target.max-memory-read-size if you will often need a
larger limit.

Fix this by removing non address bits before we calculate the read
range. A test is added for AArch64 Linux that confirms this by using
the top byte ignore feature.

This means that if you do read with a tagged pointer the output
does not include those tags. This is potentially confusing but I think
overall it's better that we don't pretend that we're reading memory
from a range that the process is unable to map.

(lldb) p ptr1
(char *) $4 = 0x3400fffffffff140 "\x80\xf1\xff\xff\xff\xff"
(lldb) p ptr2
(char *) $5 = 0x5600fffffffff140 "\x80\xf1\xff\xff\xff\xff"
(lldb) memory read ptr1 ptr2+16
0xfffffffff140: 80 f1 ff ff ff ff 00 00 38 70 bc f7 ff ff 00 00  ........8p......

Reviewed By: omjavaid, danielkiss

Differential Revision: https://reviews.llvm.org/D103626
2022-01-11 13:24:09 +00:00
Pavel Labath 6d8d1c5ea3 [lldb/qemu] Implement GetMmapArgumentList
By forwarding it to the host platform.
2022-01-11 14:08:03 +01:00
Lirong Yuan 1267506ea5 [lldb] fix memory leak in "GetGDBServerRegisterInfoXMLAndProcess"
While running heap checker on a test that uses LLDB API, the following memory leak is found:

RAW: HeapChecker started...
RAW: Leak check _main_ detected leaks of 34 bytes in 4 objects
RAW: The 2 largest leaks:
RAW: Leak of 17 bytes in 2 objects allocated from:
@ 0x7fb93bd20166 NewHook()
@ 0x7fb929372a73 absl::base_internal::MallocHook::InvokeNewHookSlow()
@ 0x5600d1046093 libc_malloc
@ 0x7fb974529c03 xmlStrdup
@ 0x7fb9744c2a0b xmlGetProp
@ 0x7fb9749d9ed6 lldb_private::XMLNode::GetAttributeValue()
@ 0x7fb979043001 std::u::function::policy_invoker<>::__call_impl<>()
@ 0x7fb9749da06d lldb_private::XMLNode::ForEachChildElement()
@ 0x7fb97903c54d lldb_private::process_gdb_remote::ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess()
@ 0x7fb97902cfe4 lldb_private::process_gdb_remote::ProcessGDBRemote::GetGDBServerRegisterInfo()
@ 0x7fb97902c1d0 lldb_private::process_gdb_remote::ProcessGDBRemote::BuildDynamicRegisterInfo()
@ 0x7fb97902e92a lldb_private::process_gdb_remote::ProcessGDBRemote::SetThreadStopInfo()
@ 0x7fb97902db18 lldb_private::process_gdb_remote::ProcessGDBRemote::DoConnectRemote()
@ 0x7fb97584965e lldb_private::Process::ConnectRemote()
@ 0x7fb975839fa6 lldb_private::Platform::DoConnectProcess()
@ 0x7fb97583a39e lldb_private::Platform::ConnectProcessSynchronous()
@ 0x7fb97545b28b CommandObjectProcessConnect::DoExecute()
@ 0x7fb9755a70c9 lldb_private::CommandObjectParsed::Execute()
@ 0x7fb97559c0e9 lldb_private::CommandInterpreter::HandleCommand()
@ 0x7fb975460145 lldb_private::CommandObjectRegexCommand::DoExecute()
@ 0x7fb9755a72d2 lldb_private::CommandObjectRaw::Execute()
@ 0x7fb97559c0e9 lldb_private::CommandInterpreter::HandleCommand()
@ 0x7fb997a5f22e lldb::SBCommandInterpreter::HandleCommand()
@ 0x7fb997a5ef9b lldb::SBCommandInterpreter::HandleCommand()

This change fixes the memory leaks by freeing memory after it is no
longer in use. Tested with "ninja check-lldb".

Differential revision: https://reviews.llvm.org/D116707
2022-01-10 14:33:09 -08: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 4609e30f50 [lldb] Remove lldb-instr 2022-01-10 11:48:16 -08:00
Stella Stamenova 9b5cf7267b [lldb] Disable several lldb tests that are flaky on Windows
This tests have recently become flaky (flakier?) causing occasional failures in the windows lldb buildbot
2022-01-10 10:21:12 -08:00
Pavel Labath 8ccfcab34f [lldb/platform-gdb] Clear cached protocol state upon disconnection
Previously we would persist the flags indicating whether the remote side
supports a particular feature across reconnects, which is obviously not
a good idea.

I implement the clearing by nuking (its the only way to be sure :) the
entire GDBRemoteCommunication object in the disconnect operation and
creating a new one upon connection. This allows us to maintain a nice
invariant that the GDBRemoteCommunication object (which is now a
pointer) exists only if it is connected. The downside to that is that a
lot of functions now needs to check the validity of the pointer instead
of blindly accessing the object.

The process communication does not suffer from the same issue because we
always destroy the entire Process object for a relaunch.

Differential Revision: https://reviews.llvm.org/D116539
2022-01-10 16:27:30 +01:00