Commit Graph

208 Commits

Author SHA1 Message Date
Pavel Labath f5aaa999b9 Fix remaining threading issues in Log.h
Summary:
This fixes two threading issues in the logging code. The access to the
mask and options flags had data races when we were trying to
enable/disable logging while another thread was writing to the log.
Since we can log from almost any context, and we want it to be fast, so
I avoided locking primitives and used atomic variables instead. I have
also removed the (unused) setters for the mask and flags to make sure
that the only way to set them is through the enable/disable channel
functions.

I also add tests, which when run under tsan, verify that the use cases
like "doing an LLDB_LOGV while another thread disables logging" are
data-race-free.

Reviewers: zturner, clayborg

Subscribers: lldb-commits

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

llvm-svn: 297368
2017-03-09 10:16:07 +00:00
Eugene Zemtsov 7993cc5eed Make LLDB skip server-client roundtrip for signals that don't require any actions
If QPassSignals packaet is supported by lldb-server, lldb-client will
utilize it and ask the server to ignore signals that don't require stops
or notifications.
Such signals will be immediately re-injected into inferior to continue
normal execution.

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

llvm-svn: 297231
2017-03-07 21:34:40 +00:00
Zachary Turner 7f6a7a3752 Remove FileSpec::ReadFileContents.
This functionality is subsumed by DataBufferLLVM, which is
also more efficient since it will try to mmap.  However, we
don't yet support mmaping writable private sections, and in
some cases we were using ReadFileContents and then modifying
the buffer.  To address that I've added a flag to the
DataBufferLLVM methods that allow you to map privately, which
disables the mmaping path entirely.  Eventually we should teach
DataBufferLLVM to use mmap with writable private, but that is
orthogonal to this effort.

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

llvm-svn: 297095
2017-03-06 23:42:14 +00:00
Pavel Labath a96eac62d6 Update log_options unit test
it was accessing the details of the Log class directly. Let it go
through the channel class instead.

This also discovered a bug when we were setting but not clearing the log
options when enabling a channel.

llvm-svn: 297053
2017-03-06 19:10:19 +00:00
Zachary Turner fb1a0a0d2f Move many other files from Core -> Utility.
llvm-svn: 297043
2017-03-06 18:34:25 +00:00
Pavel Labath ca367ce3ad Fix Log unit tests
the llvm function for getting the thread name dropped the _np suffix
during review. Zachary's commit did not reflect that.

llvm-svn: 297013
2017-03-06 15:17:36 +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
Zachary Turner 1e021a162e [Windows] Remove the #include <eh.h> hack.
Prior to MSVC 2015 we had to manually include this header any
time we were going to include <thread> or <future> due to a
bug in MSVC's STL implementation.  This has been fixed in MSVC
for some time now, and we require VS 2015 minimum, so we can
remove this across all subprojects.

llvm-svn: 296906
2017-03-03 20:21:59 +00:00
Pavel Labath e2b2c70bc1 Fix gcc compilation of LogTest.cpp
llvm-svn: 296595
2017-03-01 10:08:51 +00:00
Pavel Labath 5e336903be Modernize Enable/DisableLogChannel interface a bit
Summary:
Use StringRef and ArrayRef where possible. This adds an accessor to the
Args class to get a view of the arguments as ArrayRef<const char *>.

Reviewers: zturner

Subscribers: lldb-commits

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

llvm-svn: 296592
2017-03-01 10:08:40 +00:00
Pavel Labath c9fbd9a3be Fix MinidumpParserTest on 32-bit arches
load_size should be 64-bit unconditionally to match the underlying API.
This makes sure the MAX value correctly signals to auto-detect the file
size when mmap()ing.

llvm-svn: 296334
2017-02-27 12:21:20 +00:00
Pavel Labath 88d081b505 Log: Fix a regression in handling log options
The channel refactor introduced a regression where we were not honoring
the log options passed when enabling the channel. Fix that and add a
test.

llvm-svn: 296329
2017-02-27 11:05:39 +00:00
Zachary Turner 3f4a4b3681 Delete DataBufferMemoryMap.
After a series of patches on the LLVM side to get the mmaping
code up to compatibility with LLDB's needs, it is now ready
to go, which means LLDB's custom mmapping code is redundant.
So this patch deletes it all and uses LLVM's code instead.

In the future, we could take this one step further and delete
even the lldb DataBuffer base class and rely entirely on
LLVM's facilities, but this is a job for another day.

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

llvm-svn: 296159
2017-02-24 18:56:49 +00:00
Pavel Labath 0a51bfb83f Attempt to fix windows unit tests
In LLVM r296049, IPDBSession::getGlobalScope lost its constness. Adjust
the unittest to account for that.

