Commit Graph

153 Commits

Author SHA1 Message Date
Stella Stamenova 027a9fc2c5 [windows] Use a well-known path for ComSpec if we fail to retrieve it
Summary: Right now we always try to retrieve ComSpec and if we fail, we give up. This rarely fails, but we can update the logic so that we fail even less frequently. Since there is a well-known path (albeit not always correct), try the path when we failed to retrieve it. Note that on other platforms, we generally just return a well-known path without any checking.

Reviewers: asmith, zturner, labath

Reviewed By: zturner, labath

Subscribers: llvm-commits

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

llvm-svn: 337395
2018-07-18 15:21:54 +00:00
Pavel Labath 2df331b0f7 Remove dependency from Host to python
Summary:
The only reason python was used in the Host module was to compute the
python path. I resolve this the same way as D47384 did for clang, by
moving the path computation into the python plugin and modifying
SBHostOS class to call into this module for ePathTypePythonDir.

Reviewers: zturner, jingham, davide

Subscribers: mgorny, lldb-commits

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

llvm-svn: 335104
2018-06-20 08:35:45 +00:00
Pavel Labath 60f028ff03 Replace HostInfo::GetLLDBPath with specific functions
Summary:
Instead of a function taking an enum value determining which path to
return, we now have a suite of functions, each returning a single path
kind. This makes it easy to move the python-path function into a
specific plugin in a follow-up commit.

All the users of GetLLDBPath were converted to call specific functions
instead. Most of them were hard-coding the enum value anyway, so this
conversion was simple. The only exception was SBHostOS, which I've
changed to use a switch on the incoming enum value.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

llvm-svn: 335052
2018-06-19 15:09:07 +00:00
Pavel Labath 9d4758ecdd Attempt to fix windows&freebsd builds broken by r334950
llvm-svn: 334952
2018-06-18 15:29:42 +00:00
Pavel Labath 2272c4811f Use llvm::VersionTuple instead of manual version marshalling
Summary:
This has multiple advantages:
- we need only one function argument/instance variable instead of three
- no need to default initialize variables
- no custom parsing code
- VersionTuple has comparison operators, which makes version comparisons much
  simpler

Reviewers: zturner, friss, clayborg, jingham

Subscribers: emaste, lldb-commits

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

llvm-svn: 334950
2018-06-18 15:02:23 +00:00
Jonas Devlieghere dd2f78e34c [FileSpec] Make style argument mandatory for SetFile. NFC
Fix SetFile uses in hosts that I missed in r334663.

llvm-svn: 334664
2018-06-13 22:23:48 +00:00
Stella Stamenova 9d6fabf9e3 [lit] Split test_set_working_dir TestProcessLaunch into two tests and fix it on Windows
Summary:
test_set_working_dir was testing two scenario: failure to set the working dir because of a non existent directory and succeeding to set the working directory. Since the negative case fails on both Linux and Windows, the positive case was never tested. I split the test into two which allows us to always run both the negative and positive cases. The positive case now succeeds on Linux and the negative case still fails.
During the investigation, it turned out that lldbtest.py will try to execute a process launch command up to 3 times if the command failed. This means that we could be covering up intermittent failures by running any test that does process launch multiple times without ever realizing it. I've changed the counter to 1 (though it can still be overwritten with the environment variable).
This change also fixes both the positive and negative cases on Windows. There were a few issues:
1) In ProcessLauncherWindows::LaunchProcess, the error was not retrieved until CloseHandle was possibly called. Since CloseHandle is also a system API, its success would overwrite any existing error that could be retrieved using GetLastError. So by the time the error was retrieved, it was now a success.
2) In DebuggerThread::StopDebugging TerminateProcess was called on the process handle regardless of whether it was a valid handle. This was causing the process to crash when the handle was LLDB_INVALID_PROCESS (0xFFFFFFFF).
3) In ProcessWindows::DoLaunch we need to check that the working directory exists before launching the process to have the same behavior as other platforms which first check the directory and then launch process. This way we also control the exact error string.

Reviewers: labath, zturner, asmith, jingham

Reviewed By: labath

Subscribers: llvm-commits

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

