Commit Graph

1554 Commits

Author SHA1 Message Date
Michał Górny e9dcd8b37b [lldb] [Host/Terminal] Fix warnings with termios disabled
Thanks to Nico Weber for the suggestion.

Differential Revision: https://reviews.llvm.org/D112632
2021-10-29 09:58:09 +02:00
Michał Górny e50f02ba7e [lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuse
Refactor ConnectionFileDescriptor to improve code reuse for different
types of sockets.  Unify method naming.

While at it, remove some (now-)dead code from Socket.

Differential Revision: https://reviews.llvm.org/D112495
2021-10-28 19:24:10 +02:00
Michał Górny 073c5d0e47 [lldb] [Host/Socket] Make DecodeHostAndPort() return a dedicated struct
Differential Revision: https://reviews.llvm.org/D112629
2021-10-28 09:57:50 +02:00
Med Ismail Bennani 8dbbe3356b Revert "[lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuse"
This reverts commit e1acadb61d.
2021-10-27 23:57:33 +02:00
Michał Górny e1acadb61d [lldb] [Host/ConnectionFileDescriptor] Refactor to improve code reuse
Refactor ConnectionFileDescriptor to improve code reuse for different
types of sockets.  Unify method naming.

While at it, remove some (now-)dead code from Socket.

Differential Revision: https://reviews.llvm.org/D112495
2021-10-27 12:45:52 +02:00
Michał Górny 4373f3595f [lldb] [Host] Move port predicate-related logic to gdb-remote
Remove the port predicate from Socket and ConnectionFileDescriptor,
and move it to gdb-remote.  It is specifically relevant to the threading
used inside gdb-remote and with the new port callback API, we can
reliably move it there.  While at it, switch from the custom Predicate
to std::promise/std::future.

Differential Revision: https://reviews.llvm.org/D112357
2021-10-26 13:53:08 +02:00
Michał Górny 58d28b931f [lldb] [lldb-gdbserver] Unify listen/connect code to use ConnectionFileDescriptor
Unify the listen and connect code inside lldb-server to use
ConnectionFileDescriptor uniformly rather than a mix of it and Acceptor.
This involves:

- adding a function to map legacy values of host:port parameter
  (including legacy server URLs) into CFD-style URLs

- adding a callback to return "local socket id" (i.e. UNIX socket path
  or TCP port number) between listen() and accept() calls in CFD

- adding a "unix-abstract-accept" scheme to CFD

As an additional advantage, this permits lldb-server to accept any URL
known to CFD including the new serial:// scheme.  Effectively,
lldb-server can now listen on the serial port.  Tests for connecting
over a pty are added to test that.

Differential Revision: https://reviews.llvm.org/D111964
2021-10-26 13:06:19 +02:00
Pavel Labath 0a39a9c2cb Modernize and simplify HostInfo::GetOSKernelDescription
Replace bool+by-ref argument with llvm::Optional, and move the common
implementation into HostInfoPOSIX. Based on my (simple) experiment,
the uname and the sysctl approach return the same value on MacOS, so
there's no need for a mac-specific implementation of this functionality.

Differential Revision: https://reviews.llvm.org/D112457
2021-10-26 11:17:02 +02:00
Pavel Labath a53978c95c [lldb] Remove a trailing \0 from the result of HostInfoMacOSX::GetOSBuildString
This has been in there since forever, but only started to matter once
40e4ac3e changed how we print the string.
2021-10-25 17:33:06 +02:00
Michał Górny 9d63b90b59 [lldb] [Host/ConnectionFileDescriptor] Do not use non-blocking mode
Disable non-blocking mode that's enabled only for file:// and serial://
protocols.  All read operations should be going through the select(2)
in ConnectionFileDescriptor::BytesAvaliable, which effectively erases
(non-)blocking mode differences in reading.  We do want to perform
writes in the blocking mode.

Differential Revision: https://reviews.llvm.org/D112442
2021-10-25 16:24:00 +02:00
Michał Górny 21bb808eb4 [lldb] Support serial port parity checking
Differential Revision: https://reviews.llvm.org/D112365
2021-10-25 10:51:46 +02:00
Martin Storsjö ea9e9d61b5 [lldb] [Host/SerialPort] Fix build with GCC 7 2021-10-23 12:52:55 +03:00
Michał Górny ff56d80eaa [lldb] [Host/FreeBSD] Remove unused variable (NFC) 2021-10-23 11:38:35 +02:00
Pavel Labath 43f8845dd3 [lldb] Fix build errors from 8b8070e23
I missed windows and openbsd.
2021-10-22 14:28:52 +02:00
Pavel Labath 8b8070e234 Host::GetOSBuildString 2021-10-22 12:59:58 +02:00
Michał Górny 66e06cc8cb [llvm] [ADT] Update llvm::Split() per Pavel Labath's suggestions
Optimize the iterator comparison logic to compare Current.data()
pointers.  Use std::tie for assignments from std::pair.  Replace
the custom class with a function returning iterator_range.

Differential Revision: https://reviews.llvm.org/D110535
2021-10-22 12:27:46 +02:00
Michał Górny b8c3683d46 [lldb] [Host/SerialPort] Add std::moves for better compatibility 2021-10-21 11:08:05 +02:00
Michał Górny cbe7898447 [lldb] [Host/Terminal] Add missing #ifdef for baudRateToConst() 2021-10-21 11:00:17 +02:00
Michał Górny 4a7b4beac7 [lldb] Add serial:// protocol for connecting to serial port
Add a new serial:// protocol along with SerialPort that provides a new
API to open serial ports.  The URL consists of serial device path
followed by URL-style options, e.g.:

    serial:///dev/ttyS0?baud=115200&parity=even

If no options are provided, the serial port is only set to raw mode
and the other attributes remain unchanged.  Attributes provided via
options are modified to the specified values.  Upon closing the serial
port, its original attributes are restored.

Differential Revision: https://reviews.llvm.org/D111355
2021-10-21 10:46:45 +02:00
Michał Górny 92fb574c9f [lldb] [Host] Add setters for common teletype properties to Terminal
Add setters for common teletype properties to the Terminal class:

- SetRaw() to enable common raw mode options

- SetBaudRate() to set the baud rate

- SetStopBits() to select the number of stop bits

- SetParity() to control parity bit in the output

- SetHardwareControlFlow() to enable or disable hardware control flow
  (if supported)

Differential Revision: https://reviews.llvm.org/D111030
2021-10-21 10:33:38 +02:00
Michał Górny 39f2b05963 [lldb] [Host] Make Terminal methods return llvm::Error
Differential Revision: https://reviews.llvm.org/D111890
2021-10-19 13:31:03 +02:00
Michał Górny fee461b1d8 [lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp & m_write_sp
Combine m_read_sp and m_write_sp into a single m_io_sp.  In all
currently existing code paths, they are pointing to the same object
anyway.

Differential Revision: https://reviews.llvm.org/D111396
2021-10-11 12:08:08 +02:00
Michał Górny 4b46a41343 [lldb] [ConnectionFileDescriptorPosix] Refactor scheme matching
Move the POSIX-specific fd:// and file:// scheme handling into
separate methods.  Replace the custom GetURLAddress() matching with
splitting into scheme and path, and matching scheme via
llvm::StringSwitch.  Use early returns.

Differential Revision: https://reviews.llvm.org/D111321
2021-10-08 11:47:57 +02:00
Michał Górny dcb0e687fa [lldb] [ConnectionFileDescriptorPosix] Use a single NativeFile
Replace separate read and write NativeFile instances with a single
instance shared for reading and writing.  There is no clear indication
why two instances were used in the first place, and replacing them
with just one does not seem to cause any regressions in tests or manual
'process connect file://...'.

Differential Revision: https://reviews.llvm.org/D111314
2021-10-08 11:26:29 +02:00
Pavel Labath 93c1b3caf0 [lldb] Remove some anonymous namespaces
.. and reduce the scope of others. They don't follow llvm coding
standards (which say they should be used only when the same effect
cannot be achieved with the static keyword), and they set a bad example.
2021-10-05 08:35:18 +02:00
Pavel Labath fd9bc13803 [lldb] Fix a stray array access in Editline
This manifested itself as an asan failure in TestMultilineNavigation.py.
2021-10-04 14:26:02 +02:00
Michał Górny bd21257bf5 [lldb] [Host] Fix flipped logic in TerminalState::Save() 2021-10-01 18:23:54 +02:00
Michał Górny 58b4501eea [lldb] [Host] Refactor TerminalState
Refactor TerminalState to make the code simpler.  Move 'struct termios'
to a PImpl-style subclass.  Add an RAII interface to automatically store
and restore the state.

Differential revision: https://reviews.llvm.org/D110721
2021-10-01 12:53:21 +02:00
Michał Górny 52b04efa01 [lldb] [Host] Remove TerminalStateSwitcher
Remove TerminalStateSwitcher class.  It is not used anywhere and its API
is really weird.  This is the first step towards cleaning up Terminal.h.

Differential Revision: https://reviews.llvm.org/D110693
2021-09-29 13:45:41 +02:00
Pavel Labath 3dbf27e762 [lldb] A different fix for Domain Socket tests
we need to drop nuls from the end of the string.
2021-09-27 18:00:27 +02:00
Raphael Isemann be2a4216fc [lldb] Fix SocketTest.DomainGetConnectURI on macOS by stripping more zeroes from getpeername result
Apparently macOS is padding the name result with several padding zeroes at
the end. Just strip them all to pretend it's a C-string.

Thanks to Pavel for suggesting this fix.
2021-09-27 17:34:45 +02:00
Michał Górny 9da2fa277e [lldb] Move StringConvert inside debugserver
The StringConvert API is no longer used anywhere but in debugserver.
Since debugserver does not use LLVM API, we cannot replace it with
llvm::to_integer() and llvm::to_float() there.  Let's just move
the sources into debugserver.

Differential Revision: https://reviews.llvm.org/D110478
2021-09-27 14:32:42 +02:00
Michał Górny 93b82f45bc [lldb] [Host] Refactor XML converting getters
Refactor the XML converting attribute and text getters to use LLVM API.
While at it, remove some redundant error and missing XML support
handling, as the called base functions do that anyway.  Add tests
for these methods.

Note that this patch changes the getter behavior to be IMHO more
correct.  In particular:

- negative and overflowing integers are now reported as failures to
  convert, rather than being wrapped over or capped

- digits followed by text are now reported as failures to convert
  to double, rather than their numeric part being converted

Differential Revision: https://reviews.llvm.org/D110410
2021-09-27 14:26:33 +02:00
Markus Böck 0b61f43b60 [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES
Linking against the LibXml2::LibXml2 target has the advantage of not only importing the library, but also adding the include path as well as any definitions the library requires. In case of a static build of libxml2, eg. a define is set on Windows to remove any DLL imports and export.

LLVM already makes use of the target, but c-index-test and lldb were still linking against the library only.

The workaround for Mac OS-X that I removed seems to have also been made redundant since https://reviews.llvm.org/D84563 I believe

Differential Revision: https://reviews.llvm.org/D109975
2021-09-25 13:13:11 +02:00
Michał Górny 5f1c8d8a43 [lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API
Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant
LLDB API.  In particular, this means llvm::Regex, llvm::Error return
type and llvm::to_integer().

While at it, change the port type from int32_t to uint16_t.  The method
never returns any value outside this range, and using the correct type
allows us to rely on getAsInteger()'s implicit overflow check.

Differential Revision: https://reviews.llvm.org/D110391
2021-09-24 14:58:02 +02:00
Michał Górny c1af84ceaf Revert "[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API"
This reverts commit a6daf99228.  It causes
buildbot regressions, I'll investigate.
2021-09-24 13:33:51 +02:00
Michał Górny a6daf99228 [lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API
Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant
LLDB API.  In particular, this means llvm::Regex, llvm::Error return
type and llvm::to_integer().

While at it, change the port type from int32_t to uint16_t.  The method
never returns any value outside this range, and using the correct type
allows us to rely on getAsInteger()'s implicit overflow check.

Differential Revision: https://reviews.llvm.org/D110391
2021-09-24 13:24:58 +02:00
Pavel Labath 5685eb950d [lldb] Fix DomainSocket::GetSocketName for unnamed sockets
getpeername will return addrlen = 2 (sizeof sa_family_t) for unnamed
sockets (those not assigned a name with bind(2)). This is typically true
for client sockets as well as those created by socketpair(2).

This GetSocketName used to crash for sockets which were connected to
these kinds of sockets. Now it returns an empty string.
2021-09-23 12:30:18 +02:00
Michał Górny 8567f4d4b9 [lldb] Support querying registers via generic names without alt_names
Update GetRegisterInfoByName() methods to support getting registers
by a generic name independently of alt_name entries in the register
context.  This makes it possible to use generic names when interacting
with gdbserver (that does not supply alt_names).  It also makes it
possible to remove some of the duplicated information from register
context declarations and/or use alt_names for another purpose.

Differential Revision: https://reviews.llvm.org/D108554
2021-09-13 13:05:06 +02:00
Raphael Isemann 4b2e38d940 [lldb][NFC] Cleanup EditlineHistory 2021-09-13 09:30:31 +02:00
Raphael Isemann 4f7fb13f87 [lldb] Don't save empty expressions in the multiline editor history
Right now running `expr` to start the multiline expression editor and then
pressing enter causes an empty history empty to be created for the multiline
editor. That doesn't seem very useful for users as pressing the 'up' key will
now also bring up these empty expressions.

I don't think there is ever a use case for recalling a completely empty
expression from the history, so instead don't save those entries to the history
file and make sure we never recall them when navigating over the expression
history.

Note: This is actually a Swift downstream patch that got shipped with Apple's
LLDB for many years. However, this recently started conflicting with upstream
LLDB as D100048 added a test that made sure that empty expression entries don't
crash LLDB. Apple's LLDB was never affected by this crash as it never saved
empty expressions in the first place.

Reviewed By: augusto2112

Differential Revision: https://reviews.llvm.org/D108983
2021-08-31 18:51:18 +02:00
Hiroki ffcf571107 [LLDB] Fix 'std::out_of_range' crashing bug when file name completion using file path.
When I run a lldb command that uses filename completion, if I enter a string
that is not only a filename but also a string with a non-file name string added,
such as "./" that is relative path string , it will crash as soon as I press the
[Tab] key. For example, debugging an executable file named "hello" that is
compiled from a file named "hello.c" , and I’ll put a breakpoint on line 3 of
hello.c.

```
$ lldb ./hello
(lldb) breakpoint set --file hello.c --line 3
```

This is not a problem, but if I set "--file ./hello."  and then press [Tab] key
to complete file name, lldb crashes.

```
$ lldb ./hello
(lldb) breakpoint set --file ./hello.terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 8) > this->size() (which is 7)
```

The crash was caused because substr() (in lldb/source/Host/common/Editline.cpp)
cut out string which size is user's input string from the completion string.

I modified the code that erase the user's intput string from current line and
then add the completion string.

Differential Revision: https://reviews.llvm.org/D108817
2021-08-30 15:14:09 +02:00
Rumeet Dhindsa d9c5613e85 Update logic to close inherited file descriptors.
This patch adds the support to close all inherited fds into the child
process by iterating over /proc/self/fd entries.

Differential Revision: https://reviews.llvm.org/D105732
2021-08-19 14:40:43 -07:00
Michał Górny 8bbef4f9af [lldb] [gdb-remote] Sync vFile:open mode constants with GDB
Sync the mode constants used to drive vFile:open requests with these
used by GDB and defined for the gdb remote protocol.  This makes it
possible to use 'platform file open' after connecting to gdbremote
server (and to some degree to operate on the open file modulo other
incompatibilities).

Differential Revision: https://reviews.llvm.org/D106985
2021-08-09 12:07:18 +02:00
Michał Górny 14735cab65 [lldb] [gdb-remote] Add eOpenOptionReadWrite for future gdb compat
Modify OpenOptions enum to open the future path into synchronizing
vFile:open bits with GDB.  Currently, LLDB and GDB use different flag
models effectively making it impossible to match bits.  Notably, LLDB
uses two bits to indicate read and write status, and uses union of both
for read/write.  GDB uses a value of 0 for read-only, 1 for write-only
and 2 for read/write.

In order to future-proof the code for the GDB variant:

1. Add a distinct eOpenOptionReadWrite constant to be used instead
   of (eOpenOptionRead | eOpenOptionWrite) when R/W access is required.

2. Rename eOpenOptionRead and eOpenOptionWrite to eOpenOptionReadOnly
   and eOpenOptionWriteOnly respectively, to make it clear that they
   do not mean to be combined and require update to all call sites.

3. Use the intersection of all three flags when matching against
   the three possible values.

This commit does not change the actual bits used by LLDB.

Differential Revision: https://reviews.llvm.org/D106984
2021-08-09 12:06:59 +02:00
Neal Sidhwaney 55fd6f292f Revert "D106035: Remove conditional compilation for WCHAR support in libedit"
This reverts commit 7529f0e3e1.
2021-08-05 02:55:10 -07:00
Neal Sidhwaney 7529f0e3e1 D106035: Remove conditional compilation for WCHAR support in libedit
This change moves to using narrow character types and libedit APIs in
Editline, because those are the same types that the rest of LLVM/LLDB
uses, and it's generally considered better practice to use UTF-8
encoded in char than it is to use wider characters. However, for
character input, the change leaves in using a wchar to enable input of
multi-byte characters.

Differential Revision: https://reviews.llvm.org/D106035
2021-08-05 00:29:54 -07:00
Fangrui Song 72a83674dd Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]. NFC
[[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015.
2021-07-29 09:59:45 -07:00
David Spickett 7d27230de3 [lldb][AArch64] Add memory tag writing to lldb-server
This is implemented using the QMemTags packet, as specified
by GDB in:
https://sourceware.org/gdb/current/onlinedocs/gdb/General-Query-Packets.html#General-Query-Packets

(recall that qMemTags was previously added to read tags)

On receipt of a valid packet lldb-server will:
* align the given address and length to granules
  (most of the time lldb will have already done this
  but the specification doesn't guarantee it)
* Repeat the supplied tags as many times as needed to cover
  the range. (if tags > range we just use as many as needed)
* Call ptrace POKEMTETAGS to write the tags.

The ptrace step will loop just like the tag read does,
until all tags are written or we get an error.
Meaning that if ptrace succeeds it could be a partial write.
So we call it again and if we then get an error, return an error to
lldb.

We are not going to attempt to restore tags after a partial
write followed by an error. This matches the behaviour of the
existing memory writes.

The lldb-server tests have been extended to include read and
write in the same test file. With some updated function names
since "qMemTags" vs "QMemTags" isn't very clear when they're
next to each other.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D105180
2021-07-27 12:02:17 +01:00
Jonas Devlieghere fd2433e139 [lldb] Replace default bodies of special member functions with = default;
Replace default bodies of special member functions with = default;

$ run-clang-tidy.py -header-filter='lldb' -checks='-*,modernize-use-equals-default' -fix ,

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-equals-default.html

Differential revision: https://reviews.llvm.org/D104041
2021-07-02 11:31:16 -07:00