Commit Graph

26328 Commits

Author SHA1 Message Date
Fangrui Song c129220eaa [lldb/gdb-remote] Fix -Wswitch after D116462 2022-04-19 18:01:06 -07:00
David Spickett 68e73eaee6 [lldb] Handle empty search string in "memory find"
Given that you'd never find empty string, just error.

Also add a test that an invalid expr generates an error.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D123793
2022-04-19 09:19:38 +00:00
Saleem Abdulrasool 2696d82fa0 Windows: correct iteration of additional search paths
This adjusts the path iteration - `paths` is a null-terminated sequence
of C strings, creating an array from a single contiguous buffer.  We
would previously continue to iterate indefinitely as we did not check if
we had encountered the terminator.

Found by inspection.
2022-04-16 18:01:02 -07:00
Zequan Wu dc100ebfda [LLDB][NativePDB] Followup c50817d1be 2022-04-15 12:08:44 -07:00
Zequan Wu c50817d1be [LLDB][NativePDB] Don't create inlined function parameters when it's malformed. 2022-04-15 11:59:11 -07:00
Zequan Wu 2f78f9455f [LLDB][NativePDB] Fix subfield_register_simple_type.s test 2022-04-15 10:36:25 -07:00
Jonas Devlieghere af91446aa2
[lldb] Show the DBGError if dsymForUUID can't find a dSYM
Show the user the DBGError (if available) when dsymForUUID fails.

rdar://90949180

Differential revision: https://reviews.llvm.org/D123743
2022-04-14 16:54:00 -07:00
Jonas Devlieghere 03049c5125
Revert "[lldb] Pin the shared cache when iterating over its images"
This reverts commit af969141fa because it
didn't have the intended performance benefit to offset the increase in
our (virtual) memory usage.
2022-04-14 16:23:56 -07:00
Jonas Devlieghere 428775d518
[lldb] Remove TestShell.test
Remove TestShell.test because it's failing on the bot with "this is a
non-interactive debug session, cannot get permission to debug
processes." The only thing that's special about this test is the shell
we're launching with. I need to do a bit of digging to understand why
that's causing this error.

rdar://91766931
2022-04-14 12:10:54 -07:00
Zequan Wu 3dbf524ad7 [LLDB][NativePDB] Fix a crash when S_DEFRANGE_SUBFIELD_REGISTER descirbes a simple type
When a variable is simple type and has 64 bits, the debug info may look like the following when targeting 32bit windows. The variable's content is split into two 32bits registers.
```
480 | S_LOCAL [size = 12] `x`
      type=0x0013 (__int64), flags = param
492 | S_DEFRANGE_SUBFIELD_REGISTER [size = 20]
      register = EAX, may have no name = true, offset in parent = 0
      range = [0001:0073,+7), gaps = []
512 | S_DEFRANGE_SUBFIELD_REGISTER [size = 20]
      register = ECX, may have no name = true, offset in parent = 4
      range = [0001:0073,+7), gaps = []
```

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D122943
2022-04-14 11:06:21 -07:00
Zequan Wu ef7cba7148 [LLDB][NativePDB] Fix inline line info in line table
It fixes the following case:
```
0602      line 1 (+1)
0315      code 0x15 (+0x15)
0B2B      code 0x20 (+0xB) line 2 (+1)
0602      line 3 (+1)
0311      code 0x31 (+0x11)
...
```

Inline ranges should have following mapping:
`[0x15, 0x20) -> line 1`
`[0x20, 0x31) -> line 2`
Inline line entries:
`0x15, line 1`, `0x20, line 2`, `0x31, line 3`.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D123092
2022-04-14 11:00:56 -07:00
Jonas Devlieghere 99d9c44434
[lldb] Port Process::PrintWarning* to use the new diagnostic events
Port the two Process::PrintWarning functions to use the new diagnostic
events through Debugger::ReportWarning. I kept the wrapper function in
the process, but delegated the work to the Module. Consistent with the
current code, the Module ensures the warning is only printed once per
module.