llvm-svn: 334642
2018-06-13 19:02:44 +00:00
Pavel Labath 70f4eaf699 Fix windows&mac builds broken by r331970 (RunShellCommand/Timeout) refactor
llvm-svn: 331974
2018-05-10 11:27:43 +00:00
Adrian Prantl 05097246f3 Reflow paragraphs in comments.
This is intended as a clean up after the big clang-format commit
(r280751), which unfortunately resulted in many of the comment
paragraphs in LLDB being very hard to read.

FYI, the script I used was:

import textwrap
import commands
import os
import sys
import re
tmp = "%s.tmp"%sys.argv[1]
out = open(tmp, "w+")
with open(sys.argv[1], "r") as f:
  header = ""
  text = ""
  comment = re.compile(r'^( *//) ([^ ].*)$')
  special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$')
  for line in f:
      match = comment.match(line)
      if match and not special.match(match.group(2)):
          # skip intentionally short comments.
          if not text and len(match.group(2)) < 40:
              out.write(line)
              continue

          if text:
              text += " " + match.group(2)
          else:
              header = match.group(1)
              text = match.group(2)

          continue

      if text:
          filled = textwrap.wrap(text, width=(78-len(header)),
                                 break_long_words=False)
          for l in filled:
              out.write(header+" "+l+'\n')
              text = ""

      out.write(line)

os.rename(tmp, sys.argv[1])

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

llvm-svn: 331197
2018-04-30 16:49:04 +00:00
Pavel Labath 3ff377a927 Fix windows and freebsd builds for r322174 (Environment)
llvm-svn: 322176
2018-01-10 12:25:48 +00:00
Pavel Labath 62930e57eb Add Utility/Environment class for handling... environments
Summary:
There was some confusion in the code about how to represent process
environment. Most of the code (ab)used the Args class for this purpose,
but some of it used a more basic StringList class instead. In either
case, the fact that the underlying abstraction did not provide primitive
operations for the typical environment operations meant that even a
simple operation like checking for an environment variable value was
several lines of code.

This patch adds a separate Environment class, which is essentialy a
llvm::StringMap<std::string> in disguise. To standard StringMap
functionality, it adds a couple of new functions, which are specific to
the environment use case:
- (most important) envp conversion for passing into execve() and likes.
  Instead of trying to maintain a constantly up-to-date envp view, it
  provides a function which creates a envp view on demand, with the
  expectation that this will be called as the very last thing before
  handing the value to the system function.
- insert(StringRef KeyEqValue) - splits KeyEqValue into (key, value)
  pair and inserts it into the environment map.
- compose(value_type KeyValue) - takes a map entry and converts in back
  into "KEY=VALUE" representation.

With this interface most of the environment-manipulating code becomes
one-liners. The only tricky part was maintaining compatibility in
SBLaunchInfo, which expects that the environment entries are accessible
by index and that the returned const char* is backed by the launch info
object (random access into maps is hard and the map stores the entry in
a deconstructed form, so we cannot just return a .c_str() value). To
solve this, I have the SBLaunchInfo convert the environment into the
"envp" form, and use it to answer the environment queries. Extra code is
added to make sure the envp version is always in sync.

(This also improves the layering situation as Args was in the Interpreter module
whereas Environment is in Utility.)

Reviewers: zturner, davide, jingham, clayborg

Subscribers: emaste, lldb-commits, mgorny

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

llvm-svn: 322174
2018-01-10 11:57:31 +00:00
Pavel Labath f1fb38b746 Remove dead Core/StreamFile includes
llvm-svn: 306817
2017-06-30 11:31:13 +00:00
Pavel Labath f2a8bccf85 Move StructuredData from Core to Utility
Summary:
It had a dependency on StringConvert and file reading code, which is not
in Utility. I've replaced that code by equivalent llvm operations.

I've added a unit test to demonstrate that parsing a file still works.

Reviewers: zturner, jingham

Subscribers: kubamracek, mgorny, lldb-commits

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

llvm-svn: 306394
2017-06-27 10:45:31 +00:00
Pavel Labath f891812b7b Remove home-grown thread-local storage wrappers
Summary:
Use c++11 thread_local variables instead. As far as I am aware, they are
supported by all compilers/targets we care about.

