Commit Graph

301 Commits

Author SHA1 Message Date
Martin Storsjö bc13101cf9 [lldb] Fix building for mingw after changes to sigtstp_handler
Some signal handlers were set up within an !_MSC_VER condition,
i.e. omitted in MSVC builds but included in mingw builds. Previously
sigtstp_handler was defined in all builds, but since
4bcadd6686 / D120320 it's only
defined non platforms other than Windows.

Change the condition to !_WIN32 for consistency between the MSVC
and mingw builds, fixing the build for mingw.

Differential Revision: https://reviews.llvm.org/D122486
2022-03-26 22:32:53 +02:00
Pavel Labath 4bcadd6686 [lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.

The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).

Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.

Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.

This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
  automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
  the thread which is running the handler

This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.

I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.

Differential Revision: https://reviews.llvm.org/D120320
2022-03-09 14:31:17 +01:00
Jonas Devlieghere 4212a57a54
[lldb] Remove reproducer_handler from the driver 2022-03-03 13:22:39 -08:00
Jonas Devlieghere 4429cf146e
[Support] Allow the ability to change WithColor's auto detection function
WithColor has an "auto detection mode" which looks whether the
corresponding whether the corresponding cl::opt is enabled or not. While
this is great when opting into cl::opt, it's not so great for downstream
users of this utility, which might have their own competing options to
enable or disable colors. The WithColor constructor takes a color mode,
but the big benefit of the class are its static error and warning
helpers and default error handlers.

In order to allow users of this utility to enable or disable colors
globally, this patch adds the ability to specify a global auto detection
function. By default, the auto detection function behaves the way that
it does today. The benefit of this patch lies in that it can be
overwritten. In addition to a ability to change the auto detection
function, I've also made it possible to get your hands on the default
auto detection function, so you swap it back if if you so desire.

This patch allow downstream users (like LLDB) to globally disable colors
with its own command line flag.

Differential revision: https://reviews.llvm.org/D120593
2022-02-28 20:30:06 -08:00
Jonas Devlieghere 3a167c4a90
Revert "[Support] Allow the ability to change WithColor's auto detection function"
This reverts commit a83cf7a846 because it
breaks a bunch of build bots.
2022-02-28 15:32:15 -08:00
Jonas Devlieghere a83cf7a846
[Support] Allow the ability to change WithColor's auto detection function
WithColor has an "auto detection mode" which looks whether the
corresponding whether the corresponding cl::opt is enabled or not. While
this is great when opting into cl::opt, it's not so great for downstream
users of this utility, which might have their own competing options to
enable or disable colors. The WithColor constructor takes a color mode,
but the big benefit of the class are its static error and warning
helpers and default error handlers.

In order to allow users of this utility to enable or disable colors
globally, this patch adds the ability to specify a global auto detection
function. By default, the auto detection function behaves the way that
it does today. The benefit of this patch lies in that it can be
overwritten. In addition to a ability to change the auto detection
function, I've also made it possible to get your hands on the default
auto detection function, so you swap it back if if you so desire.

This patch allow downstream users (like LLDB) to globally disable colors
with its own command line flag.

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

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

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

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

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

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

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

Differential revision: https://reviews.llvm.org/D116697
2022-01-05 15:03:46 -08:00
Jonas Devlieghere fa1260697e [lldb] Remove reproducer replay functionality
This is part of a bigger rework of the reproducer feature. See [1] for
more details.