Differential revision: https://reviews.llvm.org/D123698
2022-04-14 11:00:21 -07:00
Jonas Devlieghere 64d9b233b9
[lldb] Prevent crash when adding a stop hook with --shlib
Currently, lldb crashes when adding a stop hook with --shlib because we
unconditionally use the target in SymbolContextSpecifier::AddSpecification.
This patch prevents the crash and add a test.

rdar://68524781

Differential revision: https://reviews.llvm.org/D123746
2022-04-14 11:00:21 -07:00
Jonas Devlieghere 6443d0d413
[lldb] Remove reproducer logic from LocateSymbolFileMacOSX 2022-04-13 16:27:02 -07:00
Jonas Devlieghere 80c600fe98
[lldb] Format LocateSymbolFileMacOSX (NFC) 2022-04-13 16:27:02 -07:00
Jonas Devlieghere 343f3de559
[lldb] Fix a bug in the decorator matching logic.
This changes the decorator helper `_match_decorator_property` to
consider `None` as the actual value as not a match. Using `None` for the
pattern continues to be considered a match.

I discovered the issue because marking a test as NO_DEBUG_INFO_TESTCASE
will cause the call to `self.getDebugInfo()` to return `None` and
incorrectly skip or XFAIL the corresponding test.

I used the above scenario to create a test for the decorators.

Differential revision: https://reviews.llvm.org/D123401
2022-04-13 15:07:33 -07:00
Jonas Devlieghere 763ff89c0e
[debugserver ] Un-conditionalize use of libcompression
Jason removed the include guards in 681f6c2f55. This patch removes the
corresponding CMake logic as well.

Differential revision: https://reviews.llvm.org/D123616
2022-04-13 14:36:25 -07:00
Jonas Devlieghere acc56e55fe
[lldb] Expand $ when using tcsh
Unlike for any of the other shells, we were escaping $ when using tcsh.
There's nothing special about $ in tcsh and this prevents you from
expanding shell variables, one of the main reasons this functionality
exists in the first place.

Differential revision: https://reviews.llvm.org/D123690
2022-04-13 13:01:09 -07:00
Nathan Sidwell 201c4b9cc4 [demangler] Rust demangler buffer return
The rust demangler has some odd buffer handling code, which will copy
the demangled string into the provided buffer, if it will fit.
Otherwise it uses the allocated buffer it made.  But the length of the
incoming buffer will have come from a previous call, which was the
length of the demangled string -- not the buffer size.  And of course,
we're unconditionally allocating a temporary buffer in the first
place.  So we don't actually get buffer reuse, and we get a memcpy in
somecases.

However, nothing in LLVM ever passes in a non-null pointer.  Neither
does anything pass in a status pointer that is then made use of.  The
only exercise these have is in the test suite.

So let's just make the rust demangler have the same API as the dlang
demangler.

Reviewed By: tmiasko

Differential Revision: https://reviews.llvm.org/D123420
2022-04-13 08:50:04 -07:00
Pavel Labath 7d70b1a405 [lldb] Fixup af921006d3 for non-linux platforms 2022-04-13 15:38:36 +02: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 a3d69a193a
[lldb] Re-enable TestStepNoDebug.py on AS
This test showed up as an unexpected pass and is now consistently
passing on Apple Silicon.
2022-04-12 20:28:29 -07:00
Jonas Devlieghere 990d0c7109
[lldb] Print diagnostic prefixes (error, warning) in color
Print diagnostic prefixes (error, warning) in their respective colors
when colors are enabled.
2022-04-12 20:28:29 -07:00
Raphael Isemann 07a722c574
[lldb] Escape semicolons for all shells
LLDB supports having globbing regexes in the process launch arguments
that will be resolved using the user's shell. This requires that we pass
the launch args to the shell and then read back the expanded arguments
using LLDB's argdumper utility.

As the shell will not just expand the globbing regexes but all special
characters, we need to escape all non-globbing charcters such as $, &,
<, >, etc. as those otherwise are interpreted and removed in the step
where we expand the globbing characters. Also because the special
characters are shell-specific, LLDB needs to maintain a list of all the
characters that need to be escaped for each specific shell.