llvm-svn: 296107
2017-02-24 11:17:40 +00:00
Pavel Labath 048b3ece1d Add format_provider for the MemoryRegionInfo::OptionalBool enum
llvm-svn: 295821
2017-02-22 10:37:57 +00:00
Pavel Labath ba95a28c18 Log: Fix race in accessing the stream variable
Summary:
The code was attempting to copy the shared pointer member in order to
guarantee atomicity, but this is not enough. Instead, protect the
pointer with a proper read-write mutex.

This bug was present here for a long time, but my recent refactors must
have altered the timings slightly, such that now this fails fairly often
when running the tests: the test runner runs the "log disable" command
just as the thread monitoring the lldb-server child is about to report
that the server has exited.

I add a test case for this. It's not possible to reproduce the race
deterministically in normal circumstances, but I have verified that
before the fix, the test failed when run under tsan, and was running
fine afterwards.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

llvm-svn: 295712
2017-02-21 09:58:23 +00:00
Pavel Labath c4a3395103 Fix a couple of corner cases in NameMatches
Summary:
I originally set out to move the NameMatches closer to the relevant
function and add some unit tests. However, in the process I've found a
couple of bugs in the implementation:
- the early exits where not always correct:
  - (test==pattern) does not mean the match will always suceed because
    of regular expressions
  - pattern.empty() does not mean the match will fail because the "" is
    a valid prefix of any string

So I cleaned up those and added some tests. The only tricky part here
was that regcomp() implementation on darwin did not recognise the empty
string as a regular expression and returned an REG_EMPTY error instead.
The simples fix here seemed to be to replace the empty expression with
an equivalent non-empty one.

Reviewers: clayborg, zturner

Subscribers: mgorny, lldb-commits

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

llvm-svn: 295651
2017-02-20 11:35:33 +00:00
Pavel Labath 6673afb2dc Fix VASprintfTest on darwin
The way of injecting an error into the printf call was not working on
darwin - the C library still happily format the character. It only
returns an error after we use a wide character that does not fit into a
single byte, so switch the test to use that.

llvm-svn: 295443
2017-02-17 13:27:50 +00:00
Pavel Labath fb0d22d645 Reapply "Refactor log channel registration mechanism"
Changes wrt. previous version:
- add #include <atomic>: fix build on windows
- add extra {} around the string literals used to initialize
  llvm::StringLiteral: fix gcc build

llvm-svn: 295442
2017-02-17 13:27:42 +00:00
Pavel Labath a272fa8fff Fix breakage caused by r295368
Also move the ErrorTest into the Utility package, to follow the class it
is testing.

llvm-svn: 295436
2017-02-17 10:19:46 +00:00
Zachary Turner d9c0e15f4b Fix build
llvm-svn: 295369
2017-02-16 20:15:26 +00:00
Zachary Turner 24ae6294a4 Finish breaking the dependency from Utility.
Differential Revision: https://reviews.llvm.org/D29964

llvm-svn: 295368
2017-02-16 19:38:21 +00:00
Pavel Labath f0713996b2 Revert "Refactor log channel registration mechanism"
The change breaks on Windows and NetBSD bots. Revert while I
investigate.

llvm-svn: 295201
2017-02-15 17:13:19 +00:00
Pavel Labath 5fb8af40df Refactor log channel registration mechanism
Summary:
We currently have two log channel registration mechanisms. One uses a
set of function pointers and the other one is based on the
PluginManager.

The PluginManager dependency is unfortunate, as logging
is also used in lldb-server, and the PluginManager pulls in a lot of
classes which are not used in lldb-server.

Both approach have the problem that they leave too much to do for the
user, and so the individual log channels end up reimplementing command
line argument parsing, category listing, etc.

Here, I replace the PluginManager-based approach with a one. The new API
is more declarative, so the user only needs to specify the list of list
of channels, their descriptions, etc., and all the common tasks like
enabling/disabling categories are hadled by common code. I migrate the
LogChannelDWARF (only user of the PluginManager method) to the new API.

In the follow-up commits I'll replace the other channels with something
similar.

Reviewers: clayborg, zturner, beanz

Subscribers: aprantl, lldb-commits

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

llvm-svn: 295190
2017-02-15 16:11:59 +00:00
Pavel Labath 46d78f754a Fix unittests after r295088
This resurrects TestModule.so which got lost during the move and is
needed for the ModuleCache test.

llvm-svn: 295171
2017-02-15 12:27:19 +00:00
Zachary Turner 01c3243fc1 Remove dependencies from Utility to Core and Target.
With this patch, the only dependency left is from Utility
to Host.  After this is broken, Utility will finally be
standalone.

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

