Commit Graph

26919 Commits

Author SHA1 Message Date
Muhammad Omair Javaid 891319f654 [LLDB] Fix pointers.test for AArch64/Windows
pointers.test started failing again for AArch64 windows after D125509
This patch fixes the test to make it pass on AArch64 windows again.

LLDB AArch64 Windows buildbot running at:
https://lab.llvm.org/staging/#/builders/207
2022-07-13 15:55:31 +05:00
Martin Storsjö 306fc2cd87 [lldb] Fix build with GCC 9 after "[ADT] Use Empty Base Optimization for Allocators"
This fixes this compilation error, after
a565509308f9372c4de1c4c32afde461a42e81c8:

In file included from ../tools/lldb/include/lldb/Host/Host.h:14,
                 from ../tools/lldb/source/Host/common/File.cpp:28:
../tools/lldb/include/lldb/Utility/Environment.h: In copy constructor ‘lldb_private::Environment::Environment(const lldb_private::Environment&)’:
../tools/lldb/include/lldb/Utility/Environment.h:60:49: error: call of overloaded ‘StringMap(const lldb_private::Environment&)’ is ambiguous
   60 |   Environment(const Environment &RHS) : Base(RHS) {}
      |                                                 ^
In file included from ../include/llvm/Support/YAMLTraits.h:16,
                 from ../tools/lldb/include/lldb/Utility/ConstString.h:15,
                 from ../tools/lldb/include/lldb/Utility/FileSpec.h:15,
                 from ../tools/lldb/include/lldb/Host/FileSystem.h:14,
                 from ../tools/lldb/source/Host/common/File.cpp:27:
../include/llvm/ADT/StringMap.h:137:3: note: candidate: ‘llvm::StringMap<ValueTy, AllocatorTy>::StringMap(const llvm::StringMap<ValueTy, AllocatorTy>&) [with ValueTy = std::__cxx11::basic_string<char>; AllocatorTy = llvm::MallocAllocator]’
  137 |   StringMap(const StringMap &RHS)
      |   ^~~~~~~~~
../include/llvm/ADT/StringMap.h:122:12: note: candidate: ‘llvm::StringMap<ValueTy, AllocatorTy>::StringMap(AllocatorTy) [with ValueTy = std::__cxx11::basic_string<char>; AllocatorTy = llvm::MallocAllocator]’
  122 |   explicit StringMap(AllocatorTy A)
      |            ^~~~~~~~~
2022-07-13 12:57:04 +03:00
Kazu Hirata e5f568a49f Use has_value instead of hasValue (NFC) 2022-07-13 01:58:03 -07:00
Walter Erquinigo dbc0cb0198 [trace] Avoid a crash in the dumper when disassembling fails
In rare situations, disassemblying would fail that produce an invalid
InstructionSP object. We need to check that it's valid before using.

With this change, now the dumper doesn't crash with dumping instructions of
ioctl. In fact, it now dumps this output

 {
    "id": 6135,
    "loadAddress": "0x7f4bfe5c7515",
    "module": "libc.so.6",
    "symbol": "ioctl",
    "source": "glibc/2.34/src/glibc-2.34/sysdeps/unix/syscall-template.S",
    "line": 120,
    "column": 0
 }

Anyway, we need to investigate why the diassembler failed disassembling that
instruction. From over 2B instructions I was disassembling today, just this
one failed, so this could be a bug in LLVM's core disassembler.

Differential Revision: https://reviews.llvm.org/D129588
2022-07-12 16:23:03 -07:00
Walter Erquinigo ad7bcda940 [trace] Add a flag to the decoder to output the instruction type
To build complex binding upon instruction trace, additional metadata 'instruction type' is needed.

This diff has followings:
 - Add a flag -k  / --kind for instruction dump
 - Remove SetGranularity and SetIgnoreErros from Trace cursor

Sample output:

```
(lldb) thread trace dump instruction -k
thread #1: tid = 3198805
  libc.so.6`_IO_puts + 356
    2107: 0x00007ffff7163594 (    return)     retq
    2106: 0x00007ffff7163592 (     other)     popq   %r13
    2105: 0x00007ffff7163590 (     other)     popq   %r12
    2104: 0x00007ffff716358f (     other)     popq   %rbp
    2103: 0x00007ffff716358e (     other)     popq   %rbx
    2102: 0x00007ffff716358c (     other)     movl   %ebx, %eax
    2101: 0x00007ffff7163588 (     other)     addq   $0x8, %rsp
    2100: 0x00007ffff7163570 ( cond jump)     je     0x89588                   ; <+344>
    2099: 0x00007ffff716356e (     other)     decl   (%rdx)
    2098: 0x00007ffff7163565 ( cond jump)     je     0x8956e                   ; <+318>
    2097: 0x00007ffff716355e (     other)     cmpl   $0x0, 0x33c02b(%rip)      ; __libc_multiple_threads
    2096: 0x00007ffff7163556 (     other)     movq   $0x0, 0x8(%rdx)
    2095: 0x00007ffff7163554 ( cond jump)     jne    0x89588                   ; <+344>
    2094: 0x00007ffff7163550 (     other)     subl   $0x1, 0x4(%rdx)
    2093: 0x00007ffff7163549 (     other)     movq   0x88(%rbp), %rdx
    2092: 0x00007ffff7163547 ( cond jump)     jne    0x89588                   ; <+344>
    2091: 0x00007ffff7163540 (     other)     testl  $0x8000, (%rbp)           ; imm = 0x8000
    2090: 0x00007ffff716353c (     other)     cmovaq %rax, %rbx
    2089: 0x00007ffff7163535 (     other)     cmpq   $0x7fffffff, %rbx         ; imm = 0x7FFFFFFF
    2088: 0x00007ffff7163530 (     other)     movl   $0x7fffffff, %eax         ; imm = 0x7FFFFFFF
