Code Monkey home page Code Monkey logo

backward-cpp's Introduction

Backward-cpp Conan Center

Backward is a beautiful stack trace pretty printer for C++.

If you are bored to see this:

default trace

Backward will spice it up for you:

pretty stackstrace

There is not much to say. Of course it will be able to display the code snippets only if the source files are accessible (else see trace #4 in the example).

All "Source" lines and code snippet prefixed by a pipe "|" are frames inline the next frame. You can see that for the trace #1 in the example, the function you_shall_not_pass() was inlined in the function ...read2::do_test() by the compiler.

Installation

Install backward.hpp

Backward is a header only library. So installing Backward is easy, simply drop a copy of backward.hpp along with your other source files in your C++ project. You can also use a git submodule or really any other way that best fits your environment, as long as you can include backward.hpp.

Install backward.cpp

If you want Backward to automatically print a stack trace on most common fatal errors (segfault, abort, un-handled exception...), simply add a copy of backward.cpp to your project, and don't forget to tell your build system.

The code in backward.cpp is trivial anyway, you can simply copy what it's doing at your convenience.

Note for folly library users: must define backward::SignalHandling sh; after folly::init(&argc, &argv);.

Configuration & Dependencies

Integration with CMake

If you are using CMake and want to use its configuration abilities to save you the trouble, you can easily integrate Backward, depending on how you obtained the library.

Notice that all approaches are equivalent in the way Backward is added to a CMake target, the difference is in how CMake is pointed to the Backward sources. Backward defines three targets:

  • Backward::Interface is an interface target that brings compiler definition flags, include directory, and external libraries. This is all you need to use the backward.hpp header library.
  • Backward::Object brings Backward::Interface and backward.cpp as an OBJECT CMake library. This target cannot be exported, so it is not available when Backward is used via find_package.
  • Backward::Backward brings Backward::Interface and backward.cpp as either STATIC or SHARED library (depending on the BACKWARD_SHARED option). This target is exported and always available, however note that the linker will not include unused objects from a static library, unless the -Wl,--whole-archive option (or similar) is used.

With FetchContent():

If you are using a recent version of CMake, you can integrate backward via FetchContent like below:

include(FetchContent)

# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
FetchContent_Declare(backward
    GIT_REPOSITORY https://github.com/bombela/backward-cpp
    GIT_TAG master  # or a version tag, such as v1.6
    SYSTEM          # optional, the Backward include directory will be treated as system directory
)
FetchContent_MakeAvailable(backward)

# Add Backward to your target (either Backward::Interface, Backward::Object, or Backward::Backward)
target_link_libraries(mytarget PUBLIC Backward::Interface)

As a subdirectory:

In this case you have a subdirectory containing the whole repository of Backward (e.g. using git-submodule), in this case you can do:

add_subdirectory(/path/to/backward-cpp)

# Add Backward to your target (either Backward::Interface, Backward::Object, or Backward::Backward)
target_link_libraries(mytarget PUBLIC Backward::Interface)

Modifying CMAKE_MODULE_PATH:

In this case you can have Backward installed as a subdirectory:

list(APPEND CMAKE_MODULE_PATH /path/to/backward-cpp)
find_package(Backward)

# Add Backward to your target (either Backward::Interface or Backward::Backward)
target_link_libraries(mytarget PUBLIC Backward::Interface)

Installation through a regular package manager

In this case you have obtained Backward through a package manager.

Packages currently available:

find_package(Backward)

# Add Backward to your target (either Backward::Interface or Backward::Backward)
target_link_libraries(mytarget PUBLIC Backward::Interface)

Libraries to unwind the stack

On Linux and macOS, backtrace can back-trace or "walk" the stack using the following libraries:

unwind

Unwind comes from libgcc, but there is an equivalent inside clang itself. With unwind, the stacktrace is as accurate as it can possibly be, since this is used by the C++ runtine in gcc/clang for stack unwinding on exception.

Normally libgcc is already linked to your program by default.

libunwind from the libunwind project

apt-get install binutils-dev (or equivalent)

Libunwind provides, in some cases, a more accurate stacktrace as it knows to decode signal handler frames and lets us edit the context registers when unwinding, allowing stack traces over bad function references.

For best results make sure you are using libunwind 1.3 or later, which added unw_init_local2 and support for handling signal frames.

CMake will warn you when configuring if your libunwind version doesn't support signal frames.

On macOS clang provides a libunwind API compatible library as part of its environment, so no third party libraries are necessary.

Compile with debug info

You need to compile your project with generation of debug symbols enabled, usually -g with clang++ and g++.

Note that you can use -g with any level of optimization, with modern debug information encoding like DWARF, it only takes space in the binary (it's not loaded in memory until your debugger or Backward makes use of it, don't worry), and it doesn't impact the code generation (at least on GNU/Linux x86_64 for what I know).

If you are missing debug information, the stack trace will lack details about your sources.

Libraries to read the debug info

Backward supports pretty printed stack traces on GNU/Linux, macOS and Windows, it will compile fine under other platforms but will not do anything. Pull requests are welcome :)

Also, by default you will get a really basic stack trace, based on the backtrace_symbols API:

default trace

You will need to install some dependencies to get the ultimate stack trace. Three libraries are currently supported, the only difference is which one is the easiest for you to install, so pick your poison:

libbfd from the GNU/binutils

apt-get install binutils-dev (or equivalent)

And do not forget to link with the lib: g++/clang++ -lbfd -ldl ...

This library requires dynamic loading. Which is provided by the library dl. Hence why we also link with -ldl.

