Bug: http://b/31532493
Using misaligned pointers forces us to potentially take the address of
members in a packed structure (which is now a warning/error in the
latest Clang). Using memcpy() is the proper way to handle this kind of
problem, as the compiler can insert the proper instructions (and usually
elide the memcpy() entirely).
Test: Built correctly with updated compilers.
Change-Id: Ia1f6eb62cf19404ff76b71d3c6c7ffffa1403120
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.
Correct liblog/README
Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.
Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
Undo zero-termination-substitution for linebreaks when logging.
This results in handing the complete log message to the aborter.
Add a test.
Bug: 31893081
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I2ef6c6351db2fd494a02985f634f439104136227
Should use android/log.h instead of log/log.h as a good example
to all others. Adjust header order to comply with Android Coding
standards.
Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I33a8fb4e754d2dc4754d335660c450e0a67190fc
Partially reverts commit 436f5a031f.
Remove the variants taking a fully qualified LogSeverity. Instead
use a lambda with "using" statements to translate both qualified
and unqualified names into valid expressions.
Compile-time regression was measured as 0.1s for a thousand LOG
statements on a z840.
Update tests.
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I36fdf30a9d535b19543307b85d1b3c19a97f20dd
Makes it easier to write correct code in a world where the maximum
property key/value lengths change.
Bug: http://b/23102347
Test: libbase_test64
Change-Id: I100f00904221bbcef9e8786a4e6e30428039bb49
Add WOULD_LOG to determine whether a given severity would be logged.
Add LOG_STREAM to have direct access to a logging stream.
Add LOG_S variants that take a fully qualified severity. This allows
complex expressions as parameters, e.g., ternaries for conditional
severity levels.
Add tests.
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I242b960594e68caff6db9cd8aaa4ce8aaf90474c
Add the INTERNAL_FATAL level. It will print 'F' like FATAL, but
does not abort after logging.
Add a test to logging_test.
Bug: 31338270
Test: m
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: Idf74c08e8516881efccaefc58fa3f41d57e56396
Use ECMAscript regex syntax (the default!) for a simpler regex.
Also test the cartesian product of logging options, with less copy & paste
than the previous test of a subset.
Change-Id: I7aae91d276dbbb8de6173d18b5c1ceb01c1dff73
Assume C++11 support. logging.h already used constexpr before,
macros.h now also does no longer check the language level.
Use constexpr for the logging evaluator. This allows the usage
of CHECK and co in other constexpr expressions in C++14.
Test: m checkbuild (N9)
Change-Id: Ifdffa074271fff1f9949c48829a185800ec5e524
We'd long had two copies of this stuff, so rather than rewrite both
Linux versions to use android::base::Readlink, let's kill the duplication
too...
Bug: http://b/30988271
Change-Id: I4de58a94a22a4b1faf969a6fc70ca1560a4d5121
unique_fd's implicit conversion to int allows it to be passed to
close(2), which is dangerous because unique_fd will think that it still
has ownership of the now-closed fd. Disallow this by providing an
overload for close that's tagged with an attribute that gives a
compile-time error.
Test: m
Change-Id: I514591335b337f2f57c1df371cf3979304aea17c
adb is the client that wants this, but I'm not aware of any client that
doesn't.
Bug: http://b/28467098
Test: tested manually with cat.
Change-Id: I82c3f7ddf466a67aedfbb9010e0939a44b71d3e5
adb implements its own file descriptor emulation layer on Windows,
which requires the use of adb_close instead of close throughout the
codebase. Add a template argument to unique_fd that allows for this.
Bug: http://b/28347842
Change-Id: I6397261f4973d49f2f8e04257bf67b348585bb63
This prevents a ton of macro collisions when libfoo includes libbinder
includes unique_fd.h.
Bug: 27804373
Change-Id: Ide834afb1052b32e86fad3fcba10cff3dafeb899
This prevents macro conflicts with vendor code.
Bug: 27804373
Change-Id: I759c2b7b611203d0afdc35ddd5c2adb8f942ea17
Test: Compiles when libbinder include path changes to include libbase.
I've been meaning to do this for a while, and it came up on the bug below
that there have been conflicts with similar-named files in <base/*.h>,
so let's rule out one possible explanation.
Bug: http://b/27804373
Change-Id: I69e5d52b6260c573c308513420aee0e281426bd4
Also list all known aliases of this class to increase the chances that
anyone searching for it by another name finds it anyway.
Change-Id: I58ea0a5421987fb69f93cc56252a771e9c34147e
As logging macros uses `if xxx else yyy` style, it is reported as an
error when DCHECK() is compiled with -Wdangling-else option. Because
after preprocess, DCHECK(x) becomes:
if (EnableDChecks)
if (x)
;
else
LogMessage(FATAL) << yyy;
This CL avoids compilation error by replacing `if xxx else yyy`
with `xxx && yyy` or `!(xxx) || yyy`.
Bug: 26962895
Change-Id: Ib0bf242cc04a238ec31a1ab66b53fc8a5b5ed28f
Also use ReadFully to replace read, because read can
return reading bytes less than requested. And use
WriteFully to replace write.
Bug: 26962895
Change-Id: Iff0b2bc6d925619a537f7fef682c2a7ad89a2dc2
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.
android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.
libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.
Bug: 26957718
Change-Id: I4e43e7cf18a96f22b3a9a08dbab8c3e960c12930
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.
The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.
Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.
libbase seemed like the right choice because:
1. It already has some parsing functions (parseint)
2. The net address parsing function uses the libbase string
functions so we have a libbase dependency anyway.
The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.
For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.
Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
unique_fds are wrappers for integer file descriptors that automatically
close when they go out of scope. They are movable but not copyable and
generally mimic the semantics of std::unique_ptr
Change-Id: I0657b848b6536d5ad9fc06686e240ea5c387b0ac
Test: Considerable exercise in new AIDL integration tests
Bug: None
Signed-off-by: Casey Dahlin <sadmac@google.com>
Now that we have a more standardized API (also available in Chromium),
switch to it. Another benefit is real error handling instead of just
killing the process on invalid Unicode.
Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is
the same error code that wcsrtombs(3) uses.
Update the unittest to check for EILSEQ.
Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
This reverts commit cc8cd59456.
With the dependency on libcutils (for gettid for non-bionic) removed,
this no longer breaks the build.
Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
ae5a6c06cd made adb push use
android::base::ReadFileToString() for small files, but that API did not
support UTF-8 filenames on Windows, until this fix which does the
following:
- Add android::base::{WideToUTF8,UTF8ToWide}() which are only available
on Windows. The signatures are based on Chromium's APIs of the same
name.
- Add the namespace android::base::utf8 which has versions of APIs that
take UTF-8 strings. To use this, make sure your code is in a namespace
and then do "using namespace android::base::utf8;". On Windows, this will
make calls to open() call android::base::utf8::open(), and on other
platforms, it will just call the regular ::open().
- Make ReadFileToString() and WriteStringToFile() use utf8::open() and
utf8::unlink().
- Adapt unittests from Chromium.
- fastboot needs to link with libcutils because it links with libbase
which depends on libcutils for gettid() for logging.
Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
I've been using these changes to compile with Visual Studio.
- GetFileBasename(): __FILE__ uses \ with Visual Studio.
- adb_trace.cpp: Apparently VS needs an ampersand before the function name.
- "expr1 ? : expr2" is a GCC extension.
- <algorithm> contains std::min().
- seekdir can't always be #define'd because some headers have members
named seekdir.
- adb_utils.cpp: Not really a compiler issue, just a random fix:
0x7F/DEL is not printable.
Change-Id: I0dfb634f1ba4ccbc0d1b9f71b00e838fbebb3b41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
We've needed this several times in the past.
Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2
Test: Full android build
Signed-off-by: Casey Dahlin <sadmac@google.com>
Fix LOG() to properly save and restore errno. Test this properly.
Only do logging if severity is >= the minimum.
Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this
properly.
Fix base logging tests on Windows. All libbase_tests now pass on
Windows.
Change place to lock, so the lock can protect logging of all data in
LogMessage.
Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Add to whitelist.
For some reason, when compiling, parseint_test.cpp would encounter
errors like the following:
host cross C++: host_cross_libbase_test <= system/core/base/parseint_test.cpp
In file included from external/gtest/include/gtest/gtest.h:1929:0,
from system/core/base/parseint_test.cpp:19:
system/core/base/parseint_test.cpp: In member function ‘virtual void parseint_signed_smoke_Test::TestBody()’:
external/gtest/include/gtest/internal/gtest-internal.h:133:55: error: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Werror=conversion-null]
(sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
^
external/gtest/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro ‘GTEST_ASSERT_’
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^
external/gtest/include/gtest/gtest_pred_impl.h:166:3: note: in expansion of macro ‘GTEST_PRED_FORMAT2_’
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^
external/gtest/include/gtest/gtest.h:1993:3: note: in expansion of macro ‘ASSERT_PRED_FORMAT2’
ASSERT_PRED_FORMAT2(::testing::internal:: \
^
external/gtest/include/gtest/gtest.h:1994:32: note: in expansion of macro ‘GTEST_IS_NULL_LITERAL_’
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
^
external/gtest/include/gtest/gtest.h:2011:32: note: in expansion of macro ‘GTEST_ASSERT_EQ’
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^
system/core/base/parseint_test.cpp:23:3: note: in expansion of macro ‘ASSERT_EQ’
ASSERT_EQ(false, android::base::ParseInt("x", &i));
^
For whatever reason, the gcc for Windows isn't handling the template
metaprogramming correctly, so to work-around the issue, I
search-and-replaced "ASSERT_EQ(false, " to "ASSERT_FALSE(" and
"ASSERT_EQ(true, " to "ASSERT_TRUE(" and that seems to compile just fine
for Linux and Windows (and the tests pass on both platforms).
Change-Id: I05132909d1f4b18afff23139652a218649689f2d
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.
Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
This matches the behavior of the google3/Chrome APIs. It's probably what you
want in all cases except where you plan on calling Split(content, "\n"), but
we should probably have something like simpleperf's LineReader for that
anyway.
Change-Id: I1a128ed8c328bc95b0b2ef4068a65a8562721418
Win32:
- getprogname(): call basename() which is available in mingw's crt.
Don't potentially go recursive with DCHECK_GT().
- Use Win32 critical section instead of mutex.
Other:
- Change log_characters check to compile-time.
- Fix code that gets the basename of __FILE__. The previous code was not
setting _file, so it didn't work.
- Save and restore errno for LOG calls. Inspired by similar Chromium code.
Change-Id: Ie7bb700918be726fa81d60177d1894d2daeff296
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>