-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include <dali/public-api/common/dali-common.h>
#include <stdlib.h>
#include <string>
#include <cstdio>
-#include <execinfo.h>
-#ifndef EMSCRIPTEN // cxxabi not supported
-# include <cxxabi.h>
+#if defined(BACKTRACE_ENABLED)
+#if defined(__GLIBC__)
+#include <execinfo.h>
+#endif
+#include <cxxabi.h>
#endif
-
#include <cstring>
// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
-namespace
-{
-const int MAX_NUM_STACK_FRAMES = 25;
-const size_t C_SYMBOL_LENGTH = 4096;
-}
-
namespace Dali
{
-#ifndef EMSCRIPTEN
+#if defined(BACKTRACE_ENABLED)
+
+namespace
+{
+const int32_t MAX_NUM_STACK_FRAMES = 25;
+}
std::string Demangle(const char* symbol)
{
size_t tokenLength = endOfToken - startOfToken;
// Allocate space for symbol
- char *mangledSymbol = (char*)malloc(tokenLength+1u);
- strncpy(mangledSymbol, startOfToken, tokenLength);
- mangledSymbol[tokenLength] = '\0';
-
- size_t size;
- int status;
- char* demangled=NULL;
- demangled = abi::__cxa_demangle( mangledSymbol, NULL, &size, &status );
- if( demangled != NULL )
+ char *mangledSymbol = reinterpret_cast< char* >( malloc( tokenLength + 1u ) );
+ if(mangledSymbol != NULL)
{
- result = demangled;
- free(demangled); // demangle() allocates returned string, so free it
+ strncpy(mangledSymbol, startOfToken, tokenLength);
+ mangledSymbol[tokenLength] = '\0';
+
+ size_t size;
+ int32_t status;
+ char* demangled=NULL;
+ demangled = abi::__cxa_demangle( mangledSymbol, NULL, &size, &status );
+ if( demangled != NULL )
+ {
+ result = demangled;
+ free(demangled); // demangle() allocates returned string, so free it
+ }
+ else
+ {
+ result = symbol;
+ }
+ free(mangledSymbol);
}
- else
- {
- result = symbol;
- }
- free(mangledSymbol);
}
}
return result;
}
-#endif // EMSCRIPTEN
-
-#ifndef EMSCRIPTEN
-
-DALI_EXPORT_API DaliException::DaliException(const char *location, const char* condition)
-: mLocation(location), mCondition(condition)
+DALI_CORE_API DaliException::DaliException( const char* location, const char* condition )
+: location( location ), condition( condition )
{
// Note, if a memory error has occured, then the backtrace won't work - backtrace_symbols relies on
// allocating memory.
// Initial dlog error message is output in DALI_ASSERT_ALWAYS macro
// Also output on stderr
- fprintf(stderr, "Exception: \n%s\n thrown at %s\nSee dlog for backtrace\n", mCondition.c_str(), mLocation.c_str());
+#if defined(DEBUG_ENABLED)
+ fprintf(stderr, "Exception: \n%s\n thrown at %s\nSee dlog for backtrace\n", condition, location);
+#else
+ fprintf(stderr, "Exception: \n%s\n thrown\nSee dlog for backtrace\n", condition );
+#endif
DALI_LOG_ERROR_NOFN("Backtrace:\n");
void* frameArray[MAX_NUM_STACK_FRAMES];
- int nSize = backtrace(frameArray, MAX_NUM_STACK_FRAMES);
+ int32_t nSize = backtrace(frameArray, MAX_NUM_STACK_FRAMES);
char** symbols = backtrace_symbols(frameArray, nSize);
- for(int i=1; i< nSize; i++)
+ for(int32_t i=1; i< nSize; i++)
{
std::string demangled_symbol = Demangle(symbols[i]);
DALI_LOG_ERROR_NOFN("[%02d] %s\n", i, demangled_symbol.c_str() );
free(symbols);
}
-#else
-DALI_EXPORT_API DaliException::DaliException(const char *location, const char* condition)
-: mLocation(location), mCondition(condition)
+#else // BACKTRACE_ENABLED
+
+DALI_CORE_API DaliException::DaliException( const char* location, const char* condition )
+: location( location ), condition( condition )
{
- printf("Exception: \n%s\n thrown at %s\nSee dlog for backtrace\n", mCondition.c_str(), mLocation.c_str());
+#if defined(DEBUG_ENABLED)
+ printf("Exception: \n%s\n thrown at %s\n", condition, location );
+#else
+ printf("Exception: \n%s\n thrown\n", condition );
+#endif
}
-#endif // EMSCRIPTEN
-DALI_EXPORT_API void DaliAssertMessage(const char* condition, const char* file, int line)
+#endif // BACKTRACE_ENABLED
+
+DALI_CORE_API void DaliAssertMessage( const char* location, const char* condition )
{
- DALI_LOG_ERROR_NOFN( "Assertion (%s) failed in: %s:%d\n", condition, file, line );
+#if defined(DEBUG_ENABLED)
+ DALI_LOG_ERROR_NOFN( "Assert (%s) failed in: %s\n", condition, location );
+#else
+ DALI_LOG_ERROR_NOFN( "Assert (%s) failed\n", condition );
+#endif
}
} // Dali