Commit Graph

285 Commits

Author SHA1 Message Date
Fangrui Song f1e2d5851b [OptTable] Rename PrintHelp to printHelp
To be consistent with other member functions and match the coding standard.
2021-06-24 14:47:03 -07:00
Raphael Isemann 76e47d4887 [lldb][NFC] Use C++ versions of the deprecated C standard library headers
The C headers are deprecated so as requested in D102845, this is replacing them
all with their (not deprecated) C++ equivalent.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D103084
2021-05-26 12:46:12 +02:00
Brad Smith 3a62d4fde8 Fix typo, arvm7 -> armv7 2021-05-05 00:56:44 -04:00
Fangrui Song cdae6d7711 [lldb] Fix one leak in reproducer
Use a variable of static storage duration to reference an intentionally
leaked variable. A static data area is in the GC-set of various leak
checkers.

This fixes 3 `check-lldb-shell` tests in a `-DLLVM_USE_SANITIZER={Leaks,Address}` build,
e.g. `test/Shell/Reproducer/TestHomeDir.test`

Differential Revision: https://reviews.llvm.org/D100806
2021-04-19 19:39:10 -07:00
Pavel Labath aca4488847 [lldb] Surpress "ingoring result" warning in reproducer_handler 2020-12-27 13:58:05 +01:00
Jonas Devlieghere 0ca90eb335 [lldb] Don't use ::exit but instead return from the driver loop (NFC)
This fixes a reproducer test failure that was caused by the undefined
order in which global destructors run. More concretely, the static
instance of the RealFileSystem had been destroyed before we finalized
the reproducer, which uses it to copy files into the reproducer. By
exiting normally, we call SBDebugger::Terminate and finalize the
reproducer before any static dtors are run.
2020-11-09 16:47:30 -08:00
Jonas Devlieghere 6ac12b5b6c [lldb] Destory the debugger in the Driver dtor (NFC) 2020-11-09 16:47:30 -08:00
Jonas Devlieghere 73811d32c7 [lldb] Move copying of files into reproducer out of process
For performance reasons the reproducers don't copy the files captured by
the file collector eagerly, but wait until the reproducer needs to be
generated.

This is a problematic when LLDB crashes and we have to do all this
signal-unsafe work in the signal handler. This patch uses a similar
trick to clang, which has the driver invoke a new cc1 instance to do all
this work out-of-process.

This patch moves the writing of the mapping file as well as copying over
the reproducers into a separate process spawned when lldb crashes.

Differential revision: https://reviews.llvm.org/D89600
2020-10-23 12:33:54 -07:00
Jonas Devlieghere 3746906193 [lldb] Add reproducer verifier
Add a reproducer verifier that catches:

 - Missing or invalid home directory
 - Missing or invalid working directory
 - Missing or invalid module/symbol paths
 - Missing files from the VFS

The verifier is enabled by default during replay, but can be skipped by
passing --reproducer-no-verify.

Differential revision: https://reviews.llvm.org/D86497
2020-09-02 22:00:00 -07:00
Med Ismail Bennani 0224738c1a [lldb/interpreter] Improve REPL init file compatibility
This patch changes the command interpreter sourcing logic for the REPL
init file. Instead of looking for a arbitrary file name, it standardizes
the REPL init file name to match to following scheme:

                          `.lldbinit-<language>-repl`

This will make the naming more homogenous and the sourcing logic future-proof.

rdar://65836048

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-09-02 01:21:22 +02:00
Raphael Isemann 7c80f2da81 Revert "[lldb] Add reproducer verifier"
This reverts commit 297f69afac. It broke
the Fedora 33 x86-64 bot. See the review for more info.
2020-09-01 12:21:44 +02:00
Jonas Devlieghere 297f69afac [lldb] Add reproducer verifier
Add a reproducer verifier that catches:

 - Missing or invalid home directory
 - Missing or invalid working directory
 - Missing or invalid module/symbol paths
 - Missing files from the VFS

