Commit Graph

230 Commits (7bc0ad1ea5e9fbfb67fc1a20f962bfd68d6d9b5c)

Author SHA1 Message Date
Ansariel 4f5af772a3 Fix crash in writeToRecorders 2020-12-16 14:26:17 +01:00
Ansariel 87dacc1ec1 Merge branch 'DRTVWR-507-maint' of https://bitbucket.org/lindenlab/viewer 2020-09-25 16:13:23 +02:00
Andrey Kleshchev 3424a1f965 SL-13979 Crash of logging system at LLError::Settings::getInstance()
LLSingleton depends onto logging system, having logging system be based on LLSingleton causes crashes and deadlocks
2020-09-25 13:54:06 +03:00
Nicky Dasmijn c7804dbf7e Merge remote-tracking branch 'll/d476' into fs-vs2017-d476 2020-07-20 11:53:09 +02:00
Nat Goodspeed d8649dbb8a SL-13361: Enable color processing on Windows 10 debug console.
(cherry picked from commit 0b61150e69)
2020-07-01 13:38:05 -04:00
Nicky Dasmijn 27715d4d03 Merge remote-tracking branch 'll/d476' into fs-eep-vs2017-d476 2020-05-21 06:54:02 +02:00
Nicky Dasmijn cff453ff51 Merge remote-tracking branch 'eep/master' into fs-eep-vs2017 2020-05-20 13:49:20 +02:00
Nat Goodspeed ca6f092929 DRTVWR-476: Merge branch 'master' of lindenlab/viewer into DRTVWR-476-boost-1.72 2020-05-06 16:06:26 -04:00
Nat Goodspeed 962ccb4f01 DRTVWR-476: Facilitate debugging test programs with logging.
On Mac, even if you run a test program with --debug or set LOGTEST=DEBUG, it
won't log to stderr if you're filtering build output or running the build in
an emacs compile buffer. This is because, on Mac, a viewer launched by mouse
rather than from the command line is passed a stderr stream that ultimately
gets logged to the system Console. The shouldLogToStderr() function is
intended to avoid spamming the Console with the (voluminous) viewer log
output. It tests whether stderr isatty() and, if not, suppresses calling
LLError::logToStderr().

This makes debugging test programs using log output trickier than necessary.
Change shouldLogToStderr() to permit logging when either stderr isatty() or is
a pipe. The original intention is preserved in that empirically, a viewer
launched by mouse is passed a stderr stream identified as a character device
rather than as a pipe.

Also introduce SetEnv, a class that facilitates setting (e.g.) LOGTEST=DEBUG
for specific test programs without setting it for all test programs in the
build. Using the constructor for a static object means you can set environment
variables before main() is entered, which is important because it's the main()
function in test.cpp that acts on the LOGTEST and LOGFAIL environment
variables.

These changes make it unnecessary to retain the temporary change in test.cpp
to force LOGTEST to DEBUG.
2020-04-03 10:46:17 -04:00
Nat Goodspeed cc9bdbcf19 DRTVWR-476: Introduce LLStacktrace, a token to stream stack trace.
LLStacktrace has no behavior except when you stream an instance to a
std::ostream. Then it reports the current traceback at that point to the
ostream.

This bit of indirection is intended to avoid the boost/stacktrace.hpp header
from being included everywhere.
2020-03-25 19:21:16 -04:00
Nat Goodspeed 7826683fa2 DRTVWR-476: Back out 355d9db4a59f: unroll stderr redirection. 2020-03-25 19:06:13 -04:00
Nat Goodspeed 99d4ddc668 DRTVWR-476: Back out e913c05d43b6: unroll stderr redirection. 2020-03-25 19:06:13 -04:00
Nat Goodspeed d94e4613ca DRTVWR-476: Back out e66ec842b851: unrolling stderr redirection. 2020-03-25 19:06:13 -04:00
Nat Goodspeed 950204a5d7 DRTVWR-476: Partially revert 978e09882565: undo using LLTempRedirect.
But leave LLTempRedirect available in the code base.
2020-03-25 19:06:13 -04:00
Nat Goodspeed 7ef10fe11c DRTVWR-476: Don't test configuration.emptyMap().
LLSD::emptyMap() is a factory for an empty map instance, NOT a predicate on
any particular instance. In fact checking configuration.isUndefined() and
testing whether the map is empty are both subsumed by (! configuration).
2020-03-25 19:06:13 -04:00
Nat Goodspeed ec2bd40d3e DRTVWR-476: Encapsulate dup()/dup2() fd saving as LLTempRedirect. 2020-03-25 19:06:12 -04:00
Nat Goodspeed 7f1a200214 DRTVWR-476: On Windows, dup2() et al. need <io.h> 2020-03-25 19:05:17 -04:00
Nat Goodspeed 07134aaee7 DRTVWR-476: Try to extend stderr redirection to Windows as well.
Make the LLError::Settings LLSingleton duplicate the file handle for stderr
(usually 2) on construction. Make its destructor restore the original target
for that file handle. Provide a getDupStderr() method to obtain the duplicate
file handle.