```

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D128477
2022-07-12 16:23:03 -07:00
Jonas Devlieghere 5edfc0b928
[lldb] Fix macOS Ventura version number checks
Unlike Python 2 which reports 10.16 on any recent macOS, Python 3
correctly reports Ventura as macOS 13.
2022-07-12 13:29:46 -07:00
Jonas Devlieghere b620852d23
[lldb] Make the g_arguments_data constexpr and fix the static assert
This fixes the static assert that's meant to keep the g_arguments_data
table in sync with the CommandArgumentType enumeration. Indeed, the
assert didn't fire even though the current code is missing an entry.
This patches fixes that as well.

Differential revision: https://reviews.llvm.org/D129529
2022-07-12 13:12:36 -07:00
Pavel Labath a72306e202 [lldb] Fix TestDataFormatterLibcxxString broken by D129490
We need to check for the error inside the value object to avoid reading
garbage through invalid (target) pointers.
2022-07-12 20:12:22 +02:00
Zequan Wu b74a01a80b Reland "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."
This reland 227dffd0b6 and
562c3467a6 with failed api tests fixed by keeping
function base file addres in DWARFExpressionList.
2022-07-12 10:54:24 -07:00
Nico Weber 7f83dae7f5 try to fix lldb build after d489268392 2022-07-12 11:08:44 -04:00
Muhammad Omair Javaid 7b69843f0b [LLDB] Catagory decorator for watchpoint test in TestCompletion.py
This patch adds watchpoint catagory decorator to watchpoint dependent
tests in TestCompletion.py.
2022-07-12 17:15:33 +05:00
Muhammad Omair Javaid 68cc1eeb1d [LLDB] Fix NativePDB/local-variables.cpp for AArch64/Windows
This patch fixes NativePDB/local-variables.cpp test for AArch64 Windows.
There are two changes:
1) Replace function breakpoint with line breakpoint required due to pr56288
2) Adjust "target modules dump ast" test as the output was slightly different
on AArch64/Windows.
2022-07-12 16:26:47 +05:00
David M. Lary 1e3ee766bb [lldb] add SBSection.alignment to python bindings
This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb.

Reviewed By: clayborg, JDevlieghere, labath

Differential Revision: https://reviews.llvm.org/D128069
2022-07-12 12:18:38 +02:00
Pavel Labath 918b1e7bbd Revert "[lldb] add SBSection.alignment to python bindings"
The patch didn't get proper attribution. Will recommit.

This reverts commit 4135abca89.
2022-07-12 12:17:29 +02:00
Pavel Labath 4135abca89 [lldb] add SBSection.alignment to python bindings
This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb.

Reviewed By: clayborg, JDevlieghere, labath

Differential Revision: https://reviews.llvm.org/D128069
2022-07-12 12:14:54 +02:00
Michael Buch 4d26faa526 [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type
This member variable was removed a while ago in
443427357f. It was previously used in
materialization code paths that have since been removed. Nowadays,
`m_object_pointer_type` gets set but not used anywhere.

This patch simply removes all remaining instances of it and any
supporting code.

**Testing**

* API tests pass

Differential Revision: https://reviews.llvm.org/D129367
2022-07-12 10:33:41 +01:00
Michael Buch d1e9d0b27f [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator
This patch adds a formatter for libcxx's `std::unordered_map` iterators.
The implementation follows a similar appraoch to the `std::map` iterator
formatter. I was hesistant about coupling the two into a common
implementation since the libcxx layouts might change for one of the
the containers but not the other.

All `std::unordered_map` iterators are covered with this patch:
1. const/non-const key/value iterators
2. const/non-const bucket iterators

Note that, we currently don't have a formatter for `std::unordered_map`.
This patch doesn't change that, we merely add support for its iterators,
because that's what Xcode users requested. One can still see contents
of `std::unordered_map`, whereas with iterators it's less ergonomic.

**Testing**

* Added API test

Differential Revision: https://reviews.llvm.org/D129364
2022-07-12 10:13:55 +01:00
Pavel Labath d4381153ea [lldb/libc++] Simplify the libc++ string formatter
Precise string layout has changed a lot recently, but a long of these
changes did not have any effect on the usages of its fields -- e.g.
introduction/removal of an anonymous struct or union does not change the
way one can access the field in C++. Our name-based variable lookup
rules (deliberately) copy the C++ semantics, which means these changes
would have been invisible to the them, if only we were using name-based
lookup.

This patch replaces the opaque child index accesses with name-based
lookups, which allows us to greatly simplify the data formatter code.
The formatter continues to support all the string layouts that it
previously supported.

It is unclear why the formatter was not using this approach from the
beginning. I would speculate that the original version was working
around some (now fixed) issue with anonymous members or base classes,
and the subsequent revisions stuck with that approach out of inertia.

Differential Revision: https://reviews.llvm.org/D129490
2022-07-12 09:57:13 +02:00
Raphael Isemann 9bc34636a5
[lldb] Add support for escaping fish arguments
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 list of special characters that need to be escaped
for fish. Without this patch on systems where fish is the user's shell
having any of these special characters in your arguments or path to
the binary will cause the process launch to fail. E.g., `lldb -- ./calc
1<2` is failing without this patch. The same happens if the absolute
path to calc is in a directory that contains for example parentheses
or other special characters.

Differential revision: https://reviews.llvm.org/D104635
2022-07-11 16:44:46 -07:00
Jonas Devlieghere 9097920eba
[lldb] Add a test to prefer exact triple matches in platform selection
Add a test that ensures we always prioritize exact triple matches when
creating platforms. This is a regression test for a (now resolved) bug
that that resulted in the remote tvOS platform being selected for a tvOS
simulator binary because the ArchSpecs are compatible.
2022-07-11 16:35:51 -07:00
Jonas Devlieghere ce233e7146
[lldb] Use the just-built libc++ for testing the LLDB data formatters
Make sure we use the libc++ from the build dir. Currently, by passing
-stdlib=libc++, we might pick up the system libc++. This change ensures
that if LLVM_LIBS_DIR is set, we try to use the libc++ from there.

Differential revision: https://reviews.llvm.org/D129166
2022-07-11 14:49:24 -07:00
Martin Storsjö 66cdd6548a [lldb] Reduce the stack alignment requirements for the Windows x86_64 ABI
This fixes https://github.com/llvm/llvm-project/issues/56095.

Differential Revision: https://reviews.llvm.org/D129455
2022-07-11 23:41:35 +03:00
spupyrev b444358126 Revert "Rebase: [Facebook] Add clang driver options to test debug info and BOLT"
This reverts commit f921985a29.
2022-07-11 09:50:46 -07:00
Amir Ayupov f921985a29 Rebase: [Facebook] Add clang driver options to test debug info and BOLT
Summary:
This is an essential piece of infrastructure for us to be
continuously testing debug info with BOLT. We can't only make changes
to a test repo because we need to change debuginfo tests to call BOLT,
hence, this diff needs to sit in our opensource repo. But when upstreaming
to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming,
we need to git diff and check all folders that are being modified by our
commits and discard this one (and leave as an internal diff).

To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON.
Then run check-lldb and check-debuginfo.

Manual rebase conflict history:
https://phabricator.intern.facebook.com/D29205224
https://phabricator.intern.facebook.com/D29564078
https://phabricator.intern.facebook.com/D33289118
https://phabricator.intern.facebook.com/D34957174

Test Plan:
tested locally
Configured with:
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests"
-DLLVM_TEST_BOLT=ON
Ran test suite with:
ninja check-debuginfo
ninja check-lldb

Reviewers: #llvm-bolt

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D35317341

Tasks: T92898286
2022-07-11 09:31:51 -07:00
Jonas Devlieghere 9302ff0951
Revert "jGetLoadedDynamicLibrariesInfos can inspect machos not yet loaded"
This reverts commit 77a38f6839 because (I
suspect) it breaks TestAppleSimulatorOSType.py on GreenDragon [1].

[1] https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45191/
2022-07-11 09:25:14 -07:00
Michał Górny 9790406a92 Reland "[lldb] [test] Improve stability of llgs vCont-threads tests"
Perform a major refactoring of vCont-threads tests in order to attempt
to improve their stability and performance.

Split test_vCont_run_subset_of_threads() into smaller test cases,
and split the whole suite into two files: one for signal-related tests,
the running-subset-of tests.

Eliminate output_match checks entirely, as they are fragile to
fragmentation of output.  Instead, for the initial thread list capture
raise an explicit SIGINT from inside the test program, and for
the remaining output let the test program run until exit, and check all
the captured output afterwards.

For resume tests, capture the LLDB's thread view before and after
starting new threads in order to determine the IDs corresponding
to subthreads rather than relying on program output for that.

Add a mutex for output to guarantee serialization.  A barrier is used
to guarantee that all threads start before SIGINT, and an atomic bool
is used to delay prints from happening until after SIGINT.

Call std::this_thread::yield() to reduce the risk of one of the threads
not being run.

This fixes the test hangs on FreeBSD.  Hopefully, it will also fix all
the flakiness on buildbots.

Thanks to Pavel Labath for figuring out why the original version did not
work on Debian.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D129012
2022-07-11 18:05:14 +02:00
Venkata Ramanaiah Nalamothu 419cc0a0b2 [lldb] Fix thread step until to not set breakpoint(s) on incorrect line numbers
The requirements for "thread until <line number>" are:

a) If any code contributed by <line number> or the nearest subsequent of <line number> is executed before leaving the function, stop
b) If you end up leaving the function w/o triggering (a), then stop

In case of (a), since the <line number> may have multiple entries in the line table and the compiler might have scheduled/moved the relevant code across, and the lldb does not know the control flow, set breakpoints on all the line table entries of best match of <line number> i.e. exact or the nearest subsequent line.

Along with the above, currently, CommandObjectThreadUntil is also setting the breakpoints on all the subsequent line numbers after the best match and this latter part is wrong.

This issue is discussed at http://lists.llvm.org/pipermail/lldb-dev/2018-August/013979.html.

In fact, currently `TestStepUntil.py` is not actually testing step until scenarios and `test_missing_one` test fails without this patch if tests are made to run. Fixed the test as well.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D50304
2022-07-11 18:45:37 +05:30
Pavel Labath fea52ac541 [lldb/test] Use SIGINT as the "stopping" signal
Using SIGSTOP means that if anything goes wrong in the test, the process
can end up in the stopped state, where it is not running, but still
taking up resources. Eventually, these "zombies" can make the machine
completely unusable. Instead, use a signal whose default action is to
kill the processes.
2022-07-11 08:42:17 +02:00
Dave Lee 4655400b21 [lldb] Delete more mydir references (NFC) 2022-07-10 18:56:06 -07:00
Jason Molenda 77a38f6839 jGetLoadedDynamicLibrariesInfos can inspect machos not yet loaded
jGetLoadedDynamicLibrariesInfos normally checks with dyld to find
the list of binaries loaded in the inferior, and getting the filepath,
before trying to parse the Mach-O binary in inferior memory.
This allows for debugserver to parse a Mach-O binary present in memory,
but not yet registered with dyld.  This patch also adds some simple
sanity checks that we're reading a Mach-O header before we begin
stepping through load commands, because we won't have the sanity check
of consulting dyld for the list of loaded binaries before parsing.
Also adds a testcase.

Differential Revision: https://reviews.llvm.org/D128956
rdar://95737734
2022-07-08 15:13:49 -07:00
Leonard Chan 474c873148 Revert "[llvm] cmake config groundwork to have ZSTD in LLVM"
This reverts commit f07caf20b9 which seems to break upstream https://lab.llvm.org/buildbot/#/builders/109/builds/42253.
2022-07-08 13:48:05 -07:00
Cole Kissane f07caf20b9 [llvm] cmake config groundwork to have ZSTD in LLVM
- added `FindZSTD.cmake`
- added a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- likewise added have_zstd to compiler-rt/test/lit.common.cfg.py, clang-tools-extra/clangd/test/lit.cfg.py, and several lit.site.cfg.py.in files mirroring have_zlib behavior

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-08 11:46:52 -07:00
Louis Dionne d2e86866be [libc++] Re-apply the use of ABI tags to provide per-TU insulation
This commit re-applies 9ee97ce3b8, which was reverted by 61d417ce
because it broke the LLDB data formatter tests. It also re-applies
6148c79a (the manual GN change associated to it).

Differential Revision: https://reviews.llvm.org/D127444
2022-07-08 08:38:36 -04:00
serge-sans-paille 132d711554 [lldb/test] Disable TestStringLiteralExpr.test on Windows
This test, introduced by b042d15d2e, fails on
https://lab.llvm.org/buildbot/#/builders/83/builds/20933/steps/7/logs/stdio

but succeeds on other targets, see for instance
https://lab.llvm.org/buildbot/#/builders/68/builds/35462/steps/6/logs/stdio

This test is not be arch specific, just disabling it on Windows.
2022-07-08 12:17:31 +02:00
Jesus Checa Hidalgo b042d15d2e [lldb/test] Add Shell/Expr/TestStringLiteralExpr.test
This test should exercise the usage of expressions containing
string literals and ensure that lldb doesn't crash.

Differential Revision: https://reviews.llvm.org/D129261
2022-07-08 10:01:07 +02:00
David Blaikie 72d9390778 Add a little extra test coverage for simple template names
This would fail with an overly naive approach to simple template
name (clang's -gsimple-template-names) since the names wouldn't be
unique per specialization, creating ambiguity/chance that a query for
one specialization would find another.
2022-07-08 00:12:29 +00:00
Jonas Devlieghere e4c5bca597
Revert "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."
This reverts commit 227dffd0b6 and its
follow up 562c3467a6 because it breaks a
bunch of tests on GreenDragon:

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45155/
2022-07-07 16:36:10 -07:00
Zequan Wu 562c3467a6 [LLDB] Fix aggregate-indirect-arg.cpp failure introduced by 227dffd0b6 2022-07-07 15:01:07 -07:00
David Blaikie b92c33495a Remove dead code: TypeMap::RemoveMismatchedTypes(TypeClass type_class) 2022-07-07 20:46:14 +00:00
David Blaikie 6edbde1001 Simplify some AsCString usage that was also explicitly handling default 2022-07-07 20:27:05 +00:00
David Blaikie 856ebe9e82 Retrieve as StringRef since that's how it'll be used 2022-07-07 20:13:36 +00:00
Augusto Noronha 5ade38c285 [lldb] Add comments to describe m_memory_addr and IsInMemory
Differential Revision: https://reviews.llvm.org/D129319
2022-07-07 13:11:50 -07:00
David Blaikie 65cac0ed92 Use StringRef to avoid unnecessary copies into std::strings 2022-07-07 19:50:12 +00:00
Zequan Wu 227dffd0b6 [LLDB][NFC] Decouple dwarf location table from DWARFExpression.
Differential Revision: https://reviews.llvm.org/D125509
2022-07-07 10:26:58 -07:00
Jonas Devlieghere ec48a0df91
[lldb] Improve the error message in run_to_breakpoint_do_run
Improve the error message when we fail to hit the initial breakpoint in
run_to_breakpoint_do_run. In addition to the process state, we now also
report the exit code and reason (if the process exited) as well as the
inferior's output.

Differential revision: https://reviews.llvm.org/D111978
2022-07-07 10:22:45 -07:00
David Spickett f3d43eca34 [lldb][Windows] Fixup overlapping memory regions tests
As suggested in post-commit review on https://reviews.llvm.org/D129272.

* Rename the test case.
* Simplify the overlap check.
* Correct assertion.
2022-07-07 15:36:14 +00:00
Pavel Labath d955185b94 [lldb/test] Use the shim executable for TestGdbRemoteAttach*Or*Wait as well
Without it, the test may nondeterminstically fail due to YAMA
restrictions.

Also, merge the two tests into one to reduce duplication.
2022-07-07 17:35:15 +02:00
Michał Górny fad93cd682 Revert "[lldb] [test] Improve stability of llgs vCont-threads tests"
This reverts commit 86e472317c.
It breaks Debian buildbot, for some reason.
2022-07-07 17:01:43 +02:00
Michał Górny 86e472317c [lldb] [test] Improve stability of llgs vCont-threads tests
Perform a major refactoring of vCont-threads tests in order to attempt
to improve their stability and performance.

Split test_vCont_run_subset_of_threads() into smaller test cases,
and split the whole suite into two files: one for signal-related tests,
the running-subset-of tests.

Eliminate output_match checks entirely, as they are fragile to
fragmentation of output.  Instead, for the initial thread list capture
raise an explicit SIGSTOP from inside the test program, and for
the remaining output let the test program run until exit, and check all
the captured output afterwards.

For resume tests, capture the LLDB's thread view before and after
starting new threads in order to determine the IDs corresponding
to subthreads rather than relying on program output for that.

Add a mutex for output to guarantee serialization.  A barrier is used
to guarantee that all threads start before SIGSTOP, and an atomic bool
is used to delay prints from happening until after SIGSTOP.

Call std::this_thread::yield() to reduce the risk of one of the threads
not being run.

This fixes the test hangs on FreeBSD.  Hopefully, it will also fix all
the flakiness on buildbots.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D129012
2022-07-07 16:33:55 +02:00
Pavel Labath 8262ff44c5 [lldb/test] Add a couple of libc++ std::string layouts
.. to the "string simulator" test. These layouts were used at some point in
the past few months, and are already supported by the code.
2022-07-07 16:20:20 +02:00
David Spickett 1ca8a97802 [lldb][Windows] Fix memory region base addresses when a range is split
Previously we recorded AllocationBase as the base address of the region
we get from VirtualQueryEx. However, this is the base of the allocation,
which can later be split into more regions.

So you got stuff like:
[0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header
[0x00007fff377c0000-0x00007fff37840000) r-x .text
[0x00007fff377c0000-0x00007fff37870000) r-- .rdata

Where all the base addresses were the same.

Instead, use BaseAddress as the base of the region. So we get:
[0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header
[0x00007fff377c1000-0x00007fff37840000) r-x .text
[0x00007fff37840000-0x00007fff37870000) r-- .rdata

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information

The added test checks for any overlapping regions which means
if we get the base or size wrong it'll fail. This logic
applies to any OS so the test isn't restricted to Windows.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D129272
2022-07-07 13:55:48 +00:00
Pavel Labath 11a09692ad [lldb] Fixup TestLoadAfterAttach for 82ba3f4
After 82ba3f4, we (again) need to call lldb_enable_attach to be able to
attach to processes on linux. This was a new test, so it does not have
the necessary boilerplate.
2022-07-07 15:06:40 +02:00
Pavel Labath 82ba3f4465 Recommit "[lldb/test] Don't use preexec_fn for launching inferiors"
This recommits b15b1421, which reverted in was reverted in f51c47d98 due to
failures on apple systems. The problem was that the patch introduced a race
where the debug server could start the attach process before the first process
(which isn't supposed to be attached to) was set up. This caused us to attach
to the wrong process.

The new version introduces additional synchronization to ensure that does not
happen.

Original commit message was:
As the documentation states, using this is not safe in multithreaded
programs, and I have traced it to a rare deadlock in some of the tests.

The reason this was introduced was to be able to attach to a program
from the very first instruction, where our usual mechanism of
synchronization -- waiting for a file to appear -- does not work.

However, this is only needed for a single test
(TestGdbRemoteAttachWait) so instead of doing this everywhere, I create
a bespoke solution for that single test. The solution basically
consists of outsourcing the preexec_fn code to a separate (and
single-threaded) shim process, which enables attaching and then executes
the real program.

This pattern could be generalized in case we needed to use it for other
tests, but I suspect that we will not be having many tests like this.

This effectively reverts commit
a997a1d7fb.
2022-07-07 14:38:33 +02:00
David Spickett e5fdcfac1b [lldb][AArch64] Use "+all" feature for the disassembler
The "+all" feature name was added in https://reviews.llvm.org/D128029.

This feature means we don't have to generate a list of features
or use a base architecture feature.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D129177
2022-07-06 12:15:01 +00:00
Martin Storsjö 4270c9cd44 [lldb] Stop passing both i386 and i686 in parallel as architectures on Windows
When an object file returns multiple architectures, it is treated
as a fat binary - which really isn't the case of i386 vs i686 where
the object file actually has one architecture.

This allows getting rid of hardcoded architecture triples in
PlatformWindows.

The parallel i386 and i686 architecture strings stem from
5e6f45201f / D7120 and
ad587ae4ca / D4658.

Differential Revision: https://reviews.llvm.org/D128617
2022-07-06 12:13:36 +03:00
Med Ismail Bennani ea8b811bf8 [lldb/Core] Fix finite progress event reporting
This patch should fix event handling for finite progress reports.

Previously, the event handler would get stuck when receiving a finite
progress report, and stop displaying upcoming reports.
This was due to the fact that we were checking if the progress event was
completed by calling `GetCompleted` but returns the completion amount
instead of saying whether it's completed.

That caused the current event id to remain the same, preventing all the
following progress reports to be shown to the user.

This patch also adds some logging to facilitate debugging progress events.

rdar://91788326

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-07-05 16:25:40 -07:00
Muhammad Omair Javaid bb9b30ffbe [LLDB] Remove TestLoadUnload.py Arm/Linux Xfail decorator
This is a follow up on my last commit where one of the decorator was
left unremoved.

This patch removes Xfail decorator from TestLoadUnload.py as it is now
passing on Arm/Linux buildbot.
2022-07-06 01:39:52 +04:00
Muhammad Omair Javaid 5cca2ef3c3 [LLDB] Remove TestLoadUnload.py Arm/Linux Xfail decorator
This patch removes Xfail decorator from TestLoadUnload.py as it is now
passing on Arm/Linux buildbot.
2022-07-06 01:14:40 +04:00
Jonas Devlieghere f51c47d987
Revert "[lldb/test] Don't use preexec_fn for launching inferiors"
This reverts commit b15b1421bc because it
breaks GreenDragon [1]. The bot has been red for several days, so
reverting to green while I take a look.

[1] https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45012/
2022-07-05 10:12:57 -07:00
Muhammad Omair Javaid b7b11091ef [LLDB] Fix decorator import in TestTwoHitsOneActual.py 2022-07-05 15:26:26 +04:00
Muhammad Omair Javaid 3b2496e8fa [LLDB] Skip TestTwoHitsOneActual.py on Arm/AArch64 Linux
This test has some race condition which is making it hang on LLDB
Arm/AArch64 Linux buildbot. I am marking it as skipped until we
investigate whats going wrong.
2022-07-05 15:01:51 +04:00
Muhammad Omair Javaid ba14e4d65c [LLDB] Disable TestGdbRemoteFork* for Arm/AArch64 Linux
This test is causing some trouble with LLDB Arm/AArch64 Linux buildbot.
I am disabling is temporarily to make buildbot green.
2022-07-05 13:45:26 +04:00
Kaining Zhong dc46ae6df5 [lldb] Add support to load object files from thin archives
This fixes https://github.com/llvm/llvm-project/issues/50114 where lldb/mac
can't load object files from thin archives.  This patch allows lldb to identify
thin archives, and load object files contained in them.

Differential Revision: https://reviews.llvm.org/D126464
2022-07-05 10:52:26 +02:00
Pavel Labath b15b1421bc [lldb/test] Don't use preexec_fn for launching inferiors
As the documentation states, using this is not safe in multithreaded
programs, and I have traced it to a rare deadlock in some of the tests.

The reason this was introduced was to be able to attach to a program
from the very first instruction, where our usual mechanism of
synchronization -- waiting for a file to appear -- does not work.

However, this is only needed for a single test
(TestGdbRemoteAttachWait) so instead of doing this everywhere, I create
a bespoke solution for that single test. The solution basically
consists of outsourcing the preexec_fn code to a separate (and
single-threaded) shim process, which enables attaching and then executes
the real program.

This pattern could be generalized in case we needed to use it for other
tests, but I suspect that we will not be having many tests like this.

This effectively reverts commit
a997a1d7fb.
2022-07-01 14:36:01 +02:00
Muhammad Omair Javaid 3d477bbeee [LLDB] Xfail TestStepNoDebug.py AArch64/Windows
LLDB fails to step in/out/over code with missing debug information.
This is only reproducible on AArch64/Windows. I have reported a issue
upstream at llvm.org/pr56292

This patch Xfail TestStepNoDebug.py for AArch64/Windows.
2022-07-01 12:25:43 +04:00
Pavel Labath b6b65403b3 [lldb] Add tests which simulate the various std::string layouts
Checking whether a formatter change does not break some of the supported
string layouts is difficult because it requires tracking down and/or
building different versions and build configurations of the library.

The purpose of this patch is to avoid that by providing an in-tree
simulation of the string class. It is a reduced version of the real
string class, obtained by elimitating all non-trivial code, leaving
just the internal data structures used by the data formatter. Different
versions of the class can be simulated through preprocessor defines.

The test (ab)uses the fact that our formatters kick in for any
double-underscore sub-namespace of `std`, so it avoids colliding with
the real string class by declaring the test class in the std::__lldb
namespace.

I do not consider this to be a replacement for the existing data
formatter tests, as producing this kind of a test is not trivial, and it
is easy to make a mistake in the process. However, it's also not
realistic to expect that every person changing the data formatter will
test it against all versions of the real class, so I think it can be
useful as a first line of defence.

Adding support for new layouts can become particularly unwieldy, but
this complexity will also be reflected in the actual code, so if we find
ourselves needing to support too many variants, we may need to start
dropping support for old ones, or come up with a completely different
strategy.

Differential Revision: https://reviews.llvm.org/D124155
2022-07-01 08:08:22 +02:00
Pavel Labath 553558292e [lldb/dyld-posix] Avoid reading the module list in inconsistent states
New glibc versions (since 2.34 or including this
<ed3ce71f5c>
patch) trigger the rendezvous breakpoint after they have already added
some modules to the list. This did not play well with our dynamic
loader plugin which was doing a diff of the the reported modules in the
before (RT_ADD) and after (RT_CONSISTENT) states. Specifically, it
caused us to miss some of the modules.

While I think the old behavior makes more sense, I don't think that lldb
is doing the right thing either, as the documentation states that we
should not be expecting a consistent view in the RT_ADD (and RT_DELETE)
states.

Therefore, this patch changes the lldb algorithm to compare the module
list against the previous consistent snapshot. This fixes the previous
issue, and I believe it is more correct in general. It also reduces the
number of times we are fetching the module info, which should speed up
the debugging of processes with many shared libraries.

The change in RefreshModules ensures we don't broadcast the loaded
notification for the dynamic loader (ld.so) module more than once.

Differential Revision: https://reviews.llvm.org/D128264
2022-07-01 08:08:22 +02:00
Emre Kultursay c0702ac07b [PATCH] [lldb-server] Skip shared regions for memory allocation
Differential Revision: https://reviews.llvm.org/D128832
2022-07-01 13:45:42 +08:00
Zequan Wu 8a790e65f4 [LLDB][NativePDB] Return LLDB_INVALID_ADDRESS in PdbIndex::MakeVirtualAddress when input is invalid due to missing address info in symbol/public records. 2022-06-30 14:34:20 -07:00
Jim Ingham 38ca754eb0 Apparently you need a special makefile flag to use threads on Linux.
This is a follow-up to https://reviews.llvm.org/D128776.
2022-06-30 12:10:17 -07:00
Jim Ingham b8e0b5a071 Threads which hit a breakpoint but fail the condition are considered
not to be hit.  But another thread might be hit at the same time and
actually stop.  So we have to be sure to switch the first thread's
stop info to eStopReasonNone or we'll report a hit when the condition
failed, which is confusing.

Differential Revision: https://reviews.llvm.org/D128776
2022-06-30 11:43:59 -07:00
Jonas Devlieghere 3a56858cee
[lldb] XFAIL TestObjCXXBridgedPO on macOS Ventura
TestObjCXXBridgedPO is broken on macOS Ventura (but not on macOS
Monterey). I took a look but it doesn't seem trivial. I'm XFAILing the
test until Adrian, who wrote the test, can take a look.

rdar://96224141
2022-06-30 09:20:56 -07:00
Pavel Labath cff509f33b [lldb] Fix libc++ string formatter for the "unstable" layout
D128285 only changed the stable (v1) layout, so the matching change in
D128694 broke the formatting of the unstable strings. This fixes that,
and ensures compatibility with all older layouts as well.
2022-06-30 16:44:54 +02:00
Muhammad Omair Javaid 8e9360db1b Fix PDB/func-symbols.test for Arm/Windows
PDB/func-symbols.test was orignally written for 32bit x86, keeping in
mind cdecl and stdcall calling conventions which does name mangling for
example like adding "_" underscore before function name.
This is only x86 specific but purpose of pointers.test is NOT to test
calling convention.
I have made a minor change to make this test pass on Windows/Arm.
2022-06-30 17:58:19 +04:00
Muhammad Omair Javaid dd01d9aadb Fix TestCommandScript.py for Arm/Windows
TestCommandScript.py fails on Arm/Windows due following issues:
https://llvm.org/pr56288
https://llvm.org/pr56292

LLDB fails to skip prologue and also step over library function or
nodebug functions fails due to PDB/DWARF mismatch.

This patch replace function breakpoint with line breakpoint so that we
can expect LLDB to stop on desired line. Also replace dwarf with PDB
debug info for this test only.
2022-06-30 17:48:28 +04:00
Muhammad Omair Javaid 8b7f5ee5f0 [LLDB] Fix TestSTL.py Makefile to remove -gdwarf O0
This is a follow up to my previous commit where TestSTL.py got broken
due to 9c6e043592.
Now that we force dwarf symbols by default on windows we dont need to
specifically put -gdwarf O0 in debug flags for this test.
2022-06-30 14:06:21 +04:00
Muhammad Omair Javaid 5fe0da6d7b [LLDB] Fix TestSTL.py on Windows
TestSTL.py was broken by 9c6e043592.
This patch fixes it with changes to its Makefile.
2022-06-30 13:27:14 +04:00
Fangrui Song 67854f9ed0 Use value_or instead of getValueOr. NFC 2022-06-29 21:55:02 -07:00
Kevin Cadieux a3ec54c660 [lldb] Fix unused variable warning in TraceHTR (NFC)
A warning was recently introduced in [D128576](https://reviews.llvm.org/D128576) due to now unused lambda `function_name_from_load_address`. This warning causes build failures when treating warnings as errors. This change expands the comment to also include the definition of this lambda, fixing the warning.

Error:
```
[3809/6000] Building CXX object tools/lldb/source/Plugins/TraceExporter/common/CMakeFiles/lldbPluginTraceExporterCommon.dir/TraceHTR.cpp.o
FAILED: tools/lldb/source/Plugins/TraceExporter/common/CMakeFiles/lldbPluginTraceExporterCommon.dir/TraceHTR.cpp.o
/usr/bin/clang++ -DHAVE_ROUND -DLLDB_CONFIGURATION_DEBUG -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/__w/1/b/llvm/Debug/tools/lldb/source/Plugins/TraceExporter/common -I/__w/1/llvm-project/lldb/source/Plugins/TraceExporter/common -I/__w/1/llvm-project/lldb/include -I/__w/1/b/llvm/Debug/tools/lldb/include -I/__w/1/b/llvm/Debug/include -I/__w/1/llvm-project/llvm/include -I/__w/1/llvm-project/llvm/../clang/include -I/__w/1/b/llvm/Debug/tools/lldb/../clang/include -I/__w/1/llvm-project/lldb/source -I/__w/1/b/llvm/Debug/tools/lldb/source -isystem /usr/include/libxml2 -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -g  -fno-exceptions -gsplit-dwarf -std=c++14 -MD -MT tools/lldb/source/Plugins/TraceExporter/common/CMakeFiles/lldbPluginTraceExporterCommon.dir/TraceHTR.cpp.o -MF tools/lldb/source/Plugins/TraceExporter/common/CMakeFiles/lldbPluginTraceExporterCommon.dir/TraceHTR.cpp.o.d -o tools/lldb/source/Plugins/TraceExporter/common/CMakeFiles/lldbPluginTraceExporterCommon.dir/TraceHTR.cpp.o -c /__w/1/llvm-project/lldb/source/Plugins/TraceExporter/common/TraceHTR.cpp
/__w/1/llvm-project/lldb/source/Plugins/TraceExporter/common/TraceHTR.cpp:136:8: error: unused variable 'function_name_from_load_address' [-Werror,-Wunused-variable]
  auto function_name_from_load_address =