The verifier is enabled by default during replay, but can be skipped by
passing --reproducer-no-verify.

Differential revision: https://reviews.llvm.org/D86497
2020-08-31 15:14:18 -07:00
Med Ismail Bennani 868b45b5b3 [lldb/interpreter] Add REPL-specific init file
This patch adds the infrastructure to have language specific REPL init
files. It's the foundation work to a following patch that will introduce
Swift REPL init file.

When lldb is launched with the `--repl` option, it will look for a REPL
init file in the home directory and source it. This overrides the
default `~/.lldbinit`, which content might make the REPL behave
unexpectedly. If the REPL init file doesn't exists, lldb will fall back
to the default init file.

rdar://65836048

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-08-20 00:36:32 +02:00
Luboš Luňák 77d5a63c19 [lldb] report an error if a CLI option lacks an argument
Differential Revision: https://reviews.llvm.org/D84955
2020-07-31 22:02:40 +02:00
Jonas Devlieghere 10aa9e19fa [LLDB/Reproducers] Add flag to avoid installing the signal handler.
There are bugs where you don't want the signal handler to trigger, most
notably when that will cause another crash. Examples of this are lldb
running out of memory or a bug in the reproducer generation code. This
adds an escape hatch trough a (developer oriented) flag to not install
the signal handler.

rdar://problem/65149595

Differential revision: https://reviews.llvm.org/D83496
2020-07-09 11:50:45 -07:00
Jonas Devlieghere 84557c18b3 [lldb/Reproducers] Rename developer-oriented reproducer flags.
This is a preparatory rename of the developer facing reproducer flags.

reproducer-skip-version-check -> reproducer-no-version-check
reproducer-auto-generate      -> reproducer-generate-on-quit
2020-07-09 11:50:45 -07:00
Jonas Devlieghere ce19664d94 [lldb/Driver] Print snippet before exiting with unknown argument.
Print a little snippet before exiting when passed unrecognized
arguments. The goal is twofold:

 - Point users to lldb --help.
 - Make it clear that we exited the debugger.
2020-05-20 12:35:02 -07:00
Jonas Devlieghere 5b5b81bcdc [lldb/Driver] Error out when encountering unknown arguments
There appears to be consensus in D80165 that this is the desired
behavior and I personally agree.

Differential revision: https://reviews.llvm.org/D80226
2020-05-20 09:40:40 -07:00
Jonas Devlieghere 82093e8fb7 [lldb/Driver] Fix handling on positional arguments
Before the transition to libOption it was possible to specify arguments
for the inferior without -- as long as they didn't start with a dash.

For example, the following invocations should all behave the same:

  $ lldb inferior inferior-arg
  $ lldb inferior -- inferior-arg
  $ lldb -- inferior inferior-arg

This patch fixes that behavior, documents it and adds a test to cover
the different combinations.

Differential revision: https://reviews.llvm.org/D80165
2020-05-18 18:52:18 -07:00
Jonas Devlieghere 61d5b0e663 [lldb/Driver] Exit with a non-zero exit code in case of error in batch mode.
We have the option to stop running commands in batch mode when an error
occurs. When that happens we should exit the driver with a non-zero exit
code.

Differential revision: https://reviews.llvm.org/D78825
2020-05-05 11:01:44 -07:00
Jonas Devlieghere 4c67b11918 [lldb/API] Add SBCommandInterpreterRunResult
This adds an RunCommandInterpreter overload that returns an instance of
SBCommandInterpreterRunResults. The goal is to avoid having to add more
and more overloads when we need more output arguments.

Differential revision: https://reviews.llvm.org/D79120
2020-05-01 13:55:38 -07:00
Jonas Devlieghere 4b35403942 [lldb/API] Move SBCommandInterpreterRunOption in its own header. (NFC)
Currently, `SBCommandInterpreterRunOptions` is defined in
`SBCommandInterpreter.h`. Given that the options are always passed by
reference, a forward declaration is sufficient.