Move Settings declaration up to the top of the file so other code can
reference it.

Make RecordToFile (the Recorder subclass engaged by LLError::logToFile()),
instead of duplicating stderr's file handle itself, capture the duplicate
stderr file handle from Settings to revert stderr redirection on destruction.

Make RecordToStderr (the Recorder subclass engaged by LLError::logToStderr())
use fdopen() to create an LLFILE* targeting the duplicate file handle from
Settings. Write output to that instead of to stderr so logToStderr() continues
to provide output for the user instead of duplicating each line into the log
file.
2020-03-25 19:05:17 -04:00
Nat Goodspeed 7845f73c76 DRTVWR-476: Try to log stderr output from classic-C libraries.
Some of the libraries we use produce log output to stderr. Such output can be
informative, but is invisible unless you launch the viewer from a console. In
particular, it's invisible to anyone trying to diagnose a problem by reading
someone else's SecondLife.log file.

Make RecordToFile -- the Recorder subclass engaged by LLError::logToFile() --
redirect STDERR_FILENO to the newly-opened log file so that any subsequent
writes to stderr (or cerr, for that matter) will be captured in the log file.
But first duplicate the original stderr file handle, and restore it when
RecordToFile is destroyed. That way, output written to stderr during the final
moments of application shutdown should still appear on (console) stderr.
2020-03-25 19:05:17 -04:00
Nat Goodspeed 6b70493ddb DRTVWR-476: Make test program --debug switch work like LOGTEST=DEBUG.
The comments within indra/test/test.cpp promise that --debug is, in fact, like
LOGTEST=DEBUG. Until now, that was a lie. LOGTEST=level displayed log output
on stderr as well as in testprogram.log, while --debug did not.

Add LLError::logToStderr() function, and make initForApplication() (i.e.
commonInit()) call that instead of instantiating RecordToStderr inline. Also
call it when test.cpp recognizes --debug switch.

Remove the mFileRecorder, mFixedBufferRecorder and mFileRecorderFileName
members from SettingsConfig. That tactic doesn't scale.

Instead, add findRecorder<RECORDER>() and removeRecorder<RECORDER>() template
functions to locate (or remove) a RecorderPtr to an object of the specified
subclass. Both are based on an underlying findRecorderPos<RECORDER>() template
function. Since we never expect to manage more than a handful of RecorderPtrs,
and since access to the deleted members is very much application setup rather
than any kind of ongoing access, a search loop suffices.

logToFile() uses removeRecorder<RecordToFile>() rather than removing
mFileRecorder (the only use of mFileRecorder).

logToFixedBuffer() uses removeRecorder<RecordToFixedBuffer>() rather than
removing mFixedBufferRecorder (the only use of mFixedBufferRecorder).

Make RecordToFile store the filename with which it was instantiated. Add a
getFilename() method to retrieve it. logFileName() is now based on
findRecorder<RecordToFile>() instead of mFileRecorderFileName (the only use of
mFileRecorderFileName).

Make RecordToStderr::mUseANSI a simple bool rather than a three-state enum,
and set it immediately on construction. Apparently the reason it was set
lazily was because it consults its own checkANSI() method, and of course
'this' doesn't acquire the leaf class type until the constructor has completed
successfully. But since nothing in checkANSI() depends on anything else in
RecordToStderr, making it static solves that problem.
2020-03-25 18:47:13 -04:00
Brad Kittenbrink a6f31e9167 Fixed variadic macro usage in LL_ERRS_IF and LL_WARNS_IF and improved LLError::shouldLogToStderr() behavior under xcode. 2020-03-25 18:39:21 -04:00
Nat Goodspeed 4c9e90de43 DRTVWR-494: Get initialized LLMutexes for very early log calls.
Use function-static LLMutex instances instead of module-static instances,
since some log calls are evidently issued before we get around to initializing
llerror.cpp module-static variables.
2020-03-25 15:28:17 -04:00
Nat Goodspeed 1fc7c994d6 DRTVWR-494: Fix VS LLError::Log::demangle() vulnerability.
The Windows implementation of demangle() assumed that a "mangled" class name
produced by typeid(class).name() always starts with the prefix "class ",
checked for that and removed it. If the mangled name didn't start with that
prefix, it would emit a debug message and return the full name.