```

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D128874
2022-06-29 21:29:50 -07:00
Zequan Wu bd2044c108 [CodeView] Call llvm::codeview::visitMemberRecordStream with the deserialized CVType whose kind is FieldListRecord.
llvm::codeview::visitMemberRecordStream expects to receive an array ref that's FieldListRecord's Data not a CVType's data which has 4 more bytes preceeding. The first 2 bytes indicate the size of the FieldListRecord, and following 2 bytes is always 0x1203. Inside llvm::codeview::visitMemberRecordStream, it iterates to the data to check if first two bytes matching some type record kinds. If the size coincidentally matches one type kind, it will start parsing from there and causing crash.
2022-06-29 17:18:56 -07:00
Jonas Devlieghere 1b8c73522e
[lldb] Use assertState in even more tests (NFC)
Followup to D127355 and D127378, converting more instances of
assertEqual to assertState.
2022-06-29 17:05:58 -07:00
Jonas Devlieghere dee672ee85
[lldb] Skip instead of XFAIL TestGdbRemote_vContThreads on Darwin
The two XFAILed tests started timing out after D126983. Given that they
were XFAILed anyway I didn't investigate and just skipped them.
2022-06-29 16:34:34 -07:00
Jonas Devlieghere 3944780dd8
[lldb] Skip TestAppleSimulatorOSType is simulator isn't available
Skip TestAppleSimulatorOSType is simulator isn't available for the given
platform.
2022-06-29 15:10:16 -07:00
Jonas Devlieghere 65a7ebff33
[lldb] XFAIL TestVSCode_breakpointEvents.py on Ventura
TestVSCode_breakpointEvents.py is failing on macOS Ventura because we
receive 3 breakpoint events instead of one. This is likely the result of
dyld moving into the shared cache.
2022-06-29 15:00:57 -07:00
Muhammad Omair Javaid 9c6e043592 [LLDB] Allow API tests to override -gdwarf on Windows
This patch fixes LLDB API tests MakeFile.rules to allow overriding of
debug symbol flags when compiling tests for Windows.
Previously windows tests were forced to emit only dwarf debug symbols
as majority of the tests rely on dwarf debug info. After this patch
any test can override debug symbol flag by setting DEBUG_INFO_FLAG
variable in its make file.
2022-06-29 23:24:18 +04:00
Muhammad Omair Javaid f5ba0a3d05 Fix inline-record.test for Arm/Windows
This patch fixes inline-record.test to run on multiple platforms
including Arm/Windows. Test is fixed to expect any value for id
fields of functions and blocks returned by 'image lookup' command.
This field can be any value as it is internally generated id.
2022-06-29 23:21:02 +04:00
Pavel Labath 079c8ccb33 [lldb] Attempt to fix TestStepThroughTrampoline on windows 2022-06-29 19:59:24 +02:00
Walter Erquinigo a7d6c3effe [trace] Make events first class items in the trace cursor and rework errors
We want to include events with metadata, like context switches, and this
requires the API to handle events with payloads (e.g. information about
such context switches). Besides this, we want to support multiple
similar events between two consecutive instructions, like multiple
context switches. However, the current implementation is not good for this because
we are defining events as bitmask enums associated with specific
instructions. Thus, we need to decouple instructions from events and
make events actual items in the trace, just like instructions and
errors.

- Add accessors in the TraceCursor to know if an item is an event or not
- Modify from the TraceDumper all the way to DecodedThread to support
- Renamed the paused event to disabled.
- Improved the tsc handling logic. I was using an API for getting the tsc from libipt, but that was an overkill that should be used when not processing events manually, but as we are already processing events, we can more easily get the tscs.
event items. Fortunately this simplified many things
- As part of this refactor, I also fixed and long stating issue, which is that some non decoding errors were being inserted in the decoded thread. I changed this so that TraceIntelPT::Decode returns an error if the decoder couldn't be set up proplerly. Then, errors within a trace are actual anomalies found in between instrutions.

All test pass

Differential Revision: https://reviews.llvm.org/D128576
2022-06-29 09:19:51 -07:00
Michał Górny 4a95861d73 [lldb] [test] Avoid relying on signos in other fork tests
Sponsored by: The FreeBSD Foundation
2022-06-29 17:48:36 +02:00
Michał Górny e60ed2401b [lldb] [test] Un-XFAIL fork tests on arm as well
Sponsored by: The FreeBSD Foundation
2022-06-29 16:05:12 +02:00
Michał Górny 251165b2e4 [lldb] [test] Use raise(SIGSTOP) instead of trap in fork tests
Replace the use of "trap" with a new "stop" command in fork tests,
that maps to `raise(SIGSTOP)`.  Since traps do not increment PC on some
architectures (notably ARM), using traps would require special logic
to increment it while testing.  Using SIGSTOP avoids the problem
and is probably more logical, given that the purpose of the "trap"s
was to simply stop the inferior at a synchronization point.  This fixes
tests on AArch64 (and possibly ARM, I'll update XFAILs when it is
confirmed by the buildbot).

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128780
2022-06-29 15:37:26 +02:00
Pavel Labath 5e39198570 [lldb] Replace linux/uio.h with sys/uio.h in NativeRegisterContextLinux_s390x
Fixes PR56280.
2022-06-29 14:50:06 +02:00
Michał Górny 3c16fb3ab3 [lldb] [test] Fix variable overwrite in non-stop fork tests
Thanks to Pavel Labath for noticing the mistake in:
https://reviews.llvm.org/D128638#3618039

Sponsored by: The FreeBSD Foundation
2022-06-29 13:34:50 +02:00
Michael Daniels d8ad018869 [lldb] fix stepping through POSIX trampolines
The DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan() function was
doing the symbol lookup using the demangled name. This stopped working
with https://reviews.llvm.org/D118814. To get things working again, just
use the mangled name for the lookup instead.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D127999
2022-06-29 11:06:29 +02:00
Muhammad Omair Javaid 01bc838e45 [LLDB] Add PDB/calling-conventions.test for Arm/Windows
This patch renames PDB/calling-conventions.test to calling-conventions-x86.test.
Also restrict it to run only for target-x86*.
This patch also adds a arm specific test PDB/calling-conventions-arm.test which
tests that x86 specifc calling convention decorators are ignored by Arm compiler.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D128678
2022-06-29 12:58:16 +04:00
Muhammad Omair Javaid a18baf16c6 [LLDB] Add Arm64 CodeView to LLDB regnum mapping
This patch writes a mapping structure for converting  CodeView Arm64 register numbers to LLDB Arm64 regnums.

This fixes various symbols and variable location test failures on AArch64/Windows.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D128221
2022-06-29 12:50:57 +04:00
Muhammad Omair Javaid 695c22c84a [LLDB] Fix PDB/pointers.test for 32bit Arm/Windows
PDB/pointers.test was orignally written for 32bit x86 keeping in mind
__cdecl and __stdcall calling conventions which does name mangling for
example like adding "_" underscore before function name.
This is only x86 specific but purpose of pointers.test is NOT to test
calling convention.
I am have made a few minor changes to this test which will make it pass
when run on Windows/Arm platform.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D128668
2022-06-29 12:47:02 +04:00
Michał Górny 7fc12da898 [lldb] [test] Split TestGdbRemoteFork in two
Split the test that's gotten very long in two, in hope that it will
resolve the arm/aarch64 buildbot failures.  Even if it does not, it
could help pinpointing where the problem lies.

Sponsored by: The FreeBSD Foundation
2022-06-29 06:57:38 +02:00
Walter Erquinigo 6564ca188a [trace] Fix errors when handling command arguments
https://reviews.llvm.org/D128453 recently added some safety checks for
command arguments. Unfortunately, some few commands started failing due
to that, and this diff fixes it. But fortunately, the fix is trivial, which is
simply declaring the argument that these commands will receive.

Differential Revision: https://reviews.llvm.org/D128775
2022-06-28 17:54:30 -07:00
Walter Erquinigo f91d82816f [trace] Improve the TraceCursor iteration API
The current way ot traversing the cursor is a bit uncommon and it can't handle empty traces, in fact, its invariant is that it shold always point to a valid item. This diff simplifies the cursor API and allows it to point to invalid items, thus being able to handle empty traces or to know it ran out of data.

- Removed all the granularity functionalities, because we are not actually making use of that. We can bring them back when they are actually needed.
- change the looping logic to the following:

```
  for (; cursor->HasValue(); cursor->Next()) {
     if (cursor->IsError()) {
       .. do something for error
       continue;
     }
     .. do something for instruction
  }