This patch adds the missing semicolon character to the escape list for
all currently supported shells. Without this having a semicolon in the
binary path or having a semicolon in the launch arguments will cause the
argdumping process to fail. E.g., lldb -- ./calc "a;b" was failing
before but is working now.

Fixes rdar://55776943

Differential revision: https://reviews.llvm.org/D104629
2022-04-12 18:13:55 -07:00
Walter Erquinigo 44103c96fa [trace][intelpt] Remove code smell when printing the raw trace size
Something ugly I did was to report the trace buffer size to the DecodedThread,
which is later used as part of the `dump info` command. Instead of doing that,
we can just directly ask the trace for the raw buffer and print its size.

I thought about not asking for the entire trace but instead just for its size,
but in this case, as our traces as not extremely big, I prefer to ask for the
entire trace, ensuring it could be fetched, and then print its size.

Differential Revision: https://reviews.llvm.org/D123358
2022-04-12 13:08:03 -07:00
Walter Erquinigo bdf3e7e5b8 [trace][intelpt] Add task timer classes
I'm adding two new classes that can be used to measure the duration of long
tasks as process and thread level, e.g. decoding, fetching data from
lldb-server, etc. In this first patch, I'm using it to measure the time it takes
to decode each thread, which is printed out with the `dump info` command. In a
later patch I'll start adding process-level tasks and I might move these
classes to the upper Trace level, instead of having them in the intel-pt
plugin. I might need to do that anyway in the future when we have to
measure HTR. For now, I want to keep the impact of this change minimal.

With it, I was able to generate the following info of a very big trace:

```
(lldb) thread trace dump info                                                                                                            Trace technology: intel-pt

thread : tid = 616081
  Total number of instructions: 9729366

  Memory usage:
    Raw trace size: 1024 KiB
    Total approximate memory usage (excluding raw trace): 123517.34 KiB
    Average memory usage per instruction (excluding raw trace): 13.00 bytes

  Timing:
    Decoding instructions: 1.62s

  Errors:
    Number of TSC decoding errors: 0
```

As seen above, it took 1.62 seconds to decode 9.7M instructions. This is great
news, as we don't need to do any optimization work in this area.

Differential Revision: https://reviews.llvm.org/D123357
2022-04-12 13:08:03 -07:00
Jonas Devlieghere a66ff2316e
[lldb] Re-enable fixed on-device tests
These tests were fixed by 833882b327.
2022-04-12 11:39:25 -07:00
Pavel Labath 45428412fd [lldb] Adjust libc++ string formatter for changes in D122598
The __size_ member is now in a slightly different location.
2022-04-12 15:44:16 +02:00
David Spickett 0231a90bc4 [lldb][AArch64] Automatically add all extensions to disassembler
This means we don't have to remember to update this code as much.

This is all tested in lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
which I added previously.

We don't have a way to get the latest base architecture yet
so that remains manual. Having all the extensions specified
will probably be equivalent to the latest architecture version
in any case.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D123582
2022-04-12 12:31:43 +00:00
Luboš Luňák 195a8b977e don't extra notify ModulesDidLoad() from LoadModuleAtAddress()
Places calling LoadModuleAtAddress() already call ModulesDidLoad()
after a loop calling LoadModuleAtAddress(), so it's not necessary
to call it from there, and the batched ModulesDidLoad() may be
more efficient than this place calling it one after one.

This also makes the ModuleLoadedNotifys test pass on Linux now that
the duplicates no longer bring down the average of modules notified
per call.

Differential Revision: https://reviews.llvm.org/D123128
2022-04-12 00:36:33 +02:00
Jonas Devlieghere cbcb3bcee3
[lldb] Don't report progress in the REPL
Don't report progress events in the REPL. Most of the progress events
are debugger specific which are useful when you're debugging, but not so
much when you're waiting for the next line to be executed in the REPL.

This patch disables reporting of progress events when in REPL mode.

rdar://91502950