That's not the case for `SBCommandInterpreterRunResults`, which we need
for a new overload for `RunCommandInterpreter` and that returns this new
class by value. We can't include `SBCommandInterpreter.h` because
`SBCommandInterpreter::GetDebugger()` returns SBDebugger by value and
therefore needs a full definition.

This patch moves the definition of `SBCommandInterpreterRunOptions` into
a new header. In a later patch,  `SBCommandInterpreterRunResults` will
be defined in there as well, solving the aforementioned problem.

Differential revision: https://reviews.llvm.org/D79115
2020-04-30 13:41:21 -07:00
Jonas Devlieghere 0d671dbca9 [lldb/Driver] Remove level of indentation (NFC)
Use an early return for when we couldn't create a pipe to source the
commands.
2020-04-24 12:50:53 -07:00
Jonas Devlieghere cdc514e4c6 [lldb] Update header guards to be consistent and compliant with LLVM (NFC)
LLDB has a few different styles of header guards and they're not very
consistent because things get moved around or copy/pasted. This patch
unifies the header guards across LLDB and converts everything to match
LLVM's style.

Differential revision: https://reviews.llvm.org/D74743
2020-02-17 23:15:40 -08:00
Jonas Devlieghere 066e817b42 [lldb/Reproducers] Add a flag to always generating a reproducer
Add a flag which always generates a reproducer when normally it would be
discarded. This is meant for testing purposes to capture a debugger
session without modification the session itself.
2020-01-15 19:45:54 -08:00
Jonas Devlieghere 62827737ac [lldb/Reproducer] Add version check
To ensure a reproducer works correctly, the version of LLDB used for
capture and replay must match. Right now the reproducer already contains
the LLDB version. However, this is purely informative. LLDB will happily
replay a reproducer generated with a different version of LLDB, which
can cause subtle differences.

This patch adds a version check which compares the current LLDB version
with the one in the reproducer. If the version doesn't match, LLDB will
refuse to replay. It also adds an escape hatch to make it possible to
still replay the reproducer without having to mess with the recorded
version. This might prove useful when you know two versions of LLDB
match, even though the version string doesn't. This behavior is
triggered by passing a new flag -reproducer-skip-version-check to the
lldb driver.

Differential revision: https://reviews.llvm.org/D70934
2019-12-03 07:54:42 -08:00
Pavel Labath 12284e54b4 [lldb] fix a -Wcast-qual warning 2019-11-26 14:49:16 +01:00
Jonas Devlieghere 6c2e4e8801 [Driver] Fix newline at the end of help output
Print a regular newline at the end of the help output. The current
string literal seems to throw off shells.
2019-11-21 13:36:39 -08:00
Jonas Devlieghere b26d9e417d [Reproducer] Instruct users to replay reproducer
Improve the message printed when LLDB crashes by asking the user to
replay the reproducer before attaching it to a bugreport..

********************
Crash reproducer for lldb version 10.0.0 (git@github.com:llvm/llvm-project.git revision ...)
  clang revision ...
  llvm revision ...

Reproducer written to '/path/to/reproducer'

Before attaching the reproducer to a bug report:
 - Look at the directory to ensure you're willing to share its content.
 - Make sure the reproducer works by replaying the reproducer.

Replay the reproducer with the following command:
./bin/lldb -replay /path/to/reproducer
********************
2019-11-21 13:25:53 -08:00
Jonas Devlieghere bb775bee21 [Docs] Generate the LLDB man page with Sphinx
This patch replaces the existing out-of-date man page for lldb and
replaces it with an RST file from which sphinx generates the actual
troff file. This is similar to how man pages are generated for the rest
of the LLVM utilities.

The man page is generated by building the `docs-lldb-man` target.

Differential revision: https://reviews.llvm.org/D70514
2019-11-21 10:04:11 -08:00
Jonas Devlieghere b03374584d [Driver] Fix missing space in lldb --help output. 2019-11-20 13:49:22 -08:00
Jonas Devlieghere c8dfe90729 [Reproducer] Generate LLDB reproducer on crash
This patch hooks the reproducer infrastructure with the signal handlers.
When lldb crashes with reproducers capture enabled, it will now generate
the reproducer and print a short message the standard out. This doesn't
affect the pretty stack traces, which are still printed before.