```

- added a HasValue method that can be used to identify if the cursor ran out of data, the trace is empty, or the user tried to move to an invalid position via SetId() or Seek()
- made several simplifications to severals parts of the code.

Differential Revision: https://reviews.llvm.org/D128543
2022-06-28 16:50:12 -07:00
Med Ismail Bennani 44a114fec7 [lldb/Dataformatters] Adapt C++ std::string dataformatter for D128285
This patch changes the C++ `std::string` dataformatter to reflect
internal layout changes following D128285.

Now, in short-mode strings, in order to access the `__size_` and
`__is_long_` attributes, we need to access a packed anonymous struct,
which introduces another indirection.

We need to do the same in order to access the `__cap_` field for
long-mode strings.

This should fix the various test failures that are happening on
GreenDragon:

https://green.lab.llvm.org/green/job/lldb-cmake/44918/

rdar://96010248

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-06-28 15:34:17 -07:00
Michał Górny 261d003350 [lldb] [llgs] Fix premature server exit if multiprocess+nonstop
Fix lldb-server in the non-stop + multiprocess mode to exit on vStopped
only if all processes have exited, rather than when the first one exits.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128639
2022-06-28 21:49:17 +02:00
Michał Górny b415f8e3df [lldb] [llgs] Add base nonstop fork/vfork tests
Extend the most of baseline fork tests to run in nonstop mode as well.
For more cases, we're just testing one example scenario to save time.
This patch does not cover tests that rely on correct exit handling,
as fixing that is addressed in a followup patch.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128638
2022-06-28 21:49:16 +02:00
Michał Górny e095cddb76 [lldb] Add a NativeProcessProtocol::Threads() iterable
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128698
2022-06-28 21:49:16 +02:00
Jim Ingham f7bf9d13d5 TestIgnoredExceptions.py needs support from debugserver, so it
needs to be marked skip if out of tree debugserver.
2022-06-28 11:49:55 -07:00
Michał Górny 25f46084d8 [lldb] [test] XFAIL llgs tests failing on arm
Sponsored by: The FreeBSD Foundation
2022-06-28 17:02:59 +02:00
Michał Górny a1df636a8b [lldb] [test] Skip llgs tests broken due to #56268 on aarch64
Sponsored by: The FreeBSD Foundation
2022-06-28 16:24:38 +02:00
Yi Kong b83b82f9f4 [lldb] Fix build on older Linux kernel versions
PERF_COUNT_SW_DUMMY is introduced in Linux 3.12.

Differential Revision: https://reviews.llvm.org/D128707
2022-06-28 20:23:33 +08:00
Michał Górny f1dcc6af30 [lldb] [test] Mark test_vCont_supports_t llgs-only
Sponsored by: The FreeBSD Foundation
2022-06-28 06:06:54 +02:00
Jonas Devlieghere e06a88cbe9
[lldb] Use assertState in TestIgnoredExceptions 2022-06-27 16:30:47 -07:00
Jim Ingham c1b07d6177 Have CommandObjectParsed check for "commands that take no arguments".
This is currently being done in an ad hoc way, and so for some
commands it isn't being checked.  We have the info to make this check,
since commands are supposed to add their arguments to the m_arguments
field of the CommandObject.  This change uses that info to check whether
the command received arguments in error.

A handful of commands weren't defining their argument types, I also had
to fix them.  And a bunch of commands were checking for arguments by
hand, so I removed those checks in favor of the CommandObject one.  That
also meant I had to change some tests that were checking for the ad hoc
error outputs.

Differential Revision: https://reviews.llvm.org/D128453
2022-06-27 15:14:41 -07:00
Alex Langford ef5510d81b [NFC][lldb] Correct Module::FindFunctions documentation
Looks like a copy/paste from ModuleList::FindCompileUnits.
2022-06-27 12:33:05 -07:00
Jonas Devlieghere 9bdb7e5734
[lldb] Add a log dump command
Add a log dump command to dump logs to a file. This only works for
channels that have a log handler associated that supports dumping. For
now that's limited to the circular log handler, but more could be added
in the future.

Differential revision: https://reviews.llvm.org/D128557
2022-06-27 10:02:34 -07:00
Michał Górny fe80829289 [lldb] [llgs] Skip new vCont test on Windows
Sponsored by: The FreeBSD Foundation
2022-06-27 18:22:38 +02:00
Michał Górny b4f2d7cde5 [lldb] [llgs] Support "t" vCont action
Implement support for the "t" action that is used to stop a thread.
Normally this action is used only in non-stop mode.  However, there's
no technical reason why it couldn't be also used in all-stop mode,
e.g. to express "resume all threads except ..." (`t:...;c`).

While at it, add a more complete test for vCont correctly resuming
a subset of program's threads.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D126983
2022-06-27 17:33:59 +02:00
Mikhail Goncharov fe6db8d03f Revert "[lldb] Fix thread step until to not set breakpoint(s) on incorrect line numbers"
This reverts commit a57b62deef.

lldb-aarch64-ubuntu buildbot test fails since https://lab.llvm.org/buildbot/#/builders/96/builds/25128
2022-06-27 10:18:39 +02:00
Kazu Hirata 96d1b4ddb2 [lld] Don't use Optional::hasValue (NFC)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.
2022-06-26 19:29:40 -07:00
Kazu Hirata 3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3.
2022-06-25 11:56:50 -07:00
Kazu Hirata aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Michał Górny 1452e2e5cb Reland "[lldb] [llgs] Support multiprocess in qfThreadInfo"
Now preserving the non-standard behavior of returning "OK" response
when there is no debugged process.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128152
2022-06-25 15:15:37 +02:00
Michał Górny f609b54e24 Revert "[lldb] [llgs] Support multiprocess in qfThreadInfo"
This reverts part of commit 75757c86c6.
It broke the following test:

  commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py

I need more time to figure it out, so I'm reverting the code changes
and marking the tests depending on them xfail.
2022-06-25 09:46:28 +02:00
Jonas Devlieghere be265d25ca
[lldb] Add support for specifying a log handler
This patch adds a new flag to `log enable`, allowing the user to specify
a custom log handler. In addition to the default (stream) handler, this
allows using the circular log handler (which logs to a fixed size,
in-memory circular buffer) as well as the system log handler (which logs
to the operating system log).

Differential revision: https://reviews.llvm.org/D128323
2022-06-24 18:24:00 -07:00
Venkata Ramanaiah Nalamothu a57b62deef [lldb] Fix thread step until to not set breakpoint(s) on incorrect line numbers
The requirements for "thread until <line number>" are:

a) If any code contributed by <line number> or the nearest subsequent of <line number> is executed before leaving the function, stop
b) If you end up leaving the function w/o triggering (a), then stop

In case of (a), since the <line number> may have multiple entries in the line table and the compiler might have scheduled/moved the relevant code across, and the lldb does not know the control flow, set breakpoints on all the line table entries of best match of <line number> i.e. exact or the nearest subsequent line.

Along with the above, currently, CommandObjectThreadUntil is also setting the breakpoints on all the subsequent line numbers after the best match and this latter part is wrong.

This issue is discussed at http://lists.llvm.org/pipermail/lldb-dev/2018-August/013979.html.

In fact, currently `TestStepUntil.py` is not actually testing step until scenarios and `test_missing_one` test fails without this patch if tests are made to run. Fixed the test as well.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D50304
2022-06-25 00:01:04 +05:30
Jonas Devlieghere 87a3293961
[lldb] Move Host::SystemLog out of !defined(_WIN32)
The definition of Host::SystemLog was (unintentionally) guarded by
!defined(_WIN32).
2022-06-24 11:18:31 -07:00
Jonas Devlieghere 5a08280659
[lldb] Fix flakiness in shell tests that mixed stderr and stdout
Because the diagnostic events are processed by the default event handler
in its own thread, tests cannot rely on output ordering. Split stdout
and stderr to make the test reliable again.
2022-06-24 10:53:15 -07:00
Jonas Devlieghere 1e5d5261e2
[lldb] Add SystemLogHandler for emitting log messages to the system log
Add a system log handler that emits log messages to the operating system
log. In addition to the log handler itself, this patch also introduces a
new Host::SystemLog helper function to abstract over writing to the
system log.

Differential revision: https://reviews.llvm.org/D128321
2022-06-24 10:53:15 -07:00
Jonas Devlieghere 6879391908
[lldb] Replace Host::SystemLog with Debugger::Report{Error,Warning}
As it exists today, Host::SystemLog is used exclusively for error
reporting. With the introduction of diagnostic events, we have a better
way of reporting those. Instead of printing directly to stderr, these
messages now get printed to the debugger's error stream (when using the
default event handler). Alternatively, if someone is listening for these
events, they can decide how to display them, for example in the context
of an IDE such as Xcode.

This change also means we no longer write these messages to the system
log on Darwin. As far as I know, nobody is relying on this, but I think
this is something we could add to the diagnostic event mechanism.

Differential revision: https://reviews.llvm.org/D128480
2022-06-24 09:46:26 -07:00
Walter Erquinigo b8dcd0ba26 [NFC][lldb][trace] Rename trace session to trace bundle
As previously discussed with @jj10306, we didn't really have a name for
the post-mortem (or offline) trace session representation, which is in
fact a folder with a bunch of files. We decided to call this folder
"trace bundle", and the main JSON file in it "trace bundle description
file". This naming is pretty decent, so I'm refactoring all the existing
code to account for that.

Differential Revision: https://reviews.llvm.org/D128484
2022-06-24 08:41:33 -07:00
Michał Górny c1829e0ec5 [lldb] [test] Move part of fork tests to common helper
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128361
2022-06-24 17:20:25 +02:00
Michał Górny 4b485fc0ea [lldb] [llgs] Introduce an AppendThreadIDToResponse() helper
Introduce a helper function to append GDB Remote Serial Protocol "thread
IDs", with optional PID in multiprocess mode.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128324
2022-06-24 17:20:24 +02:00
Michał Górny e827e5186f [lldb] [llgs] Implement the 'T' packet
Implement the 'T' packet that is used to verify whether the specified
thread belongs to the debugged processes.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128170
2022-06-24 17:20:24 +02:00
Michał Górny 630da0e309 [lldb] [llgs] Include PID in QC response in multiprocess mode
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128156
2022-06-24 17:20:24 +02:00
Michał Górny 14d6707335 [lldb] [llgs] Add a test for multiprocess register read/write
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128153
2022-06-24 17:20:24 +02:00
Michał Górny 75757c86c6 [lldb] [llgs] Support multiprocess in qfThreadInfo
Update the `qfThreadInfo` handler to report threads of all debugged
processes and include PIDs when in multiprocess mode.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128152
2022-06-24 17:20:24 +02:00
Michał Górny 0481d8efa9 [lldb] [llgs] Add a test for multiprocess memory read/write
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128150
2022-06-24 17:20:24 +02:00
Michał Górny a3422793e0 [lldb] [llgs] Support resuming one process with PID!=current via vCont
Extend vCont function to support resuming a process with an arbitrary
PID, that could be different than the one selected via Hc (or no process
at all may be selected).  Resuming more than one process simultaneously
is not supported yet.

Remove the ReadTid() method that was only used by Handle_vCont(),
and furthermore it was wrongly using m_current_process rather than
m_continue_process.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127862
2022-06-24 17:20:23 +02:00
Michał Górny 3266b11714 [lldb] [llgs] Add test for resuming via c in multiprocess scenarios
Add a test verifying that it is possible to resume a single process
via the `c` packet when multiple processes are being debugged.  This
includes a tiny change to the test program — when `fork()` is called,
the child process is no longer terminated immediately but continues
performing the same tasks as queued for the parent.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127755
2022-06-24 17:20:23 +02:00
Michał Górny c18784ba33 [lldb] [llgs] Implement the vKill packet
Implement the support for the vKill packet.  This is the modern packet
used by the GDB Remote Serial Protocol to kill one of the debugged
processes.  Unlike the `k` packet, it has well-defined semantics.

The `vKill` packet takes the PID of the process to kill, and always
replies with an `OK` reply (rather than the exit status, as LLGS does
for `k` packets at the moment).  Additionally, unlike the `k` packet
it does not cause the connection to be terminated once the last process
is killed — the client needs to close it explicitly.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127667
2022-06-24 17:20:23 +02:00
Michał Górny e8fe7e930a [lldb] [llgs] Make `k` kill all processes, and fix multiple exits
Modify the behavior of the `k` packet to kill all inferiors rather than
just the current one.  The specification leaves the exact behavior
of this packet up to the implementation but since vKill is specifically
meant to be used to kill a single process, it seems logical to use `k`
to provide the alternate function of killing all of them.

Move starting stdio forwarding from the "running" response
to the packet handlers that trigger the process to start.  This avoids
attempting to start it multiple times when multiple processes are killed
on Linux which implicitly causes LLGS to receive "started" events
for all of them.  This is probably also more correct as the ability
to send "O" packets is implied by the continue-like command being issued
(and therefore the client waiting for responses) rather than the start
notification.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127500
2022-06-24 17:20:23 +02:00
Muhammad Omair Javaid 91d61c1431 [LLDB] Mark TestExprsChar Xfail for Windows/AArch64
test_unsigned_char test in TestExprsChar.py fails on AArch64/Windows
platform. There is known bug already present for the failure for various
arch/os combinations. This patch marks the test as xfail for
windows/AArch64.
2022-06-24 13:59:22 +04:00
Jonas Devlieghere 6fa9120080
[lldb] Fix up Objective-C ISA pointers
Support stripping the PAC bits from Objective-C ISA pointers in the
Objective-C runtime plugin.
2022-06-23 14:16:29 -07:00
Chelsea Cassanova 40aace59cc [lldb/Fuzzer] Have fuzzers write artifacts to specific directory
This makes the LLDB fuzzers write their fuzzer artifacts to
their own directory in the build directory. It also adds an artifact
prefix to the target fuzzer to make it easier to tell which fuzzer
wrote the artifact.

Differential revision: https://reviews.llvm.org/D128450
2022-06-23 16:55:23 -04:00
Jim Ingham a1f20da315 The help string for stop-on-shared-library-load was copied to stop-on-exec.
Fix it so it says it does what it does.
2022-06-23 13:54:50 -07:00
Jonas Devlieghere 70841b97eb
[lldb] Make thread safety the responsibility of the log handlers
Drop the thread-safe flag and make the locking strategy the
responsibility of the individual log handler.

Previously we got away with a non-thread safe mode because we were using
unbuffered streams that rely on the underlying syscalls/OS for
synchronization. With the introduction of log handlers, we can have
arbitrary logic involved in writing out the logs. With this patch the
log handlers can pick the most appropriate locking strategy for their
particular implementation.

Differential revision: https://reviews.llvm.org/D127922
2022-06-23 09:12:05 -07:00
Jonas Devlieghere 09dea54669
[lldb] Support a buffered logging mode
This patch adds a buffered logging mode to lldb. A buffer size can be
passed to `log enable` with the -b flag. If no buffer size is specified,
logging is unbuffered.

Differential revision: https://reviews.llvm.org/D127986
2022-06-23 09:12:01 -07:00
David Spickett 5e7ddb0ddf Revert "[LLDB] Handle DIE with DW_AT_low_pc and empty ranges"
This reverts commit 1beededc0e7d86d09cee972f0b9f0030a139cab4.

Due to failures on the Arm/AArch64 build bots:
https://lab.llvm.org/buildbot/#/builders/96/builds/25032
2022-06-23 10:33:05 +00:00
Chelsea Cassanova 46be5faaf0 [lldb/Fuzzer] Add command interpreter fuzzer for LLDB
This adds a command interpreter fuzzer to LLDB's fuzzing library.
The input data from the fuzzer is used as input for the command
interpreter.
Input data for the fuzzer is guided by a dictionary of keywords used in
LLDB, such as "breakpoint", "target" and others.

Differential revision: https://reviews.llvm.org/D128292
2022-06-22 17:42:55 -04:00
Jonas Devlieghere d95c406c20
[lldb] Fix off-by-one error in the AppleObjCRuntimeV2 utility function
Fix an off-by-one error in the utility function used to extract the
dynamic class info. This resulted in a buffer overflow in the inferior
which interrupted our utility function.

Differential revision: https://reviews.llvm.org/D128377
2022-06-22 13:57:24 -07:00
Jonas Devlieghere f0d87dfe30
[lldb] Return the correct utility function in AppleObjCRuntimeV2
A copy/paste error in GetClassInfoUtilityFunction resulted in the wrong
utility function being returned: copyRealizedClassList instead of
getRealizedClassList_trylock.

Differential revision: https://reviews.llvm.org/D128378
2022-06-22 13:57:23 -07:00
Jim Ingham bae10a6bbb Fix a bug with "process continue -b" when no breakpoints are
passed.  I was passing the empty list of breakponts to the
VerifyBreakpointList routine, but that treats empty as "choose
the default breakpoint" which we don't want here.
2022-06-22 12:18:07 -07:00
Walter Erquinigo efbfde0dd0 [trace] Add an option to dump instructions in json and to a file
In order to provide simple scripting support on top of instruction traces, a simple solution is to enhance the `dump instructions` command and allow printing in json and directly to a file. The format is verbose and not space efficient, but it's not supposed to be used for really large traces, in which case the TraceCursor API is the way to go.

- add a -j option for printing the dump in json
- add a -J option for pretty printing the json output
- add a -F option for specifying an output file
- add a -a option for dumping all the instructions available starting at the initial point configured with the other flags
- add tests for all cases
- refactored the instruction dumper and abstracted the actual "printing" logic. There are two writer implementations: CLI and JSON. This made the dumper itself much more readable and maintanable

sample output:

```
(lldb) thread trace dump instructions  -t -a --id 100 -J
[
  {
    "id": 100,
    "tsc": "43591204528448966"
    "loadAddress": "0x407a91",
    "module": "a.out",
    "symbol": "void std::deque<Foo, std::allocator<Foo>>::_M_push_back_aux<Foo>(Foo&&)",
    "mnemonic": "movq",
    "source": "/usr/include/c++/8/bits/deque.tcc",
    "line": 492,
    "column": 30
  },
  ...
```

Differential Revision: https://reviews.llvm.org/D128316
2022-06-22 11:14:22 -07:00
Alexander Yermolovich 130167ed1e [LLDB] Handle DIE with DW_AT_low_pc and empty ranges
The case comes out of how BOLT handles transformation of
DW_AT_low_pc/DW_AT_high_pc into DW_AT_low_pc/DW_AT_high_pc
with latter being 0.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D127889
2022-06-22 10:54:25 -07:00
Alvin Wong a1ee0b947d [lldb] Second attempt at fixing command-target-create-resolve-exe.test on the buildbot 2022-06-22 20:49:30 +03:00
Jim Ingham 4298b1b8d1 Add a "-b" option to "process continue" to run to a set of breakpoints,
temporarily ignoring the others.

Differential Revision: https://reviews.llvm.org/D126513
2022-06-22 09:55:30 -07:00
Martin Storsjö 0bc7105cd1 [lldb] Tentative attempt to fix command-target-create-resolve-exe.test on buildbot
This test does succeed in my local test environment though, but
fails on the buildbot.
2022-06-22 18:48:04 +03:00
Alvin Wong 3c867898c7 [lldb] Add setting to override PE/COFF ABI by module name
The setting `plugin.object-file.pe-coff.module-abi` is a string-to-enum
map that allows specifying an ABI to a module name. For example:

    ucrtbase.dll=msvc
    libstdc++-6.dll=gnu

This allows for debugging a process which mixes both modules built using
the MSVC ABI and modules built using the MinGW ABI.

Depends on D127048

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D127234
2022-06-22 17:16:06 +03:00
Alvin Wong 4d12378395 [lldb][windows] Fix crash on getting nested exception
LLDB tries to follow `EXCEPTION_RECORD::ExceptionRecord` to follow the
nested exception chain. In practice this code just causes Access
Violation whenever there is a nested exception. Since there does not
appear to be any code in LLDB that is actually using the nested
exceptions, this change just removes the crashing code and adds a
comment for future reference.

Fixes https://github.com/mstorsjo/llvm-mingw/issues/292

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D128201
2022-06-22 17:16:06 +03:00
Alvin Wong 2bae956057 [lldb] Resolve exe location for `target create`
This fixes an issue that, when you start lldb or use `target create`
with a program name which is on $PATH, or not specify the .exe suffix of
a program in the working directory on Windows, you get a confusing
error, for example:

    (lldb) target create notepad
    error: 'C:\WINDOWS\SYSTEM32\notepad.exe' doesn't contain any 'host'
    platform architectures: i686, x86_64, i386, i386

Fixes https://github.com/mstorsjo/llvm-mingw/issues/265

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D127436
2022-06-22 17:16:05 +03:00
Martin Storsjö 8a64dd5b06 [lldb] Fix reading i686-windows executables with GNU environment
25c8a061c5 / D127048 added an option
for setting the ABI to GNU.

When an object file is loaded, there's only minimal verification
done for the architecture spec set for it, if the object file only
provides one.

However, for i386 object files, the PECOFF object file plugin
provides two architectures, i386-pc-windows and i686-pc-windows.
This picks a totally different codepath in
TargetList::CreateTargetInternal, where it's treated as a fat
binary. This goes through more verifications to see if the
architectures provided by the object file matches what the
platform plugin supports.

The PlatformWindows() constructor explicitly adds the
"i386-pc-windows" and "i686-pc-windows" architectures (even when
running on other architectures), which allows this "fat binary
verification" to succeed for the i386 object files that provide
two architectures.

However, after that commit, if the object file is advertised with
the different environment (either when lldb is built in a mingw
environment, or if that setting is set), the fat binary validation
won't accept the file any longer.

Update ArchSpec::IsEqualTo with more logic for the Windows use
cases; mismatching vendors is not an issue (they don't have any
practical effect on Windows), and GNU and MSVC environments are
compatible to the point that PlatformWindows can handle object
files for both environments/ABIs.

As a separate path forward, one could also consider to stop returning
two architecture specs from ObjectFilePECOFF::GetModuleSpecifications
for i386 files.

Differential Revision: https://reviews.llvm.org/D128268
2022-06-22 17:16:05 +03:00
Martin Storsjö 9846a1f2d4 [lldb] Remove an outdated comment. NFC.
This comment became outdated in 053eb35651
(but was moved along); that commit moved the code and the comment
to a separate function, with a separate local variable
`num_of_bytes_read`. On error, the possibly garbage value is never
copied back to the caller's reference, thus the comment is no longer
relevant (and slightly confusing as is).

Differential Revision: https://reviews.llvm.org/D128226
2022-06-22 16:11:59 +03:00
Michał Górny 5e9aed1be5 [lldb] [test] Mark TestNonStop as LLGS-specific
Thanks for Med Ismail Bennani for reporting the debugserver failures.
2022-06-22 05:36:30 +02:00
Jonas Devlieghere c866f8544c
[lldb] Add a setting to specify the preferred dynamic class info extractor o
Add a setting to configure how LLDB parses dynamic Objective-C class
metadata. By default LLDB will choose the most appropriate method for
the target OS.

Differential revision: https://reviews.llvm.org/D128312
2022-06-21 18:51:39 -07:00
Jonas Devlieghere c08f61b45e
[lldb] Instantiate lazily named classes on macOS Ventura.
Recent revisions of the Objective-C runtime changed
objc_debug_class_getNameRaw() in a way that no longer triggers lazy
names to be instantiated. This has the unintended side-effect of making
generic bridged Swift classes, such as _SwiftDeferredNSDictionary<U,V>
to become invisible to the Objective-C runtime.

This patch detects this situation and forces the names to be
instantiated by calling class_getName() and discarding the result before
calling objc_debug_class_getNameRaw() again.

Many thanks to Mike Ash for outlining the solution and Adrian for
authoring the downstream patch.

rdar://95245318

Differential revision: https://reviews.llvm.org/D128306
2022-06-21 18:51:38 -07:00
Jason Molenda 1490f87154 Roll back Michał's changes to debugserver, not meant for there
Michał's change in https://reviews.llvm.org/D127193 did a search &
replace for a pattern that also appears in debugserver, but it
shouldn't be done there.
2022-06-21 12:57:42 -07:00
Michał Górny 80c04c664a [lldb] [llgs] Attempt to fix LLGS tests on Windows
Sponsored by: The FreeBSD Foundation
2022-06-21 20:12:07 +02:00
Michał Górny 13eb5b3455 [lldb] [llgs] Add a test for detach-all packet
Add a test verifying that plain 'D' packet correctly detaches all
processes.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127291
2022-06-21 19:47:31 +02:00
Michał Górny 313d9c1519 [lldb] [llgs] Refactor fork/vfork tests, verify state
Refactor the fork and vfork tests to reuse the code better, avoid
unnecessary regexps and avoid unnecessary conversions between
hex-strings and integers.

Verify the server state after detaching.  In particular, verify that
the detached process' PID/TID pair is no longer valid,
and that the correct process remains running.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127290
2022-06-21 19:47:30 +02:00
Michał Górny d6b3de7256 [lldb] [llgs] Fix signo sent with fork/vfork/vforkdone events
Fix ThreadStopInfo struct to include the signal number for all events.
Since signo was not included in the details for fork, vfork
and vforkdone stops, the code incidentally referenced the wrong union
member, resulting in wrong signo being sent.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127193
2022-06-21 19:47:30 +02:00
Michał Górny 5b04eb23ae [lldb] [MainLoop] Support "pending callbacks", to be called once
Support adding a "pending callback" to the main loop, that will be
called once after all the pending events are processed.  This can be
e.g. to defer destroying the process instance until its exit is fully
processed, as suggested in D127500.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128253
2022-06-21 19:47:30 +02:00
Michał Górny bc04d24085 [lldb] [llgs] Implement non-stop style stop notification packets
Implement the support for %Stop asynchronous notification packet format
in LLGS.  This does not implement full support for non-stop mode for
threaded programs -- process plugins continue stopping all threads
on every event.  However, it will be used to implement asynchronous
events in multiprocess debugging.

The non-stop protocol is enabled using QNonStop packet.  When it is
enabled, the server uses notification protocol instead of regular stop
replies.  Since all threads are always stopped, notifications are always
generated for all active threads and copied into stop notification
queue.

If the queue was empty, the initial asynchronous %Stop notification
is sent to the client immediately.  The client needs to (eventually)
acknowledge the notification by sending the vStopped packet, in which
case it is popped from the queue and the stop reason for the next thread
is reported.  This continues until notification queue is empty again,
in which case an OK reply is sent.

Asychronous notifications are also used for vAttach results and program
exits.  The `?` packet uses a hybrid approach -- it returns the first
stop reason synchronously, and exposes the stop reasons for remaining
threads via vStopped queue.

The change includes a test case for a program generating a segfault
on 3 threads.  The server is expected to generate a stop notification
for the segfaulting thread, along with the notifications for the other
running threads (with "no stop reason").  This verifies that the stop
reasons are correctly reported for all threads, and that notification
queue works.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D125575
2022-06-21 19:04:20 +02:00
Pavel Labath 1004d6e7e2 [lldb] Skip Recognizer/assert.test on linux
-> PR56144
2022-06-21 16:51:02 +02:00
Emre Kultursay 6a85b9d163 Support expressions in the context of a reference
...type variable by dereferencing the variable before
evaluating the expression.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D128126
2022-06-21 14:30:07 +02:00
Kazu Hirata ed8fceaa09 Don't use Optional::getValue (NFC) 2022-06-20 23:35:53 -07:00
Kazu Hirata d66cbc565a Don't use Optional::hasValue (NFC) 2022-06-20 20:26:05 -07:00
Kazu Hirata 0916d96d12 Don't use Optional::hasValue (NFC) 2022-06-20 20:17:57 -07:00
Kazu Hirata 064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Jeffrey Tan 5109de2da2 Fix build break introduced by https://reviews.llvm.org/D127702
Fix build break introduced by https://reviews.llvm.org/D127702

Differential Revision: https://reviews.llvm.org/D128234
2022-06-20 17:31:26 -07:00
Jeffrey Tan 8c6e138aa8 Support logpoints in lldb-vscode
This patch implements VSCode DAP logpoints feature (also called tracepoint
in other VS debugger).
This will provide a convenient way for user to do printf style logging
debugging without pausing debuggee.

Differential Revision: https://reviews.llvm.org/D127702
2022-06-20 16:22:12 -07:00
Martin Storsjö c9fc4336d4 [lldb] Fix building with GCC 7 2022-06-21 00:19:09 +03:00
Jakob Johnson 50f9367960 Add LoadTraceFromFile to SBDebugger and SBTrace
Add trace load functionality to SBDebugger via the `LoadTraceFromFile` method.
Update intelpt test case class to have `testTraceLoad` method so we can take advantage of
the testApiAndSB decorator to test both the CLI and SB without duplicating code.

Differential Revision: https://reviews.llvm.org/D128107
2022-06-20 11:54:47 -07:00
Kazu Hirata ad7ce1e769 Don't use Optional::hasValue (NFC) 2022-06-20 11:49:10 -07:00
Kazu Hirata 5413bf1bac Don't use Optional::hasValue (NFC) 2022-06-20 11:33:56 -07:00
Michał Górny d3292c4ba0 [lldb] [test] Fix test_platform_file_fstat to account for negative ints
Fix test_platform_file_fstat to correctly truncate/max out the expected
value when GDB Remote Serial Protocol specifies a value as an unsigned
integer but the underlying platform type uses a signed integer.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128042
2022-06-20 19:42:22 +02:00
Michał Górny a36b9b382a [lldb] [test] Make AVX/MPX register tests more robust and fix on BSD
Make the AVX/MPX register tests more robust by checking for the presence
of actual registers rather than register sets.  Account for the option
that the respective registers are defined but not available, as is
the case on FreeBSD and NetBSD.  This fixes test regression on these
platforms.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128041
2022-06-20 19:42:21 +02:00
Michał Górny 94074399ab [lldb] [test] Disable gmodules testing on FreeBSD
The -gmodule tests currently fail on FreeBSD due to include bugs:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264730

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128034
2022-06-20 19:42:21 +02:00
Michał Górny f8c6de8dbb [lldb] [llgs] Refactor SendStopReasonForState for multiprocess
Refactor GDBRemoteCommunicationServerLLGS::SendStopReasonForState()
to accept process as an argument rather than hardcoding
m_current_process, in order to make it work correctly for multiprocess
scenarios.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127497
2022-06-20 19:42:21 +02:00
Michał Górny af93f123b9 [lldb] [llgs] Refactor SendStopReplyPacketForThread for multiprocess
Refactor SendStopReplyPacketForThread() to accept process instance
as a parameter rather than use m_current_process.  This future-proofs
it for multiprocess support.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127289
2022-06-20 19:42:21 +02:00
Michał Górny ac570fbb85 [lldb] [llgs] Include process ID in stop responses
Include the process identifier in the `T` stop responses when
multiprocess extension is enabled (i.e. prepend it to the thread
identifier).  Use the exposed identifier to simplify the fork-and-follow
tests.

The LLDB client accounts for the possible PID since the multiprocess
extension support was added in b601c67192.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127192
2022-06-20 13:37:23 +02:00
Michał Górny e4d6ed58a8 [lldb] [llgs] Include process id in W/X stop reasons
Include the process identifier in W/X stop reasons when multiprocess
extensions are enabled.

The LLDB client does not support process identifiers there at the moment
but it parses packets in such a way that their presence does not cause
any problems.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D127191
2022-06-20 13:37:23 +02:00
Pavel Labath 1f9f7a2f5d [lldb] Relax backtrace checks in TestDyldLaunchLinux
Newer versions of glibc (2.34) have an extra frame inside the `raise`
function.
2022-06-20 12:59:31 +02:00
Kazu Hirata 30c675878c Use value_or instead of getValueOr (NFC) 2022-06-19 10:34:41 -07:00
Kazu Hirata aa88161b37 [lldb] Use value_or instead of getValueOr (NFC) 2022-06-19 09:12:01 -07:00
Jonas Devlieghere 91688716ba
[lldb] Fix modernize-use-equals-default warnings (NFC)
Fix modernize-use-equals-default warnings. Because this check is listed
in LLDB's top level .clang-tidy configuration, the check is enabled by
default and the resulting warnings show up in my editor.

I've audited the modified lines. This is not a blind change.
2022-06-17 15:08:02 -07:00
Jonas Devlieghere 9916633997
[lldb] Fix modernize-use-override warnings (NFC)
Fix modernize-use-override warnings. Because this check is listed in
LLDB's top level .clang-tidy configuration, the check is enabled by
default and the resulting warnings show up in my editor.

I've audited the modified lines. This is not a blind change.
2022-06-17 15:08:02 -07:00
Dave Lee 4cc8f2a017 [lldb][tests] Automatically call compute_mydir (NFC)
Eliminate boilerplate of having each test manually assign to `mydir` by calling
`compute_mydir` in lldbtest.py.

Differential Revision: https://reviews.llvm.org/D128077
2022-06-17 14:34:49 -07:00
Adrian Prantl f000de8760 [LLDB][ExpressionParser] Fix indices inside format-strings passed to LLDB_LOG
llvm::formatv expects the parameter indexes to start with 0.
Unfortunately it doesn't detect out-of-bounds accesses in the format
string at compile-time, of which we had several inside ClangExpressionDeclMap.

This patch fixes these out-of-bounds format accesses.

Example output

Before

ClangExpressionDeclMap::FindExternalVisibleDecls for '$__lldb_class' in a
'TranslationUnit'
  CEDM::FEVD Searching the root namespace
  CEDM::FEVD Adding type for $__lldb_class: 1

After

ClangExpressionDeclMap::FindExternalVisibleDecls for '$__lldb_class' in
a 'TranslationUnit'
  CEDM::FEVD Searching the root namespace
  CEDM::FEVD Adding type for $__lldb_class: class (lambda)

Patch by Michael Buch!

Differential Revision: https://reviews.llvm.org/D128063
2022-06-17 09:26:01 -07:00
Michał Górny 13dfe0f0fc [lldb] [test] Update baseline test status for FreeBSD
Fixes #19721
Fixes #18440
Partially fixes bug #47660
Fixes #47761
Fixes #47763

Sponsored by: The FreeBSD Foundation
2022-06-17 14:35:18 +02:00
Muhammad Omair Javaid 3fd9aebbb7 [LLDB] XFAIL TestLoadUnload fails on Arm/Ubuntu Jammy
This patch marks following tests as XFAIL for Arm/Ubuntu Jammy 22.04:
test_lldb_process_load_and_unload_commands
test_load_unload
2022-06-17 12:06:35 +04:00
Jonas Devlieghere de74756571
[lldb] Remove LogHandler::Create functions (NFC)
Remove the LogHandler::Create functions. Except for the StreamHandler
they were just forwarding their arguments to std::make_shared.
2022-06-16 21:04:08 -07:00
Jonas Devlieghere af6ec9200b
[lldb] Cleanup Python API reference files after building the docs
The sphinx-automodapi extension requires that the generated RST files
live next to the index file. This means that we generate them in the
source directory rather than the build directory. This patch ensures
these files are removed again when sphinx finishes its build.

The proper solution to this problem would be to move everything in the
doc folder from the source directory to the build directory before
generating the docs.

I believe that old RST files being kept around is the reason that the
Python API references on the website isn't getting updated. This patch
is meant as a speculative fix and a way to confirm that.
2022-06-16 16:30:49 -07:00