Reviewers: zturner, jingham

Subscribers: lldb-commits

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

llvm-svn: 305779
2017-06-20 08:11:43 +00:00
Zachary Turner 97206d5727 Rename Error -> Status.
This renames the LLDB error class to Status, as discussed
on the lldb-dev mailing list.

A change of this magnitude cannot easily be done without
find and replace, but that has potential to catch unwanted
occurrences of common strings such as "Error".  Every effort
was made to find all the obvious things such as the word "Error"
appearing in a string, etc, but it's possible there are still
some lingering occurences left around.  Hopefully nothing too
serious.

llvm-svn: 302872
2017-05-12 04:51:55 +00:00
Zachary Turner 2f3df6137a iwyu fixes for lldbCore.
This adjusts header file includes for headers and source files
in Core.  In doing so, one dependency cycle is eliminated
because all the includes from Core to that project were dead
includes anyway.  In places where some files in other projects
were only compiling due to a transitive include from another
header, fixups have been made so that those files also include
the header they need.  Tested on Windows and Linux, and plan
to address failures on OSX and FreeBSD after watching the
bots.

llvm-svn: 299714
2017-04-06 21:28:29 +00:00
Zachary Turner 5713a05b5b Move FileSpec from Host -> Utility.
llvm-svn: 298536
2017-03-22 18:40:07 +00:00
Zachary Turner 8d48cd6009 Resubmit "Delete the remainder of platform specific code in FileSpec."
This was causing a test failure in one of LLDB's tests which
specifically dealt with a limitation in LLVM's implementation
of home_directory() that LLDB's own implementation had worked
around.

This limitation has been addressed in r298513 on the LLVM side,
so the failing test (which is now unnecessary as the limitation
no longer exists) was removed in r298519, allowing this patch to
be re-submitted without modification.

llvm-svn: 298526
2017-03-22 17:33:23 +00:00
Pavel Labath ed00beba12 Revert "Delete the remainder of platform specific code in FileSpec."
This reverts commit r298465 as it breaks
TestLLVM.TestHomeDirectory.test_tilde_home_directory.

llvm-svn: 298509
2017-03-22 14:04:43 +00:00
Zachary Turner aaedf89101 Delete the remainder of platform specific code in FileSpec.
Differential Revision: https://reviews.llvm.org/D31129

llvm-svn: 298465
2017-03-22 00:27:24 +00:00
Zachary Turner 07db3f7e3f Resubmit r298334 after fixing OSX build errors.
Hopefully this works, I can't test since I don't have Mac
hardware, however.

llvm-svn: 298340
2017-03-21 05:47:57 +00:00
Jason Molenda 2eb3227f97 Revert r298334 until Zachary has a chance to fix the buildbot failure
on macosx.

llvm-svn: 298338
2017-03-21 04:45:10 +00:00
Zachary Turner bfe8bcbc43 Delete various lldb FileSystem functions.
Use LLVM's equivalent versions instead.

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

llvm-svn: 298334
2017-03-21 04:01:04 +00:00
Zachary Turner 6934e0aaa7 Remove FileSystem::Get/SetFilePermissions
Differential Revision: https://reviews.llvm.org/D31089

llvm-svn: 298205
2017-03-19 05:49:43 +00:00
Zachary Turner d3d95fd66a Remove FileSystem::MakeDirectory.
Have callers use llvm::sys::fs::create_directory() instead.

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

llvm-svn: 298203
2017-03-19 05:48:47 +00:00
Pavel Labath b7f0f45ffe Move GetAuxvData from Host to relevant process plugins
Summary:
GetAuxvData was causing dependencies from host to target and linux
process modules. It also does not fit netbsd use case, as there we can
only read the auxiliary vector with ptrace, which is better done in the
process plugin, with the other ptrace calls.

I resolve these issues by moving the freebsd and linux versions into the
relevant process plugins. In case of linux, this required adding an
interface in NativeProcessProtocol. The empty definitions on other
platforms can simply be removed.

To get the code compiling I had to add ProcessGdbRemote -> ProcessLinux
dependency, which was not caught before because we depended on it
transitively.

Reviewers: zturner, emaste

Subscribers: srhines, mgorny, lldb-commits

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

