Check if info.dli_sname is NULL,
If the image containing addr is found, but no nearest symbol was found, the dli_sname and dli_saddr fields are set to NULL.
sprintf poses two security risks:
(1) write to memory where it shouldn't
(2) read from memory where it shouldn't
This commit replaces the use of sprintf() with snprintf()
which has a size parameter to ensure the problems mentioned
above won't take place.
* Prepend the year to each glog line (#516)
This PR fixes issue #516 by prepending the year to each glog line.
Previous format of each line in a log file:
[IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
New format:
[IWEF]yyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg
* Fix logging_unittest for PR #530
Since the format of each glog line has been changed,
the logging_unittest must also be updated.
Fallback to using file offsets if no symbol is found, like we do if the
object could not be opened.
This makes backtraces usable even if objects in the trace are stripped,
since the trace can be symbolized by post-processing it with a tool like
asan_symbolize.py.
Note that this is not currently compatible with SymbolizeCallback as
this overwrites the filename in the buffer. The behavior is unchanged
in that case.
Closes: #514
- If the user specifies a custom Logger via SetLogger(), the docs state
that the logging module takes ownership of it. Prior to this change,
the logging library was not deleting a custom logger when the
LogDestination which owns it was destroyed.
* Added fixed log name support, take 2
See https://code.google.com/p/google-glog/issues/detail?id=209 and former https://github.com/google/glog/pull/19 - this is an updated version of that patch.
It adds a flag that allows to switch behavior from base_filename + filename_extension + time_pid_string to base_filename + filename_extension, while still defaulting to the current behavior to avoid breakage in existing code. This change would allow easier log rotation schemes and better control on what's written on disk.
* Ifdef away fcntl on mingw
* Use the defined HAVE_FCNTL instead
* ifdef away tests as well
add have_sys_wait for wait() on mingw.
* OS_WINDOWS bug in fseeking to the end, only triggered here
* Add support for automatic removal of old logs
GetOverdueLogNames(string log_directory, int days) will check all
filenames under log_directory, and return a list of files whose last modified time is
over the given days (calculated using difftime()).
So that we can easily for unlink all files stored in the returned vector.
* Replaced the lines that require C++11
* embed dirent.h in project
* Add support for automatic removal of old logs
In this commit, at the end of LogFileObject::Write,
it will perform clean up for old logs.
It uses GetLoggingDirectories() and for each file in each
directory, it will check if a file is a log file produced by glog.
If it is, and it is last modified 3 days ago, then it will unlink()
this file. (It will only remove the project's own log files,
it won't remove the logs from other projects.)
Currently it is hardcoded to 3 days, I'll see if this can be
implemented in a more flexible manner.
* Implement old log cleaner
The log cleaner can be enabled and disabled at any given time.
By default, the log cleaner is disabled.
For example, this will enable the log cleaner and delete
the log files whose last modified time is >= x days
google::EnableLogCleaner(x days);
To disable it, simply call
google::DisableLogCleaner();
Please note that it will only clean up the logs produced for
its own project, the log files from other project will be untouched.
* logging: log_cleaner: Use blackslash for windows dir delim
* logging: log_cleaner: remove the range-based loops
Also replaced the hardcoded overdue days with the correct variable.
* Add Marco Wang to AUTHORS and CONTRIBUTORS
* logging: log_cleaner: Remove redundant filename stripping
Previously the full path to a file is passed into IsGlogLog(),
and then std::string::erase() is used to get the filename part.
If a directory name contains '.', then this function will be unreliable.
Now only the filename it self is passed into IsGlogLog(),
so this problem will be eradicated.
* logging: log_cleaner: improve readability
* Add google::EnableLogCleaner() to windows logging.h
* logging: log_cleaner: Remove perror message
* logging: IsGlogLog: match filename keyword by keyword
Splitting a filename into tokens by '.' causes problems
if the executable's filename contains a dot.
Filename should be matched keyword by keyword in the following
order:
1. program name
2. hostname
3. username
4. "log"
When glog 0.4.0 is built using musl instead of glibc, the compilation
for this test fails because musl doesn't provide execinfo.h, which sets
HAVE_STACKTRACE to false.
Tested by building glog with musl and verifying that the build succeeds
with this patch. [See https://github.com/openwrt/packages/pull/8583]
Signed-off-by: Amol Bhave <ambhave@fb.com>
for `&CheckStackAddress`, VisualStudio emits address of a trampoline like PLT,
not the actual address of `CheckStackTrace`.
We need address of `CheckStackTrace` to guess the address range of the function.
`static` function seems to return the actual address of the function.
Fixes#421
* Fix demangling template parameter packs
Clang 4.0.1-10 and gcc 7.3.0 both mangle the function "void add<int>(int)" as
"_Z3addIJiEEvDpT_". The template parameter pack is of the form
J <template-arg>* E
The opening character for a param pack could be either I or J, as libiberty
follows [1]. This change simply adds the J case.
[1] fbd263526a/libiberty/cp-demangle.c (L3209)
* Upstream Chromium local changes to symbolize.cc
Chromium has its own fork of symbolize.cc and symbolize.h, and it has
several not-yet-upstreamed changes, that are not specific to Chromium.
This patch upstreams such a changes.
Fixed google::FindSymbol reading past end of a section
3dae0a2d7d
Fix -INT_MIN integer overflow in itoa_r().
ac4d28e9cb
Add print_unsymbolized_stack_traces gn arg.
6a2726776f
Switch to standard integer types in base/.
9b6f42934e
* Add a build option to print unsymbolized traces
This PRINT_UNSYMBOLIZED_STACK_TRACES option to cmake, and
--enable-unsymbolized-traces option to autoconf.
ReadFromOffset in symbolize.cc used to call lseek() + read() to read
data from fd. However, the fd may be reused for multiple symbolize
requests from multiple threads, and causes a race around the fd read
offset.
This updates it to use pread() to resolve the race.
Fixed these warnings:
src/logging_unittest.cc: At global scope:
src/logging_unittest.cc:1081:13: warning: 'void MyCheck(bool, bool)' defined but not used [-Wunused-function]
static void MyCheck(bool a, bool b) {
^~~~~~~
src/logging_unittest.cc:1078:13: warning: 'void MyFatal()' defined but not used [-Wunused-function]
static void MyFatal() {
^~~~~~~
If the getpwuid_r method doesn't find an entry with the given ID, it
will still return success (0), but the *result will be set to NULL.
This checks the |result| value so it won't crash if it doesn't find
the entry.
This normally shouldn't ever happen, but it can somehow happen on
iOS simulators.
The issue was caused by config.h header being included from both
header files and implementation files.
Proposed solution is to have regular header guard in the generated
config.h. Benefit of this solution is that it's least intrusive.
Downside is that it only solves issue for CMake build system, and
autoconf one is not fixed since header template is automatically
generated by autoheader who does not add header guard.
Glog was missing colored output when running in terminal
who is set to konsole* TERM, even though the terminal
itself supports colored output.
Add extra terminfo to the check function, so now output
from Glog is properly colored.
* added dbghelp symbolizer support for mingw and cygwin
* fixed compiler errors in case <stdint.h> is not available
* cmake: check whether SymFromAddr actually works
We previously had logic to compute the base address from program
headers as part of symbolization. The problem is that we need a correct
base address earlier in order to adjust a PC into the image's address
space, as these addresses can appear in unsymbolized output.
There was previously an assumption that only the mapping that
was lowest in the address space did not need to be adjusted. This
assumption is not guaranteed (for example, the kernel may choose to
map an ET_DYN lowest) and in fact turned out to be wrong in binaries
linked with lld because the first mapping is read-only.
The solution is to move the program header reading logic into the
code that reads /proc/self/maps.
There is a change in semantics for clients that install a callback
using the InstallSymbolizeOpenObjectFileCallback function. Any such
clients will need to return a correct base address from the callback
by reading program headers using code similar to that in the function
OpenObjectFileContainingPcAndGetStartAddress.
Summary:
Issue #80 points out several places in glog where TSAN discovers
false positives. One of these places is in the `LOG_EVERY_N` macros.
These macros are implemented by maintaining a static unprotected
integer counter, and TSAN will report data races on these counters.
Here is a minimum example to reproduce the data race:
```
void logging() {
for (int i = 0; i < 300; ++i) {
LOG_EVERY_N(INFO, 2) << "foo";
}
}
int main() {
auto t1 = std::thread(logging);
auto t2 = std::thread(logging);
t1.join();
t2.join();
return 0;
}
```
And here is the TSAN report:
```
WARNING: ThreadSanitizer: data race (pid=776850)
Write of size 4 at 0x558de483f684 by thread T2:
#0 logging()
#1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
#2 std::_Bind_simple<void (*())()>::operator()()
#3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
#4 execute_native_thread_routine
Previous write of size 4 at 0x558de483f684 by thread T1:
#0 logging()
#1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
#2 std::_Bind_simple<void (*())()>::operator()()
#3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
#4 execute_native_thread_routine
Location is global '<null>' at 0x000000000000 (main+0x00000011c684)
Thread T2 (tid=776857, running) created by main thread at:
#0 pthread_create
#1 __gthread_create
#2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
#3 main
Thread T1 (tid=776856, running) created by main thread at:
#0 pthread_create
#1 __gthread_create
#2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
#3 main
SUMMARY: ThreadSanitizer: data race in logging()
```
To avoid noisy TSAN reports and also avoid adding a performance hit, this
change will mark these counters as benign races so that TSAN will not report
them. This change will only have an effect if we are compiling with TSAN;
there are no changes if we are not building with TSAN.
With this change, the above example no longer reports a data race when built
and run with TSAN.
Glog uses a pre-C++11 compile time assert to verify the validity of
the severity parameter for LOG_EVERY_N. Unfortunately, some compilers
will complain about the usage of LOG_EVERY_N with
"-Wunused-local-typedef" due to the way the compile time assert is
constructed. This makes it impossible to use LOG_EVERY_N with this
warning treated as an error.
The fix simply removes the assert entirely. This is safe to do since
you can't put anything invalid into the severity parameters without
generating a compile error elsewhere. This has been safe to do ever
since the GLOG_ prefixes were added as part of 6febec361e.
Fixes#223
Commit changes to src/windows/glog/logging.h that were missed in
2df0ca34aa. Because a change to src/glog/logging.h.in was made,
src/windows/preprocess.sh needed to be run.
Don't rely on an internal-linkage extern "C" function having an
unmangled name. This isn't required by the ABI, and in fact is not
valid for a conforming compiler(!). Instead, allow symbolization to
produce either a mangled or an unmangled name here.
The macro NDEBUG could be automatically defined for release build on
some build environments (e.g. MSVC). If we use NDEBUG as a key to
distinguish using DCHECK as CHECK (I call this DCHECK is enabled) or
not, we cannot make DCHECK enabled for release build on such
environments.
Considering people use a program with glog for presubmit testing or
dogfooding, they should need to do release build with DCHECK enabled.
Previously, the implementation of google::GetStackTrace() that uses
libunwind uses a global variable that enforces that only one thread may
invoke libunwind at a time. However, libunwind is thread-safe. The
comment above the variable indicates that it is to protect against
reentrancy issues.
Instead of using a global variable, it would be much better to use a
thread-local variable to protect against these reentrancy issues. That
should provide the needed reentrancy protection while allowing multiple
threads to get stack traces at the same time.
It also allows for the removal of the atomic CAS operations on the
variable.
Resolves#160.
There can be a large kernel overhead involved in POSIX_FADV_DONTNEED.
There is no point in calling this per item logged, so rate limit
to at most once per 2MiB written.
With a simple test program that logs 100K items at WARNING level:
Before:
$ time strace -c -e fadvise64 log.test \
-log_dir=/dev/shm -logtofiles=true -logtostderr=false
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 12.522509 125 99957 fadvise64
------ ----------- ----------- --------- --------- ----------------
real 0m52.671s
user 0m2.194s
sys 0m44.022s
After:
$ time strace -c -e fadvise64 log.test \
-log_dir=/dev/shm -logtofiles=true -logtostderr=false
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.000759 152 5 fadvise64
------ ----------- ----------- --------- --------- ----------------
real 0m4.206s
user 0m1.436s
sys 0m3.153s
Fixes issue #84
See https://code.google.com/p/google-glog/issues/detail?id=209 - this is an updated version of that patch.
It adds a flag that allows to switch behavior from base_filename + filename_extension + time_pid_string to base_filename + filename_extension, while still defaulting to the current behavior to avoid breakage in existing code. This change would allow easier log rotation schemes and better control on what's written on disk.
It looks like commit 3c49b93 modified the auto-generated file src/config.h.in
to add a definition of macro GOOGLE_GLOG_DLL_DECL. One of the autotools
reverts this change upon running "make", causing the build to fail when a
source file includes demangle.h.
To fix the problem, revert the change to src/config.h.in and include
glog/logging.h from demangle.h which provides a definition of that macro.
Previously we were using a module's "start address", i.e. the
address at which the module's executable region was mapped, as the
zero virtual address, i.e. the address from which the DSO's virtual
addresses are calculated. This works fine for DSOs created by the
bfd and gold linkers, which will emit a PT_LOAD directive into the
program header which loads the executable region at virtual address
(p_vaddr) and file offset (p_offset) 0.
However, the lld linker may place a read-only region before the
executable region, meaning that both p_vaddr and p_offset for the
executable region are non-zero. This means that any symbols resolved
by the symbolizer are resolved to an incorrect virtual address. To
correctly calculate the address corresponding to virtual address zero,
we need to take into account p_vaddr and p_offset.
Specifically, the calculation starts with the "base address", i.e. the
start address minus the file offset. To get from the base address to
virtual address zero, we first add p_offset. This gives us the mapped
address of the start of the segment, or in other words the mapped
address corresponding to the virtual address of the segment. (Note
that this is distinct from the start address, as p_offset is not
guaranteed to be page aligned.) We then subtract p_vaddr, which takes
us to virtual address zero.
only signalhandler_unittest.cc uses "using namespace gflags".
others use "using namespace GFLAGS_NAMESPACE", so
signalhandler_unittest.cc does the same way.
fixes#62
When I set my own signal handler to SIGABRT, it did not executed
with CHECK. That is because SIGABRT handler is reset to default
just before glog calls abort.
Let me make it reset only if the handler is what glog installed
i.e. FailureSignalHandler.
Don't call RAW_VLOG with locking vmodule_lock
SetVLOGLevel locks vmodule_lock however RAW_VLOG at the end also implicitly locks it via InitVLOG3__.
This causes deadlock/segfault.
fixes#29
Previously, plain vector and string were used.
This assumed that there were "using" directives or
declarations before the macro was used. This will
not always be the case.
- ssize_t
Since Windows does not have ssize_t, we need to include BaseTsd.h and
use SSIZE_t instead.
- include algorithm
MSVS 2013 requests developers to include algorithm when they use
std::min.
By yyanagisawa
git-svn-id: https://google-glog.googlecode.com/svn/trunk@143 eb4d4688-79bd-11dd-afb4-1d65580434c0
their own implementation of OpenObjectFileContainingPcAndGetStartAddress.
GTTF: Make stack trace symbolization code recognize more symbols.
One example is __libc_start_main (easy to check), there may be more.
Include the correct elf header on OpenBSD and Android.
Fix Coverity NO_EFFECT defect. Comparing unsigned greater than or equal zero is always true.
git-svn-id: https://google-glog.googlecode.com/svn/trunk@140 eb4d4688-79bd-11dd-afb4-1d65580434c0
For now, we do not remove the declaration of posix_strerror_r,
but we might remove it in future.
git-svn-id: https://google-glog.googlecode.com/svn/trunk@139 eb4d4688-79bd-11dd-afb4-1d65580434c0
- Set -Isrc/windows for mingw
- Check existence of sigaction, pread, and pwrite
- Provide alternative implementation of pread and pwrite
- Eliminate symlink code for OS_WINDOWS
- Don't check /proc/self/fd if the OS isn't linux
- Don't use MSVC specific declarations in port.h for mingw
git-svn-id: https://google-glog.googlecode.com/svn/trunk@135 eb4d4688-79bd-11dd-afb4-1d65580434c0
The ABI incompatibility is bad when
- Build glog without gflags (glog package in most distributions doesn't
depend on gflags)
- Use both glog and gflags
git-svn-id: https://google-glog.googlecode.com/svn/trunk@125 eb4d4688-79bd-11dd-afb4-1d65580434c0