[1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html
2021-12-17 17:14:52 -08:00
Jonas Devlieghere 67bc243535 [lldb] Remove --reproducer-finalize and associated functionality
This is part of a bigger rework of the reproducer feature. See [1] for
more details.

[1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html
2021-12-17 12:19:55 -08:00
Levon Ter-Grigoryan f23b829a26 Fixed use of -o and -k in LLDB under Windows when statically compiled with vcruntime.
Right now if the LLDB is compiled under the windows with static vcruntime library, the -o and -k commands will not work.

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

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

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

Command which will fail:
lldb.exe -o help

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

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D104413
2021-11-24 16:17:08 +00:00
Lawrence D'Anna bbef51eb43 [lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing.   I'm
currently resorting to convolutions like this:

    def find_lldb(may_reexec=False):
		if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
			if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
				raise Exception("cannot import lldb.\n"
					f"  sys.prefix should be: {prefix}\n"
					f"  but it is: {sys.prefix}")
		else:
			line1, line2 = subprocess.run(
				['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
				encoding='utf8', stdout=subprocess.PIPE,
				check=True).stdout.strip().splitlines()
			assert line1.strip() == '(lldb) script print(sys.prefix)'
			prefix = line2.strip()
			os.environ['LLDB_PYTHON_PREFIX'] = prefix

		if sys.prefix != prefix:
			if not may_reexec:
				raise Exception(
					"cannot import lldb.\n" +
					f"  This python, at {sys.prefix}\n"
					f"  does not math LLDB's python at {prefix}")
			os.environ['LLDB_PYTHON_PREFIX'] = prefix
			python_exe = os.path.join(prefix, 'bin', 'python3')
			os.execl(python_exe, python_exe, *sys.argv)

		lldb_path = subprocess.run(['lldb', '-P'],
			check=True, stdout=subprocess.PIPE,
				encoding='utf8').stdout.strip()

		sys.path = [lldb_path] + sys.path

This patch aims to replace all that with:

  #!/usr/bin/env lldb-python
  import lldb
  ...

... by adding the following features:

* new command line option: --print-script-interpreter-info.  This
   prints language-specific information about the script interpreter
   in JSON format.

* new tool (unix only): lldb-python which finds python and exec's it.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D112973
2021-11-10 10:33:34 -08:00
Lawrence D'Anna e2a6c08bbc [lldb] fix --source-quietly
Jim says:

lldb has a -Q or --source-quietly option, which supposedly does:

    --source-quietly     Tells the debugger to execute this one-line lldb command before any file has been loaded.

That seems like a weird description, since we don't generally use source for one line entries, but anyway, let's try it:

    > $LLDB_LLVM/clean-mono/build/Debug/bin/lldb -Q "script print('I should be quiet')" a.out -O "script print('I should be before')" -o "script print('I should be after')"
    (lldb) script print('I should be before')
    I should be before
    (lldb) target create "script print('I should be quiet')"
    error: unable to find executable for 'script print('I should be quiet')'

That was weird.  The first real -O gets sourced but not quietly, then the argument to the -Q gets treated as the target.

    > $LLDB_LLVM/clean-mono/build/Debug/bin/lldb -Q a.out -O "script print('I should be before')" -o "script print('I should be after')"
    (lldb) script print('I should be before')
    I should be before
    (lldb) target create "a.out"
    Current executable set to '/tmp/a.out' (x86_64).
    (lldb) script print('I should be after')
    I should be after

Well, that's a little better, but the -Q option seems to have done nothing.

---

This fixes the description of --source-quietly, as well as causing it
to actually suppress echoing while executing the initialization
commands.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D112988
2021-11-02 11:01:55 -07:00
Nico Weber bf3383501f [lldb] Get rid of HAVE_SYS_TYPES_H
LLVM includes this header unconditionally on all platforms
(including Windows), so this define should no longer be necessary.

No behavior change.

Differential Revision: https://reviews.llvm.org/D107338
2021-08-03 22:14:56 +02:00
Jan Kratochvil 72748488ad [lldb] Fix editline unicode on Linux
Based on:
  [lldb-dev] proposed change to remove conditional WCHAR support in libedit wrapper
  https://lists.llvm.org/pipermail/lldb-dev/2021-July/016961.html

There is already setlocale in lldb/source/Core/IOHandlerCursesGUI.cpp
but that does not apply for Editline GUI editing.

Unaware how to make automated test for this, it requires pty.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D105779
2021-07-13 12:37:53 +02:00
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