This patch also introduces a new reproducer sub-command that
intentionally raises a given signal to test the reproducer signal
handling.

Currently the signal handler is doing too much work. Instead of copying
over files into the reproducers in the signal handler, we should
re-invoke ourselves with a special command line flag that looks at the
VFS mapping and performs the copy.

This is a NO-OP when reproducers are disabled.

Differential revision: https://reviews.llvm.org/D70474
2019-11-20 13:14:16 -08:00
Jonas Devlieghere b117ec8be0 [LLDB] Fix formatting in the driver (NFC) 2019-11-19 10:23:56 -08:00
Vedant Kumar 4624e83ce7 [Signal] Allow llvm clients to opt into one-shot SIGPIPE handling
Allow clients of the llvm library to opt-in to one-shot SIGPIPE
handling, instead of forcing them to undo llvm's SIGPIPE handler
registration (which is brittle).

The current behavior is preserved for all llvm-derived tools (except
lldb) by means of a default-`true` flag in the InitLLVM constructor.

This prevents "IO error" crashes in long-lived processes (lldb is the
motivating example) which both a) load llvm as a dynamic library and b)
*really* need to ignore SIGPIPE.

As llvm signal handlers can be installed when calling into libclang
(say, via RemoveFileOnSignal), thereby overriding a previous SIG_IGN for
SIGPIPE, there is no clean way to opt-out of "exit-on-SIGPIPE" in the
current model.

Differential Revision: https://reviews.llvm.org/D70277
2019-11-18 10:27:27 -08:00
Jonas Devlieghere 81104ea9ab [CMake] Configure the Info.plist so it contains a real version number.
Use CMake to configure the Info.plist file so that we have a real
version number in things like crash reporter.
2019-11-15 09:50:42 -08:00
Jonas Devlieghere fa6984a3de [LLDB] Don't install the pretty stack trace handler twice.
I noticed that currently we are printing LLVM's pretty stack trace
twice. The reason is that we're calling PrintStackTraceOnErrorSignal in
addition to InitLLVM, which besides some other useful things, also
register LLVM's pretty stack trace handler.

Differential revision: https://reviews.llvm.org/D70216
2019-11-13 17:35:58 -08:00
Haibo Huang 77a60f0df6 [lldb] Record framework build path and use it everywhere
This avoids config time dependencies on liblldb. And enables other refactoring.
2019-11-06 14:05:35 -08:00
Vedant Kumar 0877dd14e4 [Driver] Force llvm to install its handlers before lldb's
Install llvm's signal handlers up front to prevent lldb's handlers from being
ignored. This is (hopefully) a stopgap workaround.

When lldb invokes an llvm API that installs signal handlers (e.g.
llvm::sys::RemoveFileOnSignal, possibly via a compiler embedded within lldb),
lldb's signal handlers are overriden if llvm is installing its handlers for the
first time.

To work around llvm's behavior, force it to install its handlers up front, and
*then* install lldb's handlers. In practice this is used to prevent lldb test
processes from exiting due to IO_ERR when SIGPIPE is received.

Note that when llvm installs its handlers, it 1) records the old handlers it
replaces and 2) re-installs the old handlers when its new handler is invoked.
That means that a signal not explicitly handled by lldb can fall back to being
handled by llvm's handler the first time it is received, and then by the
default handler the second time it is received.

Differential Revision: https://reviews.llvm.org/D69403
2019-10-25 11:19:10 -07:00
Vedant Kumar d0bd3fc88b Revert "Disable exit-on-SIGPIPE in lldb"
This reverts commit 32ce14e55e.

