backward-cpp icon indicating copy to clipboard operation
backward-cpp copied to clipboard

Windows support

Open Manu343726 opened this issue 7 years ago • 12 comments

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.

Manu343726 avatar Dec 22 '16 19:12 Manu343726

And I would be very happy to review your PR! I honestly don't know much about Windows though.

bombela avatar Jan 09 '17 03:01 bombela

I've actually started to work windows support right here: https://github.com/yosizelensky/backward-cpp

Happy to hear your thoughts (It's not done yet)

yosizelensky avatar Sep 02 '17 11:09 yosizelensky

One year has passed since opening this issue, are we closer to getting Windows support?

ArekPiekarz avatar Dec 25 '17 10:12 ArekPiekarz

Call from 2018, is there anybody worked on Windows support ? Thanks !

zhoub avatar Jul 04 '18 02:07 zhoub

Not that I am aware of!

On Tue, Jul 3, 2018 at 7:17 PM Bo Zhou [email protected] wrote:

Call from 2018, is there anybody worked on Windows support ? Thanks !

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bombela/backward-cpp/issues/50#issuecomment-402343200, or mute the thread https://github.com/notifications/unsubscribe-auth/AANMjFSHlnYIDm6Kq39MonR7g7BfV8snks5uDCWzgaJpZM4LUTTL .

bombela avatar Jul 04 '18 02:07 bombela

I managed to put together some glue code that uses Boost::stacktrace to obtain a stacktrace under Windows, and then converts it to something that can be pretty printed by Backward. Of course that implies that you need to add a dependency on Boost.

The result is rather nice, even if Boost cannot reconstruct all the informations that Backward has on Linux. Sometimes it seems that lines are offset by 1.

The code is here: https://gitlab.com/giomasce/giolib/blob/master/giolib/stacktrace.h#L155

Some information on how the Boost backend works: https://www.boost.org/doc/libs/1_68_0/doc/html/stacktrace/configuration_and_build.html

In line of theory the code from Boost could be ported to Backward, or Boost could be used as a dependency. However, I will not work on this specifically, since I am already satisfied with my solution.

Incidentally, backward.hpp has a couple of details that require some hack to include it in MSVC: https://gitlab.com/giomasce/giolib/blob/master/giolib/stacktrace.h#L107. It would be nice if those could be fixed.

giomasce avatar Oct 30 '18 10:10 giomasce

More specifically, when compiling with MSVC under Windows there are the following problems:

  • The GNUism __attribute__ is used, making the compilation fail. Apparently, in MSVC you use __declspec(noinline) to avoid function inlining (see https://stackoverflow.com/a/3329464/807307). You can also test for the MSVC compiiler with the _MSC_VER macro (see https://msdn.microsoft.com/en-us/library/b0084kay.aspx)
  • On Windows backtrace is not defined. Ideally the code can be arranged so that if no tool for obtaining stack traces can be used, then stack traces are created empty by default (while still allowing to use backward.hpp to pretty print traces obtained for example by Boost).
  • In MSVC the default __cplusplus macro is broken, and it always takes a value in 1997, unless you use some obscure flags when calling the compiler. It seems that the macro _MSVC_LANG can be used instead (see the same document from MSDN above).

giomasce avatar Oct 30 '18 13:10 giomasce

I pushed a working prototype at my fork - still needs some work, but the basic functionality there, and it only depends on standard windows headers/libs. (only used it with clang for now, MSVC could need a few fixes so it compiles, especially earlier versions, will check that later)

I'll clean up the logic part of it in the next days, and submit a PR.

But before that, @bombela I have two questions:

  • have you considered formatting the source with clang-format? That would make larger code changes easier. (it's a 500 line diff now, likely will be more in the end)
  • I'd like to avoid implementing manual coloring for windows, what do you think about depending on rang to do it? (if rang is included, do coloring. otherwise, dont)

dutow avatar Aug 22 '19 17:08 dutow

Happy to format with clang-format. Fell free to submit a PR after running it to make your future PRs easier to merge.

We can copy rang.hpp in this repo, and instruct people to copy it alongside backward.hpp in the README.

bombela avatar Aug 22 '19 19:08 bombela

Thanks for the quick reply!

Re: formatting, do you have any preferred style (e.g. keeping as close as the current, or using a predefined style supported by it)? Clang-format doesn't have anything perfectly matching the current style. I did try to get something close to it before asking to use during development, but I've noticed some issues, such as:

  • the current namespace indentation is inconsistent (there's some code which isn't indented within a namespace at all; there's some which indented one tab no matter how many namespaces is it in (not supported by clang format currently); there's some which are indented by 2 tabs when in a nested namespace...
  • same with the preprocessor rules: some are indented after the #, others aren't - but for those indented, the first ifdef (header guard) is ignored, which is again not supported by clang-format unfortunately

dutow avatar Aug 22 '19 20:08 dutow

I do not care about the style at all. I would take the default from clang-format. The less configuration, the better.

bombela avatar Aug 22 '19 21:08 bombela

@dutow https://github.com/bombela/backward-cpp/pull/142

bombela avatar Aug 22 '19 21:08 bombela