llvm-svn: 295088
2017-02-14 19:06:07 +00:00
Pavel Labath 5f7e583b33 UriParser cleanup
- move the header file to the include folder
- enclose the class in the proper namespace

llvm-svn: 294741
2017-02-10 12:21:22 +00:00
Pavel Labath 2f7cfaf4ad Switch TestPacketSpeedJSON to use the llvm chrono formatter
llvm-svn: 294739
2017-02-10 11:49:40 +00:00
Pavel Labath d02b1c83df Add a format_provider for the Timeout class
and use it in the appropriate log statements.

Formatting of chrono types in log messages was very clunky. This should
make it much nicer to use and give better output. For details of the
formatting options see the chrono formatter in llvm.

llvm-svn: 294738
2017-02-10 11:49:33 +00:00
Pavel Labath 5fae71c51c Convert Log class to llvm streams
Summary:
This converts LLDB's logging to use llvm streams instead of
lldb_private::Stream and friends. The changes are mostly
straight-forward and amount to s/lldb_private::Stream/llvm::raw_ostream.

The part worth calling out is the rewrite of the StreamCallback class.
Previously this class contained a per-thread buffer of data written. I
assume this had something to do with it trying to make sure each log
line is delivered as a single event, instead of multiple (possibly
interleaved) events. However, this is no longer relevant as the Log
class already writes things to a temporary buffer and then delivers the
message as a single "write", so I have just removed the code in
question.

Reviewers: zturner, clayborg

Subscribers: emaste, lldb-commits, mgorny

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

llvm-svn: 294736
2017-02-10 11:49:21 +00:00
Chris Bieneman fd2f0cb170 [CMake] Final dependency cleanup patch!
Summary:
This patch removes the over-specified dependencies from LLDBDependencies and instead relies on the dependencies as expressed in each library and tool.

This also removes the library looping in favor of allowing CMake to do its thing. I've tested this patch on Darwin, and found no issues, but since linker semantics vary by system I'll also work on testing it on other platforms too.

Help testing would be greatly appreciated.

Reviewers: labath, zturner

Subscribers: danalbert, srhines, mgorny, jgosnell, lldb-commits

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

llvm-svn: 294515
2017-02-08 21:00:46 +00:00
Chris Bieneman bc9d0cd925 [CMake] Add explicit dependencies for ObjectFileELF tests
llvm-svn: 294372
2017-02-07 23:33:58 +00:00
Pavel Labath 3b7e1981b2 Remove LIBLLDB_LOG_VERBOSE category
Summary:
Per discussion in D28616, having two ways two request logging (log
enable lldb XXX verbose && log enable -v lldb XXX) is confusing. This
removes the first option and standardizes all code to use the second
one.

I've added a LLDB_LOGV macro as a shorthand for if(log &&
log->GetVerbose()) and switched most of the affected log statements to
use that (I've only left a couple of cases that were doing complex
computations in an if(log) block).

Reviewers: jingham, zturner

Subscribers: lldb-commits

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

llvm-svn: 294113
2017-02-05 00:44:54 +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 86b03cf086 Fix windows build after r293821
We started passing the list of libraries to link to the
add_lldb_unittest macro, but that macro wasn't actually doing anything
with them. Fix that.

llvm-svn: 293913
2017-02-02 18:14:04 +00:00
Chris Bieneman 1751311a87 [CMake] Update unit tests with accurate dependencies
This is extending the updates from r293696 to the LLDB unit tests.

llvm-svn: 293821
2017-02-01 22:17:00 +00:00
Pavel Labath 23ccc29197 Open ELF core dumps with more than 64K sections
Summary:
Problem:

There are three filelds in the ELF header - e_phnum, e_shnum, and e_shstrndx -
that could be bigger than 64K and therefore do not fit in 16 bits reserved for
them in the header. If this happens, pretty often there is a special section at
index 0 which contains their real values for these fields in the section header
in the fields sh_info, sh_size, and sh_link respectively.

Fix:

- Rename original fields in the header declaration. We want to have them around
just in case.

- Reintroduce these fields as 32-bit members at the end of the header. By default
they are initialized from the header in Parse() method.

- In Parse(), detect the situation when the header might have been extended into
section info #0 and try to read it from the same data source.

- ObjectFileELF::GetModuleSpecifications accesses some of these fields but the
original parse uses too small data source. Re-parse the header if necessary
using bigger data source.

- ProcessElfCore::CreateInstance uses header with potentially sentinel values,
but it does not access these fields, so a comment here is enough.

Reviewers: labath

Reviewed By: labath

Subscribers: davidb, lldb-commits, mgorny