When the class in question is actually a struct, the prefix is "struct "
instead. But when demangle() was being called before logging had been fully
initialized, the debug message remarking that it didn't start with "class "
crashed.

Look for either "class " or "struct " prefix. Remove whichever is found and
return the rest of the name. If neither is found, only log if logging is
available.
2020-03-25 15:28:17 -04:00
Nicky Dasmijn a135b5b428 Merge remote-tracking branch 'origin/ll-vs2017' into fs-vs2017 2019-12-21 13:14:51 +01:00
Nat Goodspeed 82bdbd5e41 DRTVWR-476: Reinstate operator<<(std::ostream, LLError::LLStacktrace)
which was accidentally deleted by a merge.
2019-12-18 13:18:37 -05:00
Nat Goodspeed db074a29af DRTVWR-476: Merge in logging, coord conversion crash fixes. 2019-12-18 12:58:43 -05:00
Nat Goodspeed 632782e7ef DRTVWR-494: Get initialized LLMutexes for very early log calls.
Use function-static LLMutex instances instead of module-static instances,
since some log calls are evidently issued before we get around to initializing
llerror.cpp module-static variables.
2019-12-18 12:25:45 -05:00
Nat Goodspeed 8b4e4a950c Automated merge with file:///C:%5CUsers%5CNat%5Clinden%5Cviewer-llsingleton 2019-12-12 07:57:31 -05:00
Nat Goodspeed e8d174a1a6 DRTVWR-494: Fix VS LLError::Log::demangle() vulnerability.
The Windows implementation of demangle() assumed that a "mangled" class name
produced by typeid(class).name() always starts with the prefix "class ",
checked for that and removed it. If the mangled name didn't start with that
prefix, it would emit a debug message and return the full name.

When the class in question is actually a struct, the prefix is "struct "
instead. But when demangle() was being called before logging had been fully
initialized, the debug message remarking that it didn't start with "class "
crashed.

Look for either "class " or "struct " prefix. Remove whichever is found and
return the rest of the name. If neither is found, only log if logging is
available.
2019-12-12 07:39:23 -05:00
Nicky 9335eded97 Merge with viewer-vs2107 2019-12-08 17:18:43 +01:00
Nat Goodspeed 9e58f09096 DRTVWR-476: Introduce LLStacktrace, a token to stream stack trace.
LLStacktrace has no behavior except when you stream an instance to a
std::ostream. Then it reports the current traceback at that point to the
ostream.

This bit of indirection is intended to avoid the boost/stacktrace.hpp header
from being included everywhere.
2019-11-18 18:43:01 -05:00
Nat Goodspeed 3b1dce4d3f DRTVWR-476: Merge backout of 355d9db4a59f 2019-11-12 17:02:28 -05:00
Nat Goodspeed 369daed759 DRTVWR-476: Back out 355d9db4a59f: unroll stderr redirection. 2019-11-12 17:02:11 -05:00
Nat Goodspeed dbfd51b787 DRTVWR-476: Merge backout of e913c05d43b6 2019-11-12 16:59:23 -05:00
Nat Goodspeed 4c0a0712bb DRTVWR-476: Back out e913c05d43b6: unroll stderr redirection. 2019-11-12 16:59:08 -05:00
Nat Goodspeed d92ff30320 DRTVWR-476: Merge backout of e66ec842b851 2019-11-12 16:57:13 -05:00
Nat Goodspeed 814a7f14ad DRTVWR-476: Back out e66ec842b851: unrolling stderr redirection. 2019-11-12 16:56:43 -05:00
Nat Goodspeed bf33976b48 DRTVWR-476: Partially revert 978e09882565: undo using LLTempRedirect.
But leave LLTempRedirect available in the code base.
2019-11-12 16:54:56 -05:00
Nat Goodspeed 3e9d18671e DRTVWR-476: Don't test configuration.emptyMap().
LLSD::emptyMap() is a factory for an empty map instance, NOT a predicate on
any particular instance. In fact checking configuration.isUndefined() and
testing whether the map is empty are both subsumed by (! configuration).
2019-11-12 14:47:13 -05:00
Nicky fee98dac77 Merge with VS2017 2019-11-10 12:07:34 +01:00
Nat Goodspeed 2a582e31ce DRTVWR-476: Encapsulate dup()/dup2() fd saving as LLTempRedirect. 2019-10-31 12:39:31 -04:00
Nat Goodspeed 75344c296e DRTVWR-476: On Windows, dup2() et al. need <io.h> 2019-10-29 07:32:10 -04:00
Nat Goodspeed e5bb19d2fa DRTVWR-476: Try to extend stderr redirection to Windows as well.
Make the LLError::Settings LLSingleton duplicate the file handle for stderr
(usually 2) on construction. Make its destructor restore the original target
for that file handle. Provide a getDupStderr() method to obtain the duplicate
file handle.