In post-commit review, Pavel pointed out that there's a simpler way to
ignore SIGPIPE in lldb that doesn't rely on llvm's handlers.
2019-10-24 13:19:49 -07:00
Vedant Kumar 32ce14e55e Disable exit-on-SIGPIPE in lldb
Occasionally, during test teardown, LLDB writes to a closed pipe.
Sometimes the communication is inherently unreliable, so LLDB tries to
avoid being killed due to SIGPIPE (it calls `signal(SIGPIPE, SIG_IGN)`).
However, LLVM's default SIGPIPE behavior overrides LLDB's, causing it to
exit with IO_ERR.

Opt LLDB out of the default SIGPIPE behavior. I expect that this will
resolve some LLDB test suite flakiness (tests randomly failing with
IO_ERR) that we've seen since r344372.

rdar://55750240

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

llvm-svn: 375288
2019-10-18 21:05:30 +00:00
Martin Storsjo 4778f40f78 [LLDB] [Driver] Use llvm::InitLLVM to do unicode argument conversion on Windows
This avoids the currently MSVC specific codepath of using the
wchar entry point and converting that to utf8.

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

llvm-svn: 374526
2019-10-11 08:44:51 +00:00
Lawrence D'Anna 9eb1371923 SBFile support in SBCommandReturnObject
Summary:
This patch add SBFile interfaces to SBCommandReturnObject, and
removes the internal callers of its FILE* interfaces.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374238
2019-10-09 21:50:49 +00:00
Jonas Devlieghere a0a2ca67fe [Driver] Remove duplicate option parsing (NFC)
We were checking OPT_no_use_colors three times, twice to disable colors
and once to enable debug mode. This simplifies things and now the option
is only checked once.

llvm-svn: 370814
2019-09-03 20:18:19 +00:00
Haibo Huang c6551bf013 Detect HAVE_SYS_TYPES_H in lldb
Summary:
After rL368069 I noticed that HAVE_SYS_TYPES_H is not defined in
Platform.h, or anywhere else in lldb. This change fixes that.

Reviewers: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

llvm-svn: 368125
2019-08-07 06:15:01 +00:00
Haibo Huang a63417fe6c Various build fixes for lldb on MinGW
Subscribers: mstorsjo, lldb-commits

Tags: #lldb

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

llvm-svn: 368069
2019-08-06 18:20:43 +00:00
Nathan Lanza 320d6795b2 [windows] re-call signal in sigint_handler for Windows
Summary:
Windows requires re-setting the signal handler each time it is used
and thus ctrl-c was not behaving properly on Windows

Reviewers: jfb

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

llvm-svn: 365868
2019-07-12 04:43:46 +00:00
Stefan Granitz 5dc9036746 [CMake] LLDB.framework tools handling
Summary:
Modify the way LLDB.framework tools are collected. This allows for better fine-tuning of the install behavior downstream. Each target calls `lldb_add_to_framework()` individually. When entering the function, the target exists and we can tweak its very own post-build and install steps. This was not possible with the old `LLDB_FRAMEWORK_TOOLS` approach.

No function change otherwise.
This is a reduced follow-up from the proposal in D61952.

Reviewers: xiaobai, compnerd, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: clayborg, friss, ki.stfu, mgorny, lldb-commits, labath, #lldb

Tags: #lldb

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

llvm-svn: 361946
2019-05-29 11:26:06 +00:00
Stefan Granitz a3388e5f9e [CMake] Folder structure for generated Xcode project to cover more targets
llvm-svn: 361799
2019-05-28 09:29:05 +00:00
Jorge Gorbe Moya 33dbab8271 [lldb] Fix use-of-uninitialized-value in Driver
The driver passes by reference an uninitialized num_errors variable to
RunCommandInterpreter. This should be fine, as it's supposed to be
an output argument, but the reproducer instrumentation reads it in order
to record the value of all the arguments to the function.

This change fixes it by initializing num_errors to 0 before calling
RunCommandInterpreter.

llvm-svn: 361444
2019-05-22 23:37:48 +00:00
Stefan Granitz dcc477e38c [CMake] Inline info plist in lldb driver
llvm-svn: 361068
2019-05-17 19:19:34 +00:00