Differential revision: https://reviews.llvm.org/D123426
2022-04-11 13:06:40 -07:00
Martin Storsjö 373d08adb4 [lldb] Silence warnings about unused static variables in RegisterInfos_arm64.h
Move them to the only source file that included RegisterInfos_arm64.h
that actually used these variables.

This silences warnings like these:

    In file included from lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp:42:
    lldb/source/Plugins/Process/Utility/RegisterInfos_arm64.h:790:35: warning: ‘g_register_infos_mte’ defined but not used [-Wunused-variable]
      790 | static lldb_private::RegisterInfo g_register_infos_mte[] = {
          |                                   ^~~~~~~~~~~~~~~~~~~~
    lldb/source/Plugins/Process/Utility/RegisterInfos_arm64.h:787:35: warning: ‘g_register_infos_pauth’ defined but not used [-Wunused-variable]
      787 | static lldb_private::RegisterInfo g_register_infos_pauth[] = {
          |                                   ^~~~~~~~~~~~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D123206
2022-04-11 19:50:48 +03:00
Fangrui Song ca68038d12 Reland "[Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON""
(With C++ exceptions, `clang++ --target=mips64{,el}-linux-gnu -fpie -pie
-fuse-ld=lld` has link errors (lld does not implement some strange R_MIPS_64
.eh_frame handling in GNU ld). However, sanitizer-x86_64-linux-qemu used this to
build ScudoUnitTests. Pined ScudoUnitTests to -no-pie.)

Default the option introduced in D113372 to ON to match all(?) major Linux
distros. This matches GCC and improves consistency with Android and linux-musl
which always default to PIE.
Note: CLANG_DEFAULT_PIE_ON_LINUX may be removed in the future.

Differential Revision: https://reviews.llvm.org/D120305
2022-04-08 23:40:18 -07:00
Jim Ingham 833882b327 Adapt the ObjC stepping algorithm to deal with "selector-stubs" in clang.
Clang is adding a feature to ObjC code generation, where instead of calling
objc_msgSend directly with an object & selector, it generates a stub that
gets passed only the object and the stub figures out the selector.

This patch adds support for following that dispatch method into the implementation
function.
2022-04-08 17:45:16 -07:00
Adrian Prantl 0bc9372fa7 Skip test on earlier clang versions 2022-04-08 15:40:57 -07:00
Jonas Devlieghere de2ddc8f31
[lldb] XFAIL tests that aren't passing remotely
XFAIL a series of tests that are failing remotely.
2022-04-08 15:02:26 -07:00
Jonas Devlieghere 065e3c9a8e
[lldb] Skip more tests that don't make sense to run remotely
Skip another batch of tests that don't really make sense to run
remotely.
2022-04-08 15:02:22 -07:00
Jonas Devlieghere 66b829ac7b
[lldb] Skip a bunch of tests that shouldn't run remotely
Skip a bunch of tests that don't really make sense to run remotely.
2022-04-08 10:46:34 -07:00
Jonas Devlieghere 257f984662
[lldb] Fix TestQuoting when run remotely 2022-04-08 10:46:34 -07:00
Jonas Devlieghere af2ea183f5
[lldb] Import Foundation in TestConflictingDefinition.py
We need to import foundation to get a 'NSLog' declaration when building
against the iOS SDK. This doesn't appear necessary when building against
the macOS SDK, presumable because it gets transitively imported by
objc/NSObject.h
2022-04-08 10:46:34 -07:00
Walter Erquinigo e0cfe20ad2 [trace][intel pt] Create a common accessor for live and postmortem data
Some parts of the code have to distinguish between live and postmortem threads
to figure out how to get some data, e.g. thread trace buffers. This makes the
code less generic and more error prone. An example of that is that we have
two different decoders: LiveThreadDecoder and PostMortemThreadDecoder. They
exist because getting the trace bufer is different for each case.

The problem doesn't stop there. Soon we'll have even more kinds of data, like
the context switch trace, whose fetching will be different for live and post-
mortem processes.

As a way to fix this, I'm creating a common API for accessing thread data,
which is able to figure out how to handle the postmortem and live cases on
behalf of the caller. As a result of that, I was able to eliminate the two
decoders and unify them into a simpler one. Not only that, our TraceSave
functionality only worked for live threads, but now it can also work for
postmortem processes, which might be useful now, but it might in the future.

This common API is OnThreadBinaryDataRead. More information in the inline
documentation.

Differential Revision: https://reviews.llvm.org/D123281
2022-04-07 15:58:44 -07:00
Walter Erquinigo 6423b50235 [trace][intel pt] Create a class for the libipt decoder wrapper
As we soon will need to decode multiple raw traces for the same thread,
having a class that encapsulates the decoding of a single raw trace is
a stepping stone that will make the coming features easier to implement.

So, I'm creating a LibiptDecoder class with that purpose. I refactored
the code and it's now much more readable. Besides that, more comments
were added. With this new structure, it's also easier to implement unit
tests.

Differential Revision: https://reviews.llvm.org/D123106
2022-04-07 15:58:34 -07: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
Luboš Luňák c29a51b3a2 [lldb][gui] remove the "expand" diamond for variables where expanding fails
If the variables view shows a variable that is a struct that has
MightHaveChildren(), the expand diamond is shown, but if trying to expand
it and it's not possible (e.g. incomplete type), remove the expand diamond
to visualize that it can't be in fact expanded. Otherwise it feels kinda
weird that a tree item cannot be expanded even though it "should".

I guess the MightHaveChildren() checking means that GetChildren() may
be expensive, so also do not call it for rows that are not expanded.

Differential Revision: https://reviews.llvm.org/D123008
2022-04-07 21:59:18 +02:00
Luboš Luňák f42f21746c [lldb][gui] handle Ctrl+C to stop a running process
Differential Revision: https://reviews.llvm.org/D123015
2022-04-07 21:58:37 +02: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
Nico Weber e22a60b1c8 Revert "Reland "[Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON"""
This reverts commit 2aca33baf1.
Broke tests on several bots, see comments on https://reviews.llvm.org/D120305
2022-04-07 10:07:07 -04:00
Mehdi Chinoune 3031fa88f0 [lldb] Fix building standalone LLDB on Windows.
It was broken since https://reviews.llvm.org/D110172

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D122523
2022-04-07 12:30:33 +03:00
Martin Storsjö 5560b9e884 [lldb] [CMake] Disable GCC's -Wstringop-truncation warning. NFC.
This warning gives false positives about lldb's correct use of
strncpy to fill fixed length fields that don't need null termination,
in lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp, like this:

    In file included from /usr/include/string.h:495,
                     from /usr/include/c++/9/cstring:42,
                     from ../include/llvm/ADT/StringRef.h:19,
                     from ../tools/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:10:
    In function ‘char* strncpy(char*, const char*, size_t)’,
        inlined from ‘lldb::offset_t CreateAllImageInfosPayload(const ProcessSP&, lldb::offset_t, lldb_private::StreamString&, lldb::SaveCoreStyle)’ at ../tools/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:6341:16:
    /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 16 equals destination size [-Wstringop-truncation]
      106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
          |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

The warning could be squelched locally with

    #pragma GCC diagnostic ignored "-Wstringop-truncation"

too, but Clang also interprets those GCC pragmas, and produces
a -Wunknown-warning-option warning instead. That could be remedied
by wrapping the pragma in an "#ifndef __clang__" - but that makes
things even more messy. Instead, just silence this warning entirely.

Differential Revision: https://reviews.llvm.org/D123254
2022-04-07 12:09:01 +03:00
Jason Molenda 4d3cc27831 Correct debugserver to write xmm/ymm/zmm reg values
debugserver does not call thread_set_state when changing xmm/ymm/zmm
register values, so the register contents are never updated.  Fix
that.  Mark the shell tests which xfail'ed these tests on darwin systems
to xfail them when the system debugserver, they will pass when using
the in-tree debugserver.  When this makes it into the installed
system debugservers, we'll remove the xfails.

Differential Revision: https://reviews.llvm.org/D123269
rdar://91258333
rdar://31294382
2022-04-06 23:36:52 -07:00