Diff
Modified: trunk/Source/bmalloc/ChangeLog (201968 => 201969)
--- trunk/Source/bmalloc/ChangeLog 2016-06-11 11:20:23 UTC (rev 201968)
+++ trunk/Source/bmalloc/ChangeLog 2016-06-11 11:46:19 UTC (rev 201969)
@@ -1,3 +1,25 @@
+2016-06-11 David Kilzer <[email protected]>
+
+ Implement logging for RELEASE_BASSERT_WITH_MESSAGE() in BAssert.h
+ <http://webkit.org/b/155992>
+
+ Reviewed by Geoff Garen.
+
+ * bmalloc/BAssert.h:
+ (BLOG_ERROR): Add method to always log error messages.
+ (RELEASE_BASSERT_WITH_MESSAGE): Use BLOG_ERROR() to implement
+ logging in Debug builds.
+ * bmalloc/BPlatform.h:
+ (BPLATFORM_MAC): Add.
+ (BUSE): Add BUSE() macro.
+ (BATTRIBUTE_PRINTF): Add.
+ (BUSE_OS_LOG): Add.
+ * bmalloc/Logging.cpp:
+ (bmalloc::reportAssertionFailureWithMessage): Add. Logs to
+ stderr.
+ * bmalloc/Logging.h:
+ (bmalloc::reportAssertionFailureWithMessage): Add declaration.
+
2016-06-07 Pranjal Jumde <[email protected]>
Prevents integer overflow in Vector.h
Modified: trunk/Source/bmalloc/bmalloc/BAssert.h (201968 => 201969)
--- trunk/Source/bmalloc/bmalloc/BAssert.h 2016-06-11 11:20:23 UTC (rev 201968)
+++ trunk/Source/bmalloc/bmalloc/BAssert.h 2016-06-11 11:46:19 UTC (rev 201969)
@@ -20,14 +20,18 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef BAssert_h
-#define BAssert_h
+#pragma once
#include "BPlatform.h"
+#include "Logging.h"
+#if BUSE(OS_LOG)
+#include <os/log.h>
+#endif
+
#if defined(NDEBUG) && BOS(DARWIN)
#if BCPU(X86_64) || BCPU(X86)
@@ -63,11 +67,26 @@
#define RELEASE_BASSERT(x) BASSERT_IMPL(x)
-// FIXME: Implement logging: <https://webkit.org/b/155992>
-#define RELEASE_BASSERT_WITH_MESSAGE(x, f, ...) BASSERT_IMPL(x)
+#if BUSE(OS_LOG)
+#define BMALLOC_LOGGING_PREFIX "bmalloc: "
+#define BLOG_ERROR(format, ...) os_log_error(OS_LOG_DEFAULT, BMALLOC_LOGGING_PREFIX format, __VA_ARGS__)
+#else
+#define BLOG_ERROR(format, ...) bmalloc::reportAssertionFailureWithMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__, format, __VA_ARGS__)
+#endif
-#define UNUSED(x) (void)x
+#if defined(NDEBUG)
+#define RELEASE_BASSERT_WITH_MESSAGE(x, format, ...) BASSERT_IMPL(x)
+#else
+#define RELEASE_BASSERT_WITH_MESSAGE(x, format, ...) do { \
+ if (!(x)) { \
+ BLOG_ERROR("ASSERTION FAILED: " #x " :: " format, ##__VA_ARGS__); \
+ BCRASH(); \
+ } \
+} while (0);
+#endif
+#define UNUSED(x) ((void)x)
+
// ===== Release build =====
#if defined(NDEBUG)
@@ -85,8 +104,6 @@
#define BASSERT(x) BASSERT_IMPL(x)
-#define IF_DEBUG(x) x
+#define IF_DEBUG(x) (x)
#endif // !defined(NDEBUG)
-
-#endif // BAssert_h
Modified: trunk/Source/bmalloc/bmalloc/BPlatform.h (201968 => 201969)
--- trunk/Source/bmalloc/bmalloc/BPlatform.h 2016-06-11 11:20:23 UTC (rev 201968)
+++ trunk/Source/bmalloc/bmalloc/BPlatform.h 2016-06-11 11:46:19 UTC (rev 201969)
@@ -23,22 +23,17 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef BPlatform_h
-#define BPlatform_h
+#pragma once
#ifdef __APPLE__
+#include <Availability.h>
+#include <AvailabilityMacros.h>
#include <TargetConditionals.h>
#endif
#define BPLATFORM(PLATFORM) (defined BPLATFORM_##PLATFORM && BPLATFORM_##PLATFORM)
#define BOS(OS) (defined BOS_##OS && BOS_##OS)
-#if ((defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) \
- || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) \
- || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR))
-#define BPLATFORM_IOS 1
-#endif
-
#ifdef __APPLE__
#define BOS_DARWIN 1
#endif
@@ -47,6 +42,19 @@
#define BOS_UNIX 1
#endif
+#if BOS(DARWIN) && ((defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) \
+ || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) \
+ || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR))
+#define BPLATFORM_IOS 1
+#elif BOS(DARWIN) && defined(TARGET_OS_MAC) && TARGET_OS_MAC
+#define BPLATFORM_MAC 1
+#endif
+
+/* ==== Policy decision macros: these define policy choices for a particular port. ==== */
+
+/* BUSE() - use a particular third-party library or optional OS service */
+#define BUSE(FEATURE) (defined BUSE_##FEATURE && BUSE_##FEATURE)
+
/* ==== Platform adaptation macros: these describe properties of the target environment. ==== */
/* BCPU() - the target CPU architecture */
@@ -181,4 +189,8 @@
#endif /* ARM */
-#endif // BPlatform_h
+#define BATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments)))
+
+#if (BPLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (BPLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000)
+#define BUSE_OS_LOG 1
+#endif
Modified: trunk/Source/bmalloc/bmalloc/Logging.cpp (201968 => 201969)
--- trunk/Source/bmalloc/bmalloc/Logging.cpp 2016-06-11 11:20:23 UTC (rev 201968)
+++ trunk/Source/bmalloc/bmalloc/Logging.cpp 2016-06-11 11:46:19 UTC (rev 201969)
@@ -26,6 +26,11 @@
#include "Logging.h"
#include "BPlatform.h"
+#if !BUSE(OS_LOG)
+#include <stdarg.h>
+#include <stdio.h>
+#endif
+
#if BPLATFORM(IOS)
#include <mach/exception_types.h>
#include <objc/objc.h>
@@ -46,4 +51,15 @@
#endif
}
+#if !BUSE(OS_LOG)
+void reportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ fprintf(stderr, "%s(%d) : %s\n", file, line, function);
+}
+#endif
+
} // namespace bmalloc
Modified: trunk/Source/bmalloc/bmalloc/Logging.h (201968 => 201969)
--- trunk/Source/bmalloc/bmalloc/Logging.h 2016-06-11 11:20:23 UTC (rev 201968)
+++ trunk/Source/bmalloc/bmalloc/Logging.h 2016-06-11 11:46:19 UTC (rev 201969)
@@ -23,13 +23,16 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef Logging_h
-#define Logging_h
+#pragma once
+#include "BPlatform.h"
+
namespace bmalloc {
void logVMFailure();
+#if !BUSE(OS_LOG)
+void reportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* format, ...) BATTRIBUTE_PRINTF(4, 5);
+#endif
+
} // namespace bmalloc
-
-#endif // Logging_h