Move Settings declaration up to the top of the file so other code can
reference it.

Make RecordToFile (the Recorder subclass engaged by LLError::logToFile()),
instead of duplicating stderr's file handle itself, capture the duplicate
stderr file handle from Settings to revert stderr redirection on destruction.

Make RecordToStderr (the Recorder subclass engaged by LLError::logToStderr())
use fdopen() to create an LLFILE* targeting the duplicate file handle from
Settings. Write output to that instead of to stderr so logToStderr() continues
to provide output for the user instead of duplicating each line into the log
file.
2019-10-28 17:15:40 -04:00
Nat Goodspeed 686e452659 DRTVWR-476: Try to log stderr output from classic-C libraries.
Some of the libraries we use produce log output to stderr. Such output can be
informative, but is invisible unless you launch the viewer from a console. In
particular, it's invisible to anyone trying to diagnose a problem by reading
someone else's SecondLife.log file.

Make RecordToFile -- the Recorder subclass engaged by LLError::logToFile() --
redirect STDERR_FILENO to the newly-opened log file so that any subsequent
writes to stderr (or cerr, for that matter) will be captured in the log file.
But first duplicate the original stderr file handle, and restore it when
RecordToFile is destroyed. That way, output written to stderr during the final
moments of application shutdown should still appear on (console) stderr.
2019-10-28 14:33:36 -04:00
Nat Goodspeed 18bb6d5d49 DRTVWR-476: Make test program --debug switch work like LOGTEST=DEBUG.
The comments within indra/test/test.cpp promise that --debug is, in fact, like
LOGTEST=DEBUG. Until now, that was a lie. LOGTEST=level displayed log output
on stderr as well as in testprogram.log, while --debug did not.

Add LLError::logToStderr() function, and make initForApplication() (i.e.
commonInit()) call that instead of instantiating RecordToStderr inline. Also
call it when test.cpp recognizes --debug switch.

Remove the mFileRecorder, mFixedBufferRecorder and mFileRecorderFileName
members from SettingsConfig. That tactic doesn't scale.

Instead, add findRecorder<RECORDER>() and removeRecorder<RECORDER>() template
functions to locate (or remove) a RecorderPtr to an object of the specified
subclass. Both are based on an underlying findRecorderPos<RECORDER>() template
function. Since we never expect to manage more than a handful of RecorderPtrs,
and since access to the deleted members is very much application setup rather
than any kind of ongoing access, a search loop suffices.

logToFile() uses removeRecorder<RecordToFile>() rather than removing
mFileRecorder (the only use of mFileRecorder).

logToFixedBuffer() uses removeRecorder<RecordToFixedBuffer>() rather than
removing mFixedBufferRecorder (the only use of mFixedBufferRecorder).

Make RecordToFile store the filename with which it was instantiated. Add a
getFilename() method to retrieve it. logFileName() is now based on
findRecorder<RecordToFile>() instead of mFileRecorderFileName (the only use of
mFileRecorderFileName).

Make RecordToStderr::mUseANSI a simple bool rather than a three-state enum,
and set it immediately on construction. Apparently the reason it was set
lazily was because it consults its own checkANSI() method, and of course
'this' doesn't acquire the leaf class type until the constructor has completed
successfully. But since nothing in checkANSI() depends on anything else in
RecordToStderr, making it static solves that problem.
2019-10-14 15:41:09 -04:00
Ansariel 61c56570ab Merge viewer-eep 2019-08-13 19:05:23 +02:00
Graham Linden 9bb6da1e76 Make llerror do 66% fewer fprintf calls when engaging ANSI encoding and eliminate branches from high-traffic code. 2019-07-30 11:59:20 -07:00
Nicky e6e66a953e Merge with viewer-vs2017 2019-06-06 14:37:27 +02:00
Nat Goodspeed ebcfbf277e Automated merge with ssh://bitbucket.org/lindenlab/viewer-release 2019-06-05 14:15:15 -04:00
Brad Kittenbrink 7ba60f7682 Fixed variadic macro usage in LL_ERRS_IF and LL_WARNS_IF and improved LLError::shouldLogToStderr() behavior under xcode. 2019-03-08 13:39:56 -08:00