llvm-svn: 298066
2017-03-17 11:08:40 +00:00
Zachary Turner d82067f83a Remove LLDB's recursive directory deletion function.
LLVM now has such a function, so we use that instead.

llvm-svn: 297360
2017-03-09 05:12:36 +00:00
Zachary Turner ed96be99fa Delete LLDB's code for getting / setting thread name.
This is now functionality in LLVM, and all callers have
already been updated to use the LLVM functions.

llvm-svn: 296946
2017-03-04 01:31:06 +00:00
Zachary Turner 666cc0b291 Move DataBuffer / DataExtractor and friends from Core -> Utility.
llvm-svn: 296943
2017-03-04 01:30:05 +00:00
Zachary Turner 6f9e690199 Move Log from Core -> Utility.
All references to Host and Core have been removed, so this
class can now safely be lowered into Utility.

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

llvm-svn: 296909
2017-03-03 20:56:28 +00:00
Kamil Rytarowski c5f28e2a05 Switch std::call_once to llvm::call_once
Summary:
The std::call_once implementation in libstdc++ has problems on few systems: NetBSD, OpenBSD and Linux PPC. LLVM ships with a homegrown implementation llvm::call_once to help on these platforms.

This change is required in the NetBSD LLDB port. std::call_once with libstdc++ results with crashing the debugger.

Sponsored by <The NetBSD Foundation>

Reviewers: labath, joerg, emaste, mehdi_amini, clayborg

Reviewed By: labath, clayborg

Subscribers: #lldb

Tags: #lldb

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

llvm-svn: 294202
2017-02-06 17:55:02 +00:00
Zachary Turner bf9a77305f Move classes from Core -> Utility.
This moves the following classes from Core -> Utility.

ConstString
Error
RegularExpression
Stream
StreamString

The goal here is to get lldbUtility into a state where it has
no dependendencies except on itself and LLVM, so it can be the
starting point at which to start untangling LLDB's dependencies.
These are all low level and very widely used classes, and
previously lldbUtility had dependencies up to lldbCore in order
to use these classes.  So moving then down to lldbUtility makes
sense from both the short term and long term perspective in
solving this problem.

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

llvm-svn: 293941
2017-02-02 21:39:50 +00:00
Pavel Labath 2d0c5b0297 Replace chdir() usage with the llvm equivalent.
This removes a hack in PosixApi.h, which tends to produce strange
compile errors when it's included in the wrong order.

llvm-svn: 293045
2017-01-25 11:10:52 +00:00
Pavel Labath 1d5855b107 Replace getcwd with the llvm equivalent
Summary:
getcwd() is not available (well.. um.. deprecated?) on windows, and the way
PosixApi.h is providing it causes strange compile errors when it's included in
the wrong order. The best way to avoid that is to just not use chdir.

This replaces all uses of getcwd in generic code. There are still a couple of
more uses, but these are in platform-specific code.

chdir() is causing a similar problem, but for that there is no llvm equivalent
for that (yet).

Reviewers: zturner

Subscribers: lldb-commits

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

llvm-svn: 292795
2017-01-23 15:56:45 +00:00
Pavel Labath bda6fb7389 Attempt to fix windows build for r291198
llvm-svn: 291233
2017-01-06 12:41:15 +00:00
David Blaikie a322f36cfd Make lldb -Werror clean for -Wstring-conversion
Also found/fixed one bug identified by this warning in
RenderScriptx86ABIFixups.cpp where a string literal was being used in an
effort to provide a name for an instruction/register, but was instead
being passed as the bool 'isVolatile' parameter.

llvm-svn: 291198
2017-01-06 00:38:06 +00:00
Hafiz Abid Qadeer f6ee79c926 Fix build for mingw.
Summary: I was building lldb using cross mingw-w64 toolchain on Linux and observed some issues. This is first patch in the series to fix that build. It mostly corrects the case of include files and adjusts some #ifdefs from _MSC_VER to _WIN32 and vice versa. I built lldb on windows with VS after applying this patch to make sure it does not break the build there.

Reviewers: zturner, labath, abidh

Subscribers: ki.stfu, mgorny, lldb-commits

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

