Giter Club home page Giter Club logo

Comments (6)

bombela avatar bombela commented on September 21, 2024

It looks like you are not collecting all the trace details in your _get_trace method. Try calling abort() with backward-cpp signal handler installed for comparison.

The README doesn't specify what needs to be in code for pretty code ?

It does, read again :) And as far as I can tell, your defines are correct in your cmake output. (But I am not experienced with CMake, so take my affirmation with a grain of salt). You have unwind and BFD.

Do i need to throw special Exceptions or is everything catched ?
Do i need a TRY/CATCH block in main which covers everything ?

backward-cpp doesn't offer any function to attach stacktrace onto Exceptions (I had a work in progress branch at some point, but never took the time to finish the work).

If you never catch an exception, eventually your program will call abort(). This will effectively get you a stacktrace from backward-cpp assuming signal handlers are registered. But this stackstrace will start from the abort() call not were the exception was raised.

So your idea of storing a stacktrace alongside the Exception is perfectly good, but make sure to collect all the details :) I would advise you to collect the stacktrace in the exception without resolving anything yet, and use the stacktrace printer whenever you want to resolve and print details about the exception stacktrace.

Best,

from backward-cpp.

xMAC94x avatar xMAC94x commented on September 21, 2024

I was not sure if

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lbfd")

is the correct way to link against the library, so i added:

target_link_libraries(PfTEngineTest "libbfd.so")

now when calling abort in f() i get a pretty nice stacktrace.

`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
Stack trace (most recent call last):
#31   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#30   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#29   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#28   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#27   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#26   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#25   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#24   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#23   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#22   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#21   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#20   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#19   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#18   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#17   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#16   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#15   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#14   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#13   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#12   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#11   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#10   Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#9    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#8    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#7    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#6    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#5    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#4    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#3    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 50, in f(int) [0x4be574]
         47: 	else
         48: 	{
         49: 		std::cout << "i=" << i << "\n";
      >  50: 		f(i + 1);
         51: 	}
         52: }
#2    Source "/home/gitlab-runner/builds/0c2717af/0/PfTTech/PfTEngine/src/test/pfthread.cpp", line 44, in f(int) [0x4be53b]
         41: {
         42: 	if (i >= 42)
         43: 	{
      >  44: 		abort();
         45: 		throw TracedException();
         46: 	}
         47: 	else
#1    Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7faf86b13029, in abort
#0    Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7faf86b11428, in gsignal
Aborted (Signal sent by tkill() 19122 999)
Aborted

from backward-cpp.

bombela avatar bombela commented on September 21, 2024

I am glad that it works now :)

from backward-cpp.

Manu343726 avatar Manu343726 commented on September 21, 2024

So the pretty output only shows up if you link against the right libraries? I think there's a bug in the conan recipe then :(

from backward-cpp.

bombela avatar bombela commented on September 21, 2024

from backward-cpp.

Manu343726 avatar Manu343726 commented on September 21, 2024

From the package recipe perspective, conan is just a python script that tells how to get your project sources, build them, and what build artifacts must be packaged (In this way it works very similar to some system package managers). The only thing that makes it special is that conan is specifically designed for C++, so it keeps track of compiler versioning, abi, platform, etc when building and resolving the dependencies.

With this in mind, if there's a bug in the way optional libraries are handled is because I didn't take this right into account when writing the recipe. Specifically, I put one conan option (A package can define multiple options that result in different "variants" of the same package, for example "MyFooLib" Debug vs Release) for each backward-cpp option. Then conan build() method just invokes your CMakeLists.txt with those options. What I forgot is to tell the library (Maybe by modifying how the cmake library target is handled in the CMakeLists.txt) to link against different optional libraries depending on the options.

from backward-cpp.

Related Issues (20)

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.