<commit_before>/*
 * Copyright 2013 <NAME>
 *
 * 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.
 */

#include <q/pp.hpp>
#include <q/abi.hpp>

#ifdef LIBQ_ON_ANDROID

#include "stacktrace.hpp"

#include <unwind.h>
#include <dlfcn.h>

namespace q { namespace detail {

stacktrace default_stacktrace( ) noexcept
{
	static const std::size_t buflen = 128;
	struct stack {
		std::size_t size = 0;
		void* addresses[ buflen ];
	};
	stack s;

	_Unwind_Backtrace( [ ]( struct _Unwind_Context* context, void* arg)
	{
		uintptr_t pc = _Unwind_GetIP( context );
		stack* s = static_cast< stack* >( arg );
		if ( pc )
		{
			if ( s->size == buflen )
				return _URC_END_OF_STACK;
			s->addresses[ s->size++ ] =
				reinterpret_cast< void* >( pc );
		}
		return _URC_NO_REASON;
	}, &s );

	std::vector< stacktrace::frame > frames;
	frames.reserve( s.size );

	for ( std::size_t i = 0; i < s.size; ++i )
	{
		stacktrace::frame frame;
		Dl_info info;
		if ( dladdr( s.addresses[ i ], &info ) && info.dli_sname )
			frame.symbol = info.dli_sname;
		frame.addr =
			reinterpret_cast< std::uint64_t >( s.addresses[ i ] );
		frame.frameno = i;
		frames.push_back( frame );<commit_msg>stacktrace: demangling of function names for android<commit_after>/*
 * Copyright 2013 <NAME>
 *
 * 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.
 */

#include <q/pp.hpp>
#include <q/abi.hpp>

#ifdef LIBQ_ON_ANDROID

#include "stacktrace.hpp"

#include <unwind.h>
#include <dlfcn.h>

namespace q { namespace detail {

stacktrace default_stacktrace( ) noexcept
{
	static const std::size_t buflen = 128;
	struct stack {
		std::size_t size = 0;
		void* addresses[ buflen ];
	};
	stack s;

	_Unwind_Backtrace( [ ]( struct _Unwind_Context* context, void* arg)
	{
		uintptr_t pc = _Unwind_GetIP( context );
		stack* s = static_cast< stack* >( arg );
		if ( pc )
		{
			if ( s->size == buflen )
				return _URC_END_OF_STACK;
			s->addresses[ s->size++ ] =
				reinterpret_cast< void* >( pc );
		}
		return _URC_NO_REASON;
	}, &s );

	std::vector< stacktrace::frame > frames;
	frames.reserve( s.size );

	for ( std::size_t i = 0; i < s.size; ++i )
	{
		stacktrace::frame frame;
		Dl_info info;
		if ( dladdr( s.addresses[ i ], &info ) && info.dli_sname )
			frame.symbol = info.dli_sname;
		auto demanged = demangle_cxx( frame.symbol.c_str( ) );
		if ( !demanged.empty( ) )
			frame.symbol = demanged;
		frame.addr =
			reinterpret_cast< std::uint64_t >( s.addresses[ i ] );
		frame.frameno = i;
		frames.push_back( frame );
{'fraction_non_alphanumeric': 0.12342135476463835, 'fraction_numerical': 0.008610792192881744, 'mean_word_length': 3.652870493991989, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5701641', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1210, 'n_words': 372}