llvm-svn: 289821
2016-12-15 15:00:41 +00:00
Alexander Shaposhnikov 696bd63550 [lldb] Fix typos in file headers
This diff fixes typos in file headers (incorrect file names).

Test plan:

Under llvm/tools/lldb/source:
find ./* -type f | grep -e '\(cpp\|h\)$' | while read F; do B=$(basename $F); echo $F head -n 1 $F | grep -v $B | wc -l ; done

Differential revision: https://reviews.llvm.org/D27115

llvm-svn: 287966
2016-11-26 05:23:44 +00:00
Pavel Labath ce8d6d9c6c Fix builds Windows and OSX builds after Connection refactor in r287922
Switch various bits of platform-specific code to chrono that I did not notice
when doing a linux build. This exposed a bug that ConnectionGenericFileWindows
did not handle the magic UINT32_MAX timeout value (instead it waited for about an
hour, which is close enough I guess). Fix that as well.

llvm-svn: 287927
2016-11-25 14:43:37 +00:00
Zachary Turner 3165945a41 Convert Platform, Process, and Connection functions to StringRef.
All tests pass on Linux and Windows.

llvm-svn: 287259
2016-11-17 21:15:14 +00:00
Zachary Turner c156427ded Don't allow direct access to StreamString's internal buffer.
This is a large API change that removes the two functions from
StreamString that return a std::string& and a const std::string&,
and instead provide one function which returns a StringRef.

Direct access to the underlying buffer violates the concept of
a "stream" which is intended to provide forward only access,
and makes porting to llvm::raw_ostream more difficult in the
future.

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

llvm-svn: 287152
2016-11-16 21:15:24 +00:00
Mehdi Amini 665be50e37 Revert unwanted changes in lldb when updating llvm::Error()
My script updated lldb::Errors, and I failed to fix it entirely
before pushing. This restore everything in lldb as it was before
r286561.

llvm-svn: 286565
2016-11-11 05:07:57 +00:00
Mehdi Amini 41af43092c Make the Error class constructor protected
This is forcing to use Error::success(), which is in a wide majority
of cases a lot more readable.

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

llvm-svn: 286561
2016-11-11 04:28:40 +00:00
Pavel Labath 88d0cbe06d Remove TimeValue usage from lldb/Host
llvm-svn: 286371
2016-11-09 14:53:32 +00:00
Zachary Turner 97d2c4011b Convert some Args index-based iteration to range-style iteration.
This is better for a number of reasons.  Mostly style, but also:

1) Signed-unsigned comparison warnings disappear since there is
   no loop index.
2) Iterating with the range-for style gives you back an entry
   that has more than just a const char*, so it's more efficient
   and more useful.
3) Makes code safter since the type system enforces that it's
   impossible to index out of bounds.

llvm-svn: 283413
2016-10-05 23:40:23 +00:00
Zachary Turner 5a8ad4591b Make lldb -Werror clean on Windows.
Differential Revision: https://reviews.llvm.org/D25247

llvm-svn: 283344
2016-10-05 17:07:34 +00:00
Dimitar Vlahovski 17d9caf665 Again fixing windows build breakage like in rL282862
llvm-svn: 282866
2016-09-30 15:41:33 +00:00
Dimitar Vlahovski 7ca05307c9 Fixing windows build breakage caused by rL282822
The breakage was because of the moving of the UTF functions to the llvm
namespace

llvm-svn: 282862
2016-09-30 14:36:17 +00:00
Zachary Turner 27a5c2b302 Change FileAction::GetPath() to return a StringRef.
llvm-svn: 282306
2016-09-23 22:11:51 +00:00
Zachary Turner ecbb0bb169 Fix more functions in Args to use StringRef.
This patch also marks the const char* versions as =delete to prevent
their use.  This has the potential to cause build breakages on some
platforms which I can't compile.  I have tested on Windows, Linux,
and OSX.  Best practices for fixing broken callsites are outlined in
Args.h in a comment above the deleted function declarations.

Eventually we can remove these =delete declarations, but for now they
are important to make sure that all implicit conversions from
const char * are manually audited to make sure that they do not invoke a
conversion from nullptr.

llvm-svn: 281919
2016-09-19 17:54:06 +00:00