mirror of
https://github.com/boostorg/stacktrace.git
synced 2026-01-29 08:02:09 +00:00
Compare commits
5 Commits
boost-1.67
...
boost-1.68
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fedfa1265 | ||
|
|
4a5471a239 | ||
|
|
e4e2d4c3c1 | ||
|
|
14852ad597 | ||
|
|
87b4789289 |
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,8 +13,9 @@
|
||||
#endif
|
||||
|
||||
#include <boost/stacktrace/detail/to_hex_array.hpp>
|
||||
#include <boost/stacktrace/detail/to_dec_array.hpp>
|
||||
#include <boost/stacktrace/detail/try_dec_convert.hpp>
|
||||
#include <boost/core/demangle.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -212,7 +213,7 @@ std::size_t frame::source_line() const {
|
||||
}
|
||||
res = res.substr(last + 1);
|
||||
|
||||
if (!boost::conversion::try_lexical_convert(res, line_num)) {
|
||||
if (!boost::stacktrace::detail::try_dec_convert(res.c_str(), line_num)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <boost/core/demangle.hpp>
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/stacktrace/detail/to_dec_array.hpp>
|
||||
#include <boost/stacktrace/detail/to_hex_array.hpp>
|
||||
#include <windows.h>
|
||||
#include "dbgeng.h"
|
||||
@@ -329,7 +329,7 @@ public:
|
||||
res += " at ";
|
||||
res += source_line.first;
|
||||
res += ':';
|
||||
res += boost::lexical_cast<boost::array<char, 40> >(source_line.second).data();
|
||||
res += boost::stacktrace::detail::to_dec_array(source_line.second).data();
|
||||
} else if (!module_name.empty()) {
|
||||
res += " in ";
|
||||
res += module_name;
|
||||
@@ -349,7 +349,7 @@ std::string to_string(const frame* frames, std::size_t size) {
|
||||
if (i < 10) {
|
||||
res += ' ';
|
||||
}
|
||||
res += boost::lexical_cast<boost::array<char, 40> >(i).data();
|
||||
res += boost::stacktrace::detail::to_dec_array(i).data();
|
||||
res += '#';
|
||||
res += ' ';
|
||||
idebug.to_string_impl(frames[i].address(), res);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
#include <boost/stacktrace/detail/to_hex_array.hpp>
|
||||
#include <boost/stacktrace/detail/location_from_symbol.hpp>
|
||||
#include <boost/stacktrace/detail/to_dec_array.hpp>
|
||||
#include <boost/core/demangle.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
@@ -67,7 +67,7 @@ std::string to_string(const frame* frames, std::size_t size) {
|
||||
if (i < 10) {
|
||||
res += ' ';
|
||||
}
|
||||
res += boost::lexical_cast<boost::array<char, 40> >(i).data();
|
||||
res += boost::stacktrace::detail::to_dec_array(i).data();
|
||||
res += '#';
|
||||
res += ' ';
|
||||
res += impl(frames[i].address());
|
||||
@@ -84,7 +84,7 @@ std::string to_string(const frame* frames, std::size_t size) {
|
||||
std::string frame::name() const {
|
||||
#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
|
||||
::Dl_info dli;
|
||||
const bool dl_ok = !!::dladdr(addr_, &dli);
|
||||
const bool dl_ok = !!::dladdr(const_cast<void*>(addr_), &dli); // `dladdr` on Solaris accepts nonconst addresses
|
||||
if (dl_ok && dli.dli_sname) {
|
||||
return boost::core::demangle(dli.dli_sname);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,9 +13,9 @@
|
||||
#endif
|
||||
|
||||
#include <boost/stacktrace/detail/to_hex_array.hpp>
|
||||
#include <boost/stacktrace/detail/to_dec_array.hpp>
|
||||
#include <boost/stacktrace/detail/location_from_symbol.hpp>
|
||||
#include <boost/core/demangle.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <backtrace.h>
|
||||
|
||||
@@ -99,7 +99,7 @@ struct to_string_using_backtrace {
|
||||
res += " at ";
|
||||
res += filename;
|
||||
res += ':';
|
||||
res += boost::lexical_cast<boost::array<char, 40> >(line).data();
|
||||
res += boost::stacktrace::detail::to_dec_array(line).data();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT
|
||||
: dli_()
|
||||
{
|
||||
if (!::dladdr(addr, &dli_)) {
|
||||
if (!::dladdr(const_cast<void*>(addr), &dli_)) { // `dladdr` on Solaris accepts nonconst addresses
|
||||
dli_.dli_fname = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
46
include/boost/stacktrace/detail/to_dec_array.hpp
Normal file
46
include/boost/stacktrace/detail/to_dec_array.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP
|
||||
#define BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/array.hpp>
|
||||
|
||||
namespace boost { namespace stacktrace { namespace detail {
|
||||
|
||||
// We do not use boost::lexical_cast in this function to reduce module dependencies
|
||||
inline boost::array<char, 40> to_dec_array(std::size_t value) BOOST_NOEXCEPT {
|
||||
boost::array<char, 40> ret;
|
||||
if (!value) {
|
||||
ret[0] = '0';
|
||||
ret[1] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::size_t digits = 0;
|
||||
for (std::size_t value_copy = value; value_copy; value_copy /= 10) {
|
||||
++ digits;
|
||||
}
|
||||
|
||||
for (std::size_t i = 1; i <= digits; ++i) {
|
||||
ret[digits - i] = '0' + (value % 10);
|
||||
value /= 10;
|
||||
}
|
||||
|
||||
ret[digits] = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
#endif // BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
29
include/boost/stacktrace/detail/try_dec_convert.hpp
Normal file
29
include/boost/stacktrace/detail/try_dec_convert.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP
|
||||
#define BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace boost { namespace stacktrace { namespace detail {
|
||||
|
||||
// We do not use boost::lexical_cast in this function to reduce module dependencies
|
||||
inline bool try_dec_convert(const char* s, std::size_t& res) BOOST_NOEXCEPT {
|
||||
char* end_ptr = 0;
|
||||
res = std::strtoul(s, &end_ptr, 10);
|
||||
return *end_ptr == '\0';
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
#endif // BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright Antony Polukhin, 2016-2017.
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2015-2017 Antony Polukhin.
|
||||
// Copyright 2015-2018 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"Antony Polukhin <antoshkka -at- gmail.com>"
|
||||
],
|
||||
"description": "Gather, store, copy and print backtraces.",
|
||||
"std": [ "proposal" ],
|
||||
"category": [
|
||||
"System", "Correctness"
|
||||
]
|
||||
|
||||
@@ -182,6 +182,7 @@ test-suite stacktrace_tests
|
||||
: windbg_cached_lib_threaded_com_st ]
|
||||
|
||||
[ run test_void_ptr_cast.cpp ]
|
||||
[ run test_num_conv.cpp ]
|
||||
;
|
||||
|
||||
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.
|
||||
|
||||
71
test/test_num_conv.cpp
Normal file
71
test/test_num_conv.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright Antony Polukhin, 2016-2018.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/stacktrace/detail/to_dec_array.hpp>
|
||||
#include <boost/stacktrace/detail/to_hex_array.hpp>
|
||||
#include <boost/stacktrace/detail/try_dec_convert.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void test_to_hex_array() {
|
||||
const void* ptr = 0;
|
||||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("0x0") != std::string::npos);
|
||||
|
||||
ptr = reinterpret_cast<const void*>(0x10);
|
||||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("10") != std::string::npos);
|
||||
|
||||
ptr = reinterpret_cast<void*>(0x19);
|
||||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("19") != std::string::npos);
|
||||
|
||||
ptr = reinterpret_cast<void*>(0x999999);
|
||||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("999999") != std::string::npos);
|
||||
}
|
||||
|
||||
void test_to_dec_array() {
|
||||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(0).data()), std::string("0"));
|
||||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(10).data()), std::string("10"));
|
||||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(19).data()), std::string("19"));
|
||||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(999999).data()), std::string("999999"));
|
||||
}
|
||||
|
||||
void test_try_dec_convert() {
|
||||
std::size_t res = 0;
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("0", res));
|
||||
BOOST_TEST(res == 0);
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+0", res));
|
||||
BOOST_TEST(res == 0);
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("10", res));
|
||||
BOOST_TEST(res == 10);
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("19", res));
|
||||
BOOST_TEST(res == 19);
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+19", res));
|
||||
BOOST_TEST(res == 19);
|
||||
|
||||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("9999", res));
|
||||
BOOST_TEST(res == 9999);
|
||||
|
||||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("q", res));
|
||||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0z", res));
|
||||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0u", res));
|
||||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("+0u", res));
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
test_to_hex_array();
|
||||
test_to_dec_array();
|
||||
test_try_dec_convert();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user