Then define the following before every inclusion of backward.hpp (don't forget to update backward.cpp as well):

#define BACKWARD_HAS_BFD 1

libdw from the elfutils

apt-get install libdw-dev (or equivalent)

And do not forget to link with the lib and inform Backward to use it:

#define BACKWARD_HAS_DW 1

Of course you can simply add the define (-DBACKWARD_HAS_...=1) and the linkage details in your build system and even auto-detect which library is installed, it's up to you.

apt-get install libdwarf-dev (or equivalent)

And do not forget to link with the lib and inform Backward to use it:

#define BACKWARD_HAS_DWARF 1

There are several alternative implementations of libdwarf and libelf that are API compatible so it's possible, although it hasn't been tested, to replace the ones used when developing backward (in bold, below):

Of course you can simply add the define (-DBACKWARD_HAS_...=1) and the linkage details in your build system and even auto-detect which library is installed, it's up to you.

That's it, you are all set, you should be getting nice stack traces like the one at the beginning of this document.

API

If you don't want to limit yourself to the defaults offered by backward.cpp, and you want to take some random stack traces for whatever reason and pretty print them the way you love or you decide to send them all to your buddies over the Internet, you will appreciate the simplicity of Backward's API.

Stacktrace

The StackTrace class lets you take a "snapshot" of the current stack. You can use it like this:

using namespace backward;
StackTrace st; st.load_here(32);
Printer p; p.print(st);

The public methods are:

class StackTrace { public:
	// Take a snapshot of the current stack, with at most "trace_cnt_max"
	// traces in it. The first trace is the most recent (ie the current
	// frame). You can also provide a trace address to load_from() assuming
	// the address is a valid stack frame (useful for signal handling traces).
	// Both function return size().
	size_t load_here(size_t trace_cnt_max)
	size_t load_from(void* address, size_t trace_cnt_max)

	// The number of traces loaded. This can be less than "trace_cnt_max".
	size_t size() const

	// A unique id for the thread in which the trace was taken. The value
	// 0 means the stack trace comes from the main thread.
	size_t thread_id() const

	// Retrieve a trace by index. 0 is the most recent trace, size()-1 is
	// the oldest one.
	Trace operator[](size_t trace_idx)
};

TraceResolver

The TraceResolver does the heavy lifting, and intends to transform a simple Trace from its address into a fully detailed ResolvedTrace with the filename of the source, line numbers, inlined functions and so on.

You can use it like this:

using namespace backward;
StackTrace st; st.load_here(32);

TraceResolver tr; tr.load_stacktrace(st);
for (size_t i = 0; i < st.size(); ++i) {
	ResolvedTrace trace = tr.resolve(st[i]);
	std::cout << "#" << i
		<< " " << trace.object_filename
		<< " " << trace.object_function
		<< " [" << trace.addr << "]"
	<< std::endl;
}

The public methods are:

class TraceResolver { public:
	// Pre-load whatever is necessary from the stack trace.
	template <class ST>
		void load_stacktrace(ST&)

	// Resolve a trace. It takes a ResolvedTrace, because a `Trace` is
	// implicitly convertible to it.
	ResolvedTrace resolve(ResolvedTrace t)
};

SnippetFactory

The SnippetFactory is a simple helper class to automatically load and cache source files in order to extract code snippets.

class SnippetFactory { public:
	// A snippet is a list of line numbers and line contents.
	typedef std::vector<std::pair<size_t, std::string> > lines_t;

	// Return a snippet starting at line_start with up to context_size lines.
	lines_t get_snippet(const std::string& filename,
			size_t line_start, size_t context_size)

	// Return a combined snippet from two different locations and combine them.
	// context_size / 2 lines will be extracted from each location.
	lines_t get_combined_snippet(
			const std::string& filename_a, size_t line_a,
			const std::string& filename_b, size_t line_b,
			size_t context_size)

	// Tries to return a unified snippet if the two locations from the same
	// file are close enough to fit inside one context_size, else returns
	// the equivalent of get_combined_snippet().
	lines_t get_coalesced_snippet(const std::string& filename,
			size_t line_a, size_t line_b, size_t context_size)

Printer

A simpler way to pretty print a stack trace to the terminal. It will automatically resolve the traces for you:

using namespace backward;
StackTrace st; st.load_here(32);
Printer p;
p.object = true;
p.color_mode = ColorMode::always;
p.address = true;
p.print(st, stderr);

You can set a few options:

class Printer { public:
	// Print a little snippet of code if possible.
	bool snippet = true;

	// Colorize the trace
	//  - ColorMode::automatic: Activate colors if possible. For example, when using a TTY on linux.
	//  - ColorMode::always: Always use colors.
	//  - ColorMode::never: Never use colors.
	bool color_mode = ColorMode::automatic;

	// Add the addresses of every source location to the trace.
	bool address = false;

	// Even if there is a source location, also prints the object
	// from where the trace came from.
	bool object = false;

	// Resolve and print a stack trace to the given C FILE* object.
	// On linux, if the FILE* object is attached to a TTY,
	// color will be used if color_mode is set to automatic.
	template <typename StackTrace>
		FILE* print(StackTrace& st, FILE* fp = stderr);

	// Resolve and print a stack trace to the given std::ostream object.
	// Color will only be used if color_mode is set to always. 
	template <typename ST>
		std::ostream& print(ST& st, std::ostream& os);

SignalHandling

A simple helper class that registers for you the most common signals and other callbacks to segfault, hardware exception, un-handled exception etc.

backward.cpp simply uses it like that:

backward::SignalHandling sh;

Creating the object registers all the different signals and hooks. Destroying this object doesn't do anything. It exposes only one method:

bool loaded() const // true if loaded with success

Warning: The registered signal handlers are not signal safe, mostly because backward-cpp and the DWARF decoding libraries are using malloc. In case a signal is raised while malloc is holding a lock, a deadlock will occur.

Trace object

To keep the memory footprint of a loaded StackTrace on the low-side, there a hierarchy of trace object, from a minimal Trace to a ResolvedTrace.

Simple trace

struct Trace {
	void*  addr; // address of the trace
	size_t idx;  // its index (0 == most recent)
};

Resolved trace

A ResolvedTrace should contains a maximum of details about the location of the trace in the source code. Note that not all fields might be set.

struct ResolvedTrace: public Trace {

	struct SourceLoc {
		std::string function;
		std::string filename;
		unsigned    line;
		unsigned    col;
	};

	// In which binary object this trace is located.
	std::string                    object_filename;

	// The function in the object that contains the trace. This is not the same
	// as source.function which can be an function inlined in object_function.
	std::string                    object_function;

	// The source location of this trace. It is possible for filename to be
	// empty and for line/col to be invalid (value 0) if this information
	// couldn't be deduced, for example if there is no debug information in the
	// binary object.
	SourceLoc                      source;

	// An optional list of "inliners". All of these sources locations where
	// inlined in the source location of the trace (the attribute right above).
	// This is especially useful when you compile with optimizations turned on.
	typedef std::vector<SourceLoc> source_locs_t;
	source_locs_t                  inliners;
};

Contact and copyright

Franรงois-Xavier Bourlet [email protected]

Copyright 2013-2017 Google Inc. All Rights Reserved. MIT License.

Disclaimer

Although this project is owned by Google Inc. this is not a Google supported or affiliated project.

backward-cpp's People

Contributors

akreuzkamp avatar andreas-schwab avatar arekpiekarz avatar bastih avatar bombela avatar christophebedard avatar dodoent avatar dutow avatar eklitzke avatar forrestv avatar gbitzes avatar gerold103 avatar hesiod avatar jbakosi avatar krf avatar lahwaacz avatar madebr avatar manu343726 avatar marcomagdy avatar merlinthered avatar mgerhardy avatar no-more-secrets avatar okeuday avatar oold avatar pedronavf avatar pkestene avatar sbeyer avatar travisdowns avatar xgdgsc avatar zwimer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backward-cpp's Issues

builds.sh test doesn't work

builds.sh cmake and builds.sh make work, but builds.sh test results in

make: Entering directory '~/workspace/backward-cpp/build_c++98_gcc-4.6'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++98_gcc-4.6'
make: Entering directory '~/workspace/backward-cpp/build_c++98_gcc-4.8'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++98_gcc-4.8'
make: Entering directory '~/workspace/backward-cpp/build_c++98_gcc-530'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++98_gcc-530'
make: Entering directory '~/workspace/backward-cpp/build_c++98_gcc-620'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++98_gcc-620'
make: Entering directory '~/workspace/backward-cpp/build_c++98_clang'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++98_clang'
make: Entering directory '~/workspace/backward-cpp/build_c++11_gcc-4.8'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++11_gcc-4.8'
make: Entering directory '~/workspace/backward-cpp/build_c++11_gcc-530'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++11_gcc-530'
make: Entering directory '~/workspace/backward-cpp/build_c++11_gcc-620'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++11_gcc-620'
make: Entering directory '~/workspace/backward-cpp/build_c++11_clang'
make: *** No rule to make target 'test'.  Stop.
make: Leaving directory '~/workspace/backward-cpp/build_c++11_clang'

Why can't I print out stack information

like this๏ผš
Stack trace (most recent call last):
#1 Object "/lib/libc.so.6", at 0xf6f499bf, in __default_rt_sa_restorer_v1
#0 | Source "backward.hpp", line 2254, in backward::SignalHandling::sig_handler(int, siginfo_t*, void*)
| Source "backward.hpp", line 2232, in backward::SignalHandling::handleSignal(int, siginfo_t*, void*)
Source "backward.hpp", line 710, in backward::StackTraceImplbackward::system_tag::linux_tag::load_from(void*, unsigned int) [0x17183]

Which line in my source file is not located? I have follow define๏ผš
#define BACKWARD_HAS_BFD 1
#define BACKWARD_HAS_UNWIND == 1

thanks๏ผ

Platforms supported

Does your code work on all platforms ? I want to use it on an embedded arm 64 bit system.

I Feel guilty but I hardcoded another "print_source_loc" formatting

Just a small suggestion to add some kind of switch via a IFDEF to print from "super pretty" stack trace to the copypastable one

file:line sintax, so many program will just go to the right place.

If you deem that reasonable I will do a merge request, else in

void print_source_loc(std::ostream& os, const char* indent,

I now have

		auto fileNameClean = source_loc.filename.substr(3);
		os << indent
		   << "Source \""
		   << fileNameClean
		   << ":"
		   << source_loc.line
		   << "\"\n in "
		   << source_loc.function;
  1. So double click and most shell will select what is inside the "
  2. ??
  3. profit

Ultimate stack trace support

"You will need to install some dependencies to get the ultimate stack trace. Two libraries are currently supported, the only difference is which one is the easiest for you to install, so pick your poison:"

after which you mention libbfd, libdw, libdwarf, and libelf, which is four and not two to me. Can you clarify what library(s) are actually needed for this ultimate stack trace support ?

Should StackTrace::operator[](size_t idx) be declared const?

Semantically it seems like StackTrace::operator[](size_t idx) is a const operation, since it is simply returning by value a Trace object constructed out of the current state of the stack traces, but it is not currently declared const.

This impedes some uses, the obvious ones being that you have to pass around a non-const StackTrace object to methods that might use [], but I ran into the case where a StackTrace member of another class couldn't be accessed with operator[] in a const function of the containing class.

The current (Linux) implementation of operator[] doesn't have any problem being declared const. Adding const should be a non-breaking change, although you couldn't rule out that some other implementation would want to make this a physically non-const operation (e.g., caching values, whatever) - but that's where mutable comes in.

Unable to find BACKWARD_INCLUDE_DIR. Simpler ways to handle include dir

I have an use case where I clone the backward repository as a dependency of my project at CMake configure time (i.e. when cmake is run). The project is cloned in a directory part of my buildtree, which is then included by my project CMakeLists.txt. Like:

git_clone(backward-cpp)

add_subdirectory(backward-cpp_srcdir)

For some reason I cannot figure out the find_path(BACKWARD_INCLUDE_DIR ...) command in BackwardConfig.cmake fails. When trying to debug this issue I started to think if find_path() is the "best" (of course best is completely subjective...) way to set the library include dir. I mean, if I'm not wrong with the current project layout a simple

set(BACKWARD_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")

would do the work. The only advantage of using find_path (please correct me if I'm wrong) is that a change in the config script is not required if we change the project layout (the header would be found anyway).

If you don't mind I'm going to push a PR changing that find_path to the alternative explained above.

Q: Spliting in a client and server library, any chances of that?

A chance this library will be split in a client that grabs a backtrace, that could be stored and sent to a server and be symbolized there?

This way you can run a striped binary, but before you strip you copy the debug information and store it on the back-end. When you get a crash, you do the symbolizing on the back-end using your stored debug data.

Using imported target in CMake doesn't register signal handler

SUMMARY

One of the ways of using backward-cpp is linking to the library with an imported target in CMake. However, it doesn't register any signal handlers in case program crashes.

The probable cause is that - according to my understanding - in C++ the moment of instantiation of a global variable in a different translation unit does not have to happen before the main() function is called and a signal is raised. In that case it's strange to suggest using it like that.

Also note that using backward-cpp with the add_subdirectory method prints stack traces correctly.

STEPS TO REPRODUCE

Download backward-cpp:

mkdir external
cd external
git clone https://github.com/bombela/backward-cpp.git

Create CMakeLists.txt in the main project folder:

cmake_minimum_required(VERSION 3.0)
project(backward-cpp-test)

#set(BACWARD_SHARED ON)  # note - uncommenting this doesn't change the outcome
list(APPEND CMAKE_PREFIX_PATH external/backward-cpp)
find_package(Backward)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC Backward::Backward)

Create main.cpp:

#include <csignal>

int main()
{
    raise(SIGSEGV);
    return 0;
}

Build and run the project:

mkdir build
cd build
cmake ..
make
./backward-cpp-test

EXPECTED RESULT

Program should print:
Segmentation fault (core dumped)
followed by a stack trace.

ACTUAL RESULT

Program prints only:
Segmentation fault (core dumped)

ENVIRONMENT
Ubuntu 17.10
GCC 7.2
CMake 3.11
libbfd installed through binutils-dev
(all 64-bit)

Registering Signal Handlers With Python Runtime

Is it possible to enable the signal handlers from a python runtime? Its create from the documentation how one can add signal handlers to a C++ executable with its cmake target; however, it's unclear how one could register signal handlers for a python process using C++ extensions defined in a library containing backward-cpp.

Question: about functionality with Signals

Hello I think your library really cool and I am evaluating if we could use it in the project. So I have the following questions:

  • How does the signal handling works since you are using classes like std::vector for in the printer class, which are not to be used while signal handling according to signals cpp?

Best Regards
Federico

suppress "stack ... - ..." output

It would be nice to be able to suppress the initial line (e.g., stack 0x7f697f84b010 - 0x7f698004b010) in the default output. It's not a problem if there is an exceptional termination with a stack trace, but it's unnecessarily noisy for a normal execution.

Tag 1.1 release

Hi, I saw that some commits were added after the 1.0 release.

I suggest that a 1.1 release be tagged.

deadlock

backward uses malloc in the signal handler, which cause a very nasty deadlock in case if original signal raised by malloc itself, for example:

#0  0x00007f561384912c in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x00007f56137c6f93 in _L_lock_14932 () from /lib64/libc.so.6
#2  0x00007f56137c4013 in malloc () from /lib64/libc.so.6
#3  0x00007f56140ab288 in operator new(unsigned long) () from /usr/lib/gcc/x86_64-redhat-linux/5.3.1/libstdc++.so.6
#4  0x00000000005af533 in allocate (this=0x7f555ffec950, __n=<optimized out>) at /usr/include/c++/4.9.2/ext/new_allocator.h:104
#5  allocate (__a=..., __n=<optimized out>) at /usr/include/c++/4.9.2/bits/alloc_traits.h:357
#6  _M_allocate (this=0x7f555ffec950, __n=<optimized out>) at /usr/include/c++/4.9.2/bits/stl_vector.h:170
#7  std::vector<void*, std::allocator<void*> >::_M_default_append (this=this@entry=0x7f555ffec950, __n=40) at /usr/include/c++/4.9.2/bits/vector.tcc:557
#8  0x00000000005af848 in _M_default_append (__n=<optimized out>, this=0x7f555ffec950) at /usr/include/c++/4.9.2/bits/vector.tcc:550
#9  resize (__new_size=40, this=0x7f555ffec950) at /usr/include/c++/4.9.2/bits/stl_vector.h:676
#10 backward::StackTraceImpl<backward::system_tag::linux_tag>::load_here (this=this@entry=0x7f555ffec940, depth=depth@entry=40) at /usr/src/debug/crow-cluster/third-party/backward-cpp/backward.hpp:616
#11 0x00000000005b1eca in load_from (depth=32, addr=0x7f56137bf823 <malloc_consolidate+307>, this=0x7f555ffec940) at /usr/src/debug/crow-cluster/third-party/backward-cpp/backward.hpp:623
#12 backward::SignalHandling::sig_handler (info=0x7f555ffecb30, _ctx=<optimized out>) at /usr/src/debug/crow-cluster/third-party/backward-cpp/backward.hpp:1960
#13 <signal handler called>
#14 0x00007f56137bf823 in malloc_consolidate () from /lib64/libc.so.6
#15 0x00007f56137c1385 in _int_malloc () from /lib64/libc.so.6
#16 0x00007f56137c3fbc in malloc () from /lib64/libc.so.6
#17 0x00007f56140ab288 in operator new(unsigned long) () from /usr/lib/gcc/x86_64-redhat-linux/5.3.1/libstdc++.so.6

I don't think malloc is safe to be called from signal handlers at all, at least POSIX doesn't state so

There is not any function name info in the log

In default configuration, there is not any function name info in the log. Is this right?

Stack trace (most recent call last):
#3 Object "/lib/libc.so.6", at 0x442d77f7, in __libc_start_main
#2 Object "/usr/bin/mobile", at 0xf70b, in
#1 Object "/lib/libc.so.6", at 0x442edb4f, in
#0 Object "/usr/bin/mobile", at 0xdd6b, in

Segmentation fault (Address not mapped to object [(nil)])

Windows support

As far I know backward-cpp doesn't currently support Windows. I've been checking the Windows API docs and it seems really simple to take at least a minimal stacktrace (Not sure about source code printing).

I will be glad to work on this.

Failure to compile with clang++ (undeclared identifier '_Unwind_GetIPInfo')

I noticed this comment on HN (https://news.ycombinator.com/item?id=5381414) and did not see an Issue filed. I'm experiencing a similar issue when compiling my project (FCEUX) with clang++ and backward-cpp. I'm using "libdw" and passing "-DBACKWARD_HAS_DW=1" to the compiler. I receive the following error when compiling with clang++:

clang++ -o src/utils/backward.o -c -Wall -Wno-write-strings -Wno-sign-compare -Isrc/lua/src -DBACKWARD_HAS_DW=1 -DHAVE_ASPRINTF -pthread -D_GTK -DLUA_USE_LINUX -DOPENGL -g -DHAVE_GD -D_GNU_SOURCE=1 -D_REENTRANT -D_GTK2 -D_S9XLUA_H -DPSS_STYLE=1 -DLSB_FIRST -DFRAMESKIP -D_DEBUG -DCREATE_AVI -I/usr/include/SDL -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/libpng15 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 src/utils/backward.cpp
In file included from src/utils/backward.cpp:26:
src/utils/backward.hpp:595:18: error: use of undeclared identifier '_Unwind_GetIPInfo'
                uintptr_t ip = _Unwind_GetIPInfo(ctx, &ip_before_instruction);
                               ^
1 error generated.
scons: *** [src/utils/backward.o] Error 1
scons: building terminated because of errors.

When compiling with "-DBACKWARD_HAS_BACKTRACE=1" in addition to "-DBACKWARD_HAS_DW=1", as suggested in your reply to the HN comment, everything works as per usual. In addition, when compiling with g++, the "-DBACKWARD_HAS_BACKTRACE=1" is not required and everything works as suspected.

I'm testing with Arch Linux (64 bit fwiw). If you need any additional information, feel free to let me know. Thanks again for this really great/useful open source contribution!

Conan package

Hello,
Do you know about Conan?
Conan is modern dependency manager for C++. And will be great if your library will be available via package manager for other developers.

Here you can find example, how you can create package for the library.

If you have any questions, just ask :-)

Issues with Pedantic compiling

Hey,
while installing the library in my project i got 2 compiler warnings due to my pedantic settings ("/W4" under Windows, "-Wall -Wextra -Werror -Wno-long-long -Wpedantic" under linux).

It would be cool if you could fix them in the original code, this is the diff i used to fix both errors, however you should have a brief look the solution because i just started working with c++:

1st Error: compiler warning because of possible lost of data when converting size_t to unsigned
2nd Error: isspace returns an int, but the function should return a bool

 backward.hpp
@@ -435,7 +435,7 @@ struct Trace {
 		addr(0), idx(0) {}
 
 	explicit Trace(void* addr, size_t idx):
- 		addr(addr), idx(idx) {}
+ 		addr(addr), idx(unsigned(idx)) {}
 };
 
 struct ResolvedTrace: public Trace {
@@ -1520,7 +1520,7 @@ public:
 		// What a good boy am I.
 		struct isspace {
 			bool operator()(char c) {
- 				return std::isspace(c);
+ 				return std::isspace(c) != 0;
 			}
 		};

Stacktrace in docs vs StackTrace in code

Did the docs and code get out of sync at some point? The readme refers to the class as "Stacktrace" and "StackTrace" in different places (including example code) but it looks like it should only be "StackTrace".

BackwardConfig.cmake forcing dependency on BACKWARD_LIBRARIES

When including the BackwardConfig.cmake via find_package:

find_package(backward NO_MODULE REQUIRED)

it fails to properly detect backward if neither libdw nor libbfd are found as in this case BACKWARD_LIBRARIES is empty, hence the failure in find_package_handle_standard_args in https://github.com/bombela/backward-cpp/blob/master/BackwardConfig.cmake#L121 . Given that both libraries are optional, the failure should not be a hard error (even with REQUIRED)

deadlock when catching SIGSEGV.

Here is the backtrace printed by gdb,

#0  0x000000000287790a in sys_futex (a=0x4087f80 <tcmalloc::Static::central_cache_+1216>, o=128, v=2, t=0x7febee032860) at /home/amos/repos/dsql/src/gutil/linux_syscall_support.h:2713
#1  0x0000000002877a4b in base::internal::SpinLockDelay (w=0x4087f80 <tcmalloc::Static::central_cache_+1216>, value=2, loop=1073) at /home/amos/repos/dsql/src/gutil/spinlock_linux-inl.h:88
#2  0x00000000028af9a9 in SpinLock::SlowLock() ()
#3  0x0000000002967cd9 in tcmalloc::CentralFreeList::RemoveRange(void**, void**, int) ()
#4  0x00000000029753b3 in tcmalloc::ThreadCache::FetchFromCentralCache(unsigned long, unsigned long) ()
#5  0x000000000298236b in tc_malloc ()
#6  0x00000000028dca86 in bfd_malloc ()
#7  0x00000000028dd2bb in bfd_follow_gnu_debuglink ()
#8  0x0000000002954d37 in find_line ()
#9  0x0000000002954e97 in _bfd_dwarf2_find_nearest_line ()
#10 0x00000000028efefa in _bfd_elf_find_nearest_line ()
#11 0x00000000011b2858 in backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::find_in_section (this=0x7febee032ff8, addr=213107247788, base_addr=213106294784, fobj=..., section=0x12e02ce0, result=...) at /home/amos/repo
s/dsql/src/util/backward.hpp:1084
#12 0x00000000011b26f9 in backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::find_in_section_trampoline (section=0x12e02ce0, data=0x7febee032d60) at /home/amos/repos/dsql/src/util/backward.hpp:1060
#13 0x00000000028de4dc in bfd_map_over_sections ()
#14 0x00000000011b266c in backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::find_symbol_details (this=0x7febee032ff8, fobj=..., addr=0x319e2e8aac <clone+108>, base_addr=0x319e200000) at /home/amos/repos/dsql/src/util/backward.hpp:1048
#15 0x00000000011b203e in backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::resolve (this=0x7febee032ff8, trace=...) at /home/amos/repos/dsql/src/util/backward.hpp:817
#16 0x00000000011b51d1 in backward::Printer::print<backward::StackTrace> (this=0x7febee032ff0, st=..., os=0x319e58f120 <_IO_2_1_stderr_>) at /home/amos/repos/dsql/src/util/backward.hpp:1747
#17 0x00000000011b3ee4 in backward::SignalHandling::sig_handler (info=0x7febee033470, _ctx=0x7febee033340) at /home/amos/repos/dsql/src/util/backward.hpp:1959
#18 0x00007fecddbe8852 in os::Linux::chained_handler(int, siginfo*, void*) () from /home/amos/repos/dsql/install/postgres/jdk/jre/lib/amd64/server/libjvm.so
#19 0x00007fecddbeec86 in JVM_handle_linux_signal () from /home/amos/repos/dsql/install/postgres/jdk/jre/lib/amd64/server/libjvm.so
#20 0x00007fecddbe54b3 in signalHandler(int, siginfo*, void*) () from /home/amos/repos/dsql/install/postgres/jdk/jre/lib/amd64/server/libjvm.so
#21 <signal handler called>

How do you use backward with a library?

Hi,

I have a project in which Python uses static C++ libraries. How do I include backward in the project? Do I have to include it in each CMake file for each library? An example would be great.

Thanks

Any hints as to what's needed for a PR to work on OSX

Tinkering around and would like to get stack traces on osx. binutils is in homebrew and I found argp-standalone in homebrew (required by elfutils), then I got elfutils to not complain about GNU99 support, guessing that this is an issue in elfutils?

CMAKE_MODULE_PATH doesn't work, but CMAKE_PREFIX_PATH does

README suggests appending a path to CMAKE_MODULE_PATH to find Backward-cpp.

However that results in a following error:

CMake Warning at CMakeLists.txt:7 (find_package):
  By not providing "FindBackward.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Backward",
  but CMake did not find one.

  Could not find a package configuration file provided by "Backward" with any
  of the following names:

    BackwardConfig.cmake
    backward-config.cmake

  Add the installation prefix of "Backward" to CMAKE_PREFIX_PATH or set
  "Backward_DIR" to a directory containing one of the above files.  If
  "Backward" provides a separate development package or SDK, be sure it has
  been installed.


Configuring done
CMake Warning (dev) at CMakeLists.txt:4 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "backward-cpp-test" links to target "Backward::Backward" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

Generating done

Trying to compile it results in this build error:

14:54:43: Running steps for project backward-cpp-test...
14:54:43: Starting: "/usr/bin/cmake" --build . --target all
Scanning dependencies of target backward-cpp-test
[ 50%] Building CXX object CMakeFiles/backward-cpp-test.dir/main.cpp.o
/home/arek/dev/backward-cpp-test/main.cpp:2:10: fatal error: backward.hpp: No such file or directory
 #include <backward.hpp>
          ^~~~~~~~~~~~~~
compilation terminated.

Replacing CMAKE_MODULE_PATH with CMAKE_PREFIX_PATH fixes the problem for me.
Note that I haven't checked older versions of CMake.

My setup:
Xubuntu 17.10 x64
CMake 3.9.1
GCC 7.2.0

My CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project(backward-cpp-test)
add_executable(${PROJECT_NAME} "main.cpp")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/external/backward-cpp)
find_package(Backward)
target_link_libraries(${PROJECT_NAME} PUBLIC Backward::Backward)

My main.cpp file:

#include <backward.hpp>

using namespace backward;

int main()
{
    StackTrace st;
    st.load_here(32);
    Printer p;
    p.print(st, std::cerr);

    return 0;
}

Using libbfd and running executable via PATH results in segfault

If an executable is run by e.g. being on the PATH (anything that results in argv[0] not being a valid path to the executable), problems ensue when backward-cpp tries to print a stack trace.

dladdr returns argv[0] in dli_fname for symbols contained in the main executable, which is not a valid path if the executable was found by a search of the PATH environment variable. Then, load_object_with_bfd is called on that non-existent filename and fails.

This would just result in not getting a pretty stack trace in this situation if not for another bug:

One of the handle objects somehow gets filled with a nullptr but with _empty = false, resulting in bfd_close eventually being called with nullptr as the argument.

That results in a segfault midway through the stack trace.

Test platform: Ubuntu 16.04.3 (xenial) amd64

Don't get the pretty stack trace, only the basic one

Hi, i followed the Readme but i don't get to the pretty stacktrace, only the simple one:

i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9
i=10
i=11
i=12
i=13
i=14
i=15
i=16
i=17
i=18
i=19
i=20
i=21
i=22
i=23
i=24
i=25
i=26
i=27
i=28
i=29
i=30
i=31
i=32
i=33
i=34
i=35
i=36
i=37
i=38
i=39
i=40
i=41
#0 at unsigned long backward::details::unwind<backward::StackTraceImpl<backward::system_tag::linux_tag>::callback>(backward::StackTraceImpl<backward::system_tag::linux_tag>::callback, unsigned long)
#1 at backward::StackTraceImpl<backward::system_tag::linux_tag>::load_here(unsigned long)
#2 at TracedException::_get_trace[abi:cxx11]()
#3 at TracedException::TracedException()
#4 at f(int)
#5 at f(int)
#6 at f(int)
#7 at f(int)
#8 at f(int)
#9 at f(int)
#10 at f(int)
#11 at f(int)
#12 at f(int)
#13 at f(int)
#14 at f(int)
#15 at f(int)
#16 at f(int)
#17 at f(int)
#18 at f(int)
#19 at f(int)
#20 at f(int)
#21 at f(int)
#22 at f(int)
#23 at f(int)
#24 at f(int)
#25 at f(int)
#26 at f(int)
#27 at f(int)
#28 at f(int)
#29 at f(int)
#30 at f(int)
#31 at f(int)
Stack trace (most recent call last):

I copied the source from the _test_main.cpp file to my project

#include "backward.hpp"

using namespace backward;

class TracedException : public std::runtime_error
{
public:
	TracedException() :
		std::runtime_error(_get_trace())
	{}

private:
	std::string _get_trace()
	{
		std::ostringstream ss;

		StackTrace stackTrace;
		TraceResolver resolver;
		stackTrace.load_here();
		resolver.load_stacktrace(stackTrace);

		for (std::size_t i = 0; i < stackTrace.size(); ++i)
		{
			const ResolvedTrace trace = resolver.resolve(stackTrace[i]);

			ss << "#" << i << " at " << trace.object_function << "\n";
		}

		return ss.str();
	}
};

void f(int i)
{
	if (i >= 42)
	{
		throw TracedException();
	}
	else
	{
		std::cout << "i=" << i << "\n";
		f(i + 1);
	}
}

namespace {

	TEST(pfFiles, TestStackError)
	{
		backward::StackTrace st;
		try
		{
			f(0);
		}
		catch (const TracedException& ex)
		{
			std::cout << ex.what();
		}

		backward::Printer printer;
		//    printer.address = true;
		printer.object = true;
		printer.print(st, stdout);
	}
}

I use the following CMAKE settings.

  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-long-long -Wpedantic -std=c++14 -g")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lbfd")

I have installed backward-cpp as subdirectory in my cmake script.
I installed the gnu binutils package under ubuntu 16.04LTS with gcc 5.4.
I neither set the define (-DBACKWARD_HAS_...=1) flag nor used #define BACKWARD_HAS_BFD 1 because it seems that your cmake script automaticly detects the library:

Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Could NOT find libdw (missing:  LIBDW_LIBRARY LIBDW_INCLUDE_DIR) 
-- Found libbfd: /usr/lib/x86_64-linux-gnu/libbfd.so  
-- BACKWARD_HAS_UNWIND=1
-- BACKWARD_HAS_BACKTRACE=0
-- BACKWARD_HAS_BACKTRACE_SYMBOL=0
-- BACKWARD_HAS_DW=0
-- BACKWARD_HAS_BFD=1
-- Found Backward: /home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/3rdparty/backward-cpp  

i compile with:

add_executable(PfTEngineTest ${SOURCES} ${BACKWARD_ENABLE})
add_backward(PfTEngineTest)

So my question is: What do i have to do to get the full pretty code style?
Have i installed all dependencys correclty ?
Have i forgot something ?
The README doesn't specify what needs to be in code for pretty code ? is it enough just to compile backward.cpp with my target ?
Or do i have to create some classes ?
Do i need to throw special Exceptions or is everything catched ?
Do i need a TRY/CATCH block in main which covers everything ?

Thanks for any help :)

PS: I used the changed code from #51

examin local variables stored in the stack frame

is it possible to use this library to examin local variables stored in the stack frame?

similar to what gdb does with "info locals" command.

If not can you recommend me something?

Best regards,

ramy gad

compiling with nvcc / nvcc_wrapper - issue with CXX standard

I'm using nvcc_wrapper (a compiler wrapper provided by project
https://github.com/kokkos/kokkos ) which wraps calls to the actual nvidia nvcc compiler.

When using nvcc_wrapper in a cmake project, cmake recognizes it as GNU : CMAKE_COMPILER_IS_GNUCXX is true, but actually:

  • nvcc does not support GNU cxx extensions, i.e. one must use "-std=c++11" instead of "-std=gnu++11"
  • nvcc does not support flag "-pedantic-errors"

Would you mind if I provide a simple modification to the top level CMakeLists.txt that checks if compiler is nvcc/nvcc_wrapper and if true, turns "-std=gnu++11" into "-std=c++11" and turns off pedantic-errors flag ?

backtrace not printing stack and source information

I am trying backward-cpp with following sample code:

test.cpp:

#include <assert.h>
#include "backward.hpp"
int main()
{
  assert(0);
}

build command:

g++ -g test.cpp backward.cpp

but stack is not providing any useful information:

Stack trace (most recent call last):
#7 Object "[0xffffffffffffffff]", at 0xffffffffffffffff, in
#6 Object "./a.out", at 0x4019d8, in
#5 Object "/lib64/libc.so.6", at 0x7f540b545af4, in __libc_start_main
#4 Object "./a.out", at 0x401ab9, in
#3 Object "/lib64/libc.so.6", at 0x7f540b5525f1, in __assert_fail
#2 Object "/lib64/libc.so.6", at 0x7f540b552545, in
#1 Object "/lib64/libc.so.6", at 0x7f540b55acc7, in abort
#0 Object "/lib64/libc.so.6", at 0x7f540b5595d7, in gsignal
Aborted (Signal sent by tkill() 85950 28120)
Aborted

can you please advice whats I am doing wrong ?

cmake macro add_backward erroneously expanded

In BackwardConfig.cmake, macro add_backward does not necessarily get correctly expanded:
indeed it uses variable _BACKWARD_INCLUDE_DIRS (instead of BACKWARD_INCLUDE_DIRS), so when this macro is called elsewhere in another cmake scope, _BACKWARD_INCLUDE_DIRS is empty while BACKWARD_INCLUDE_DIRS is ok.

The simple fix is just to replace _BACKWARD_INCLUDE_DIRS by BACKWARD_INCLUDE_DIRS

backward.hpp does not detect x86 architecture for clang compiler

When I build using clang (from clion) on a 64-bit mac I get the following error message:

backward-cpp/backward.hpp:2093:3: warning: ":/ sorry, ain't know no nothing none not of your architecture!" [-W#warnings]`
#       warning ":/ sorry, ain't know no nothing none not of your architecture!"
        ^

Looking at the code, it looks like #ifdef REG_RIP // x86_64 is not defined for my architecture, and it probably shouldn't be. That's not a compiler-defined preprocessor value for x86 architecture, but __x86_64__ is

v1.4 release?

Hi,

I was thinking if the project has merged enough fixes and changes to consider releasing a v1.4 version. What do you think?

Tag release 1.2

Hello!

Would you mind tagging a new release 1.2 ? So I can create the conda-forge packages with the latest commit.

Thanks!

Error while cross-compiling...

In file included from /home/user/ALPHABOX/alpha-app/app/recorder/main.cpp:27:0:
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1938:3: warning: #warning ":/ sorry, ain't know no nothing none not of your architecture!"
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp: In static member function 'static void backward::SignalHandling::sig_handler(int, siginfo_t_, void_)':
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1929:15: warning: unused variable 'uctx'
In file included from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/move.h:38:0,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_pair.h:60,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_algobase.h:66,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/char_traits.h:41,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/ios:41,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/ostream:40,
from /home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/iostream:40,
from /home/user/ALPHABOX/alpha-app/app/recorder/main.cpp:4:
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits: At global scope:
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits: In instantiation of 'const bool std::__is_convertible_helper<backward::SourceFile, backward::SourceFile, false>::__value':
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits:312:5: instantiated from 'std::is_convertible<backward::SourceFile, backward::SourceFile>'
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_map.h:451:11: instantiated from 'mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::basic_string, _Tp = backward::SourceFile, _Compare = std::lessstd::basic_string, _Alloc = std::allocator<std::pair<const std::basic_string, backward::SourceFile> >, mapped_type = backward::SourceFile, key_type = std::basic_string]'
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1647:49: instantiated from here
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits:302:71: error: no matching function for call to 'backward::SourceFile::SourceFile(backward::SourceFile)'
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1481:2: note: candidates are: backward::SourceFile::SourceFile(const std::string&)
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1480:2: note: backward::SourceFile::SourceFile()
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits:302:71: error: initializing argument 1 of 'static std::__sfinae_types::__one std::__is_convertible_helper<_From, _To, false>::__test(_To) [with _From = backward::SourceFile, _To = backward::SourceFile, std::__sfinae_types::__one = char]'
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits: In instantiation of 'std::is_convertible<backward::SourceFile, backward::SourceFile>':
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/bits/stl_map.h:451:11: instantiated from 'mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::basic_string, _Tp = backward::SourceFile, _Compare = std::lessstd::basic_string, _Alloc = std::allocator<std::pair<const std::basic_string, backward::SourceFile> >, mapped_type = backward::SourceFile, key_type = std::basic_string]'
/home/user/ALPHABOX/alpha-app/app/recorder/backward.hpp:1647:49: instantiated from here
/home/user/SDK/linux/linux-current/ti-sdk-am335x-evm-05.04.01.00/linux-devkit/bin/../lib/gcc/arm-arago-linux-gnueabi/4.5.3/../../../../arm-arago-linux-gnueabi/include/c++/4.5.3/type_traits:312:5: error: 'std::__is_convertible_helper<backward::SourceFile, backward::SourceFile, false>::__value' is not a valid template argument for type 'bool' because it is a non-constant expression

Mention libdl requirement

For BACKWARD_HAS_BFD == 1 use at least, it seems that libdl (i.e., -ldl on the link line) is needed in addition to libbfd.

Might be worth mentioning it in the readme.

CMake linking problem

I am trying to use the first CMake method, and am totally a CMake novice. I got the project to build fine without the 2 external dependencies (so the less pretty stack traces).

add_subdirectory(/path/to/backward-cpp)

# This will add backward.cpp to your target
add_executable(mytarget mysource.cpp ${BACKWARD_ENABLE})
target_link_libraries(mytarget
[my libraries])
# This will add libraries, definitions and include directories needed by backward
# by setting each property on the target.
add_backward(mytarget)

I installed both of the suggested extra dependencies, and the BackwardConfig.cmake file is detecting one of them, so I get

-- BACKWARD_HAS_UNWIND=1
-- BACKWARD_HAS_BACKTRACE=0
-- BACKWARD_HAS_BACKTRACE_SYMBOL=0
-- BACKWARD_HAS_DW=1
-- BACKWARD_HAS_BFD=0

(As an aside, the logic located in BackwardConfig.cmake makes it seem like HAS_DW or HAS_BFD could only be true mutually exclusively, was this the intention?)

However, when I build the program, I get an error with a long list of 'undefined reference' e.g.

CMakeFiles/backward.dir/backward.cpp.o: In function `backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libdw>::resolve(backward::ResolvedTrace)':
/home/[my path]/backward-cpp/backward.hpp:1158: undefined reference to `dwfl_linux_proc_find_elf'
/home/[my path]/backward-cpp/backward.hpp:1159: undefined reference to `dwfl_standard_find_debuginfo'
etc.

which I think is a linker error? Any idea what I'm doing wrong? Do I need to add a line in target_link_libraries?

Broken travis build - conan 'test_package' removed

https://travis-ci.org/bombela/backward-cpp/jobs/319897290

conan test_package --build=outdated
ERROR: Unknown command 'test_package'

https://github.com/conan-io/conan/releases

Command test_package has been removed. Use conan create instead, and conan test for just running package tests.

Also on line 35 in the conanfile.py I think the new practice is to use CMake(self) instead of CMake(self.settings). Ref: https://github.com/conan-io/docs/blob/master/reference/build_helpers/cmake.rst

0.29.0: Deprecation: Removed old CMake helper methods (only valid constructor is CMake(self))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.