Differential Revision: https://reviews.llvm.org/D29095
Author: Eugene Birukov <eugenebi@hotmail.com>

llvm-svn: 293714
2017-01-31 23:09:46 +00:00
Pavel Labath 8198db30f3 Add format_provider for lldb::StateType
Reviewers: clayborg

Subscribers: mgorny, lldb-commits

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

llvm-svn: 292920
2017-01-24 11:48:25 +00:00
Pavel Labath c69d0a203b Fix new Log unit test
the test was flaky because I specified the format string for the process id
incorrectly. This should fix it.

llvm-svn: 292414
2017-01-18 17:31:55 +00:00
Pavel Labath a92d6230da Fix windows build for previous commit
We get an error about a redefinition of getcwd(). This seems to fix it.

llvm-svn: 292364
2017-01-18 12:29:51 +00:00
Pavel Labath 107d9bbd6c Add a more succinct logging syntax
This adds the LLDB_LOG macro, which enables one to write more succinct log
statements.
if (log)
  log->Printf("log something: %d", var);
becomes
LLDB_LOG(log, "log something: {0}, var);

The macro still internally does the "if(log)" dance, so the arguments are only
evaluated if logging is enabled, meaning it has the same overhead as the
previous syntax.

Additionally, the log statements will be automatically prefixed with the file
and function generating the log (if the corresponding new argument to the "log
enable" command is enabled), so one does not need to manually specify this in
the log statement.

It also uses the new llvm formatv syntax, which means we don't have to worry
about PRIx64 macros and similar, and we can log complex object (llvm::StringRef,
lldb_private::Error, ...) more easily.

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

llvm-svn: 292360
2017-01-18 11:00:26 +00:00
Pavel Labath 59d725cabf FileSpec: Fix PrependPathComponent("/")
Summary:
PrependPathComponent was unconditionally inserting path separators between the
path components. This is not correct if the prepended path is "/", which caused
problems down the line. Fix the function to use the same algorithm as
AppendPathComponent and add a test. This fixes one part of llvm.org/pr31611.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

llvm-svn: 292100
2017-01-16 10:07:02 +00:00
Pavel Labath 3284684dd1 Add format_provider for the Error class
Summary:
The formatter supports the same options as the string-like classes, i.e. the
ability to truncate the displayed string. I don't anticipate it would be much
used, but it seems consistent.

Reviewers: zturner, clayborg

Subscribers: mgorny, lldb-commits

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

llvm-svn: 291759
2017-01-12 11:13:24 +00:00
Tamas Berghammer 556b1611cd Improve Type::GetTypeScopeAndBasenameHelper and add unit tests
Previously it failed to handle nested types inside templated classes
making it impossible to look up these types using the fully qualified
name.

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

llvm-svn: 291559
2017-01-10 11:13:59 +00:00
Pavel Labath 763f1c453b Fix jModulesInfo handling for cross-path syntax debugging
We were sending paths with the host path separator, which meant the remote
target did not understand our packets correctly.

llvm-svn: 291103
2017-01-05 13:18:46 +00:00
Michal Gorny 95e2629216 [unittests] Split DWARF tests out of PDB, fix standalone build
Split the PDB tests into DWARF test and actual PDB tests, the latter
requiring DIA SDK. Use the new LLVMConfig.cmake LLVM_ENABLE_DIA_SDK
symbol to enable the PDB tests rather than relying on
llvm/Config/config.h private include file that is not available when
building standalone.

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

llvm-svn: 290819
2017-01-02 18:20:33 +00:00
Zachary Turner 827d5d74a5 Add methods to enable using formatv syntax in LLDB.
This adds formatv-backed formatting functions in various
places in LLDB such as StreamString, logging, constructing
error messages, etc.  A couple of callsites are changed
from Printf style syntax to formatv style syntax to
illustrate its usage.  Additionally, a FileSpec formatter
is introduced so that FileSpecs can be formatted natively.

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

llvm-svn: 289922
2016-12-16 04:27:00 +00:00
Chris Bieneman 07522bb187 [CMake] Don't add gtest if it is already there
LLVM build trees export the gtest library through a special export set. If you're building against a build tree you shouldn't need to re-add gtest, but if you're building against an installed LLVM you do.

llvm-svn: 288691
2016-12-05 19:40:34 +00:00
Pavel Labath e6e7e6c348 Fix handling of consecutive slashes in FileSpec::GetNormalizedPath()
The core of the function was actually handling them correctly. However, the
early exit was being too optimistic and did not give the function a chance to
fire if the path did not contain dots as well.

Fix that and add a couple of unit tests.

llvm-svn: 288247
2016-11-30 16:08:45 +00:00