Live data from Hacker News

C++ Insights – See your source code with the eyes of a compiler

github.com

21–30 of 70 posts

Re: C++ Insights – See your source code with the eyes of a compiler

#21
post #2

I wonder how helpful it is for g++? Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level. The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship w…

Sounds like a huge undertaking, but why not use clang for introspection and gcc for compiling? It is still useful.

Re: C++ Insights – See your source code with the eyes of a compiler

#22

I wish there was a way to show the code that is generated when using co_return or co_await e.g. https://cppinsights.io/lnk?code=Ly8gaHR0cHM6Ly93d3cuc2NzLnN0...

Sometimes, wishes come true!

Just open the drop-down to select the C++ standard. Below, there is a section "More Transformations". Enable "Show coroutine transformation", and you will get the transformation you're looking for: https://cppinsights.io/s/4d8c3fc1

Disclaimer: I'm the author.

Re: C++ Insights – See your source code with the eyes of a compiler

#25
post #20

Earlier quoted context omitted.

Don't debug -O3, or -O2 for that matter. Debug a separate debug build without optimizations, or don't heavily optimize your release build if you want to debug that (you know that obviously). Even with optimizations disabled, debugging C++ can be quite painful. Only add a little template stuff to the source code, and a few "zero-cost" methods like indexing operators or cast operators, and it quickly becomes painful to…

Use modern IDEs with features like Just My Code, which already help a lot. https://learn.microsoft.com/en-us/visualstudio/debugger/just... Also, there are scenarios where debugging without optimizations isn't an option. The issue with std::move has been solved for a while and was a VC++ bug, not C++. https://devblogs.microsoft.com/visualstudio/a-year-of-cpp-im...

Can Just My Code help if it is precisely my code that I want to skip over? I believe it does not -- IIUC it works based on modules i.e. the DLL that contains the machine code. IOW it doesn't even help if I move the "zero-cost" stuff to a separate source file -- templates and other stuff that have to be instanciated or inlined won't be separable from the code that I want to debug based on the module they're running in.

> Also, there are scenarios where debugging without optimizations isn't an option.

There are scenarios where debugging isn't an option in the first place. Doesn't mean that I should have to suffer in the typical case where debugging with no or only light optimizations is perfectly viable.

An acceptable solution I guess would be to have a [DebuggerHidden] function attribute as I found for C#. Didn't find one for C++.

Re: C++ Insights – See your source code with the eyes of a compiler

#26
post #20

Earlier quoted context omitted.

Don't debug -O3, or -O2 for that matter. Debug a separate debug build without optimizations, or don't heavily optimize your release build if you want to debug that (you know that obviously). Even with optimizations disabled, debugging C++ can be quite painful. Only add a little template stuff to the source code, and a few "zero-cost" methods like indexing operators or cast operators, and it quickly becomes painful to…

Use modern IDEs with features like Just My Code, which already help a lot. https://learn.microsoft.com/en-us/visualstudio/debugger/just... Also, there are scenarios where debugging without optimizations isn't an option. The issue with std::move has been solved for a while and was a VC++ bug, not C++. https://devblogs.microsoft.com/visualstudio/a-year-of-cpp-im...

[deleted]

Re: C++ Insights – See your source code with the eyes of a compiler

#27
post #20

Earlier quoted context omitted.

Use modern IDEs with features like Just My Code, which already help a lot. https://learn.microsoft.com/en-us/visualstudio/debugger/just... Also, there are scenarios where debugging without optimizations isn't an option. The issue with std::move has been solved for a while and was a VC++ bug, not C++. https://devblogs.microsoft.com/visualstudio/a-year-of-cpp-im...

Can Just My Code help if it is precisely my code that I want to skip over? I believe it does not -- IIUC it works based on modules i.e. the DLL that contains the machine code. IOW it doesn't even help if I move the "zero-cost" stuff to a separate source file -- templates and other stuff that have to be instanciated or inlined won't be separable from the code that I want to debug based on the module they're running in…

Well, if we are going down tiny details about what to skip, there are lots of C preprocessor stuff, standard library functions implementated in crazy ways for ISO/POSIX compliance, and own abstractions/functions, that I might also want to skip over.

Re: C++ Insights – See your source code with the eyes of a compiler

#28

Earlier quoted context omitted.

I use neovim btw

Thanks to another contributor there is a vim extensions: https://github.com/Freed-Wu/cppinsights.vim

Now do Emacs. 2 minutes od searching didn't hit anything :)

Re: C++ Insights – See your source code with the eyes of a compiler

#29
post #14

Earlier quoted context omitted.

Even C doesn't map any longer when taking into consideration -O3, UB, vector units, and compiler replaced standard library calls. I miss the part of what a modern debug lacks.

Don't debug -O3, or -O2 for that matter. Debug a separate debug build without optimizations, or don't heavily optimize your release build if you want to debug that (you know that obviously). Even with optimizations disabled, debugging C++ can be quite painful. Only add a little template stuff to the source code, and a few "zero-cost" methods like indexing operators or cast operators, and it quickly becomes painful to…

You need to be able debug optimized builds. That's a requirement of the real world if you're a software engineer.

Just learn how to use gdb, it's quite capable.

Re: C++ Insights – See your source code with the eyes of a compiler

#30
post #20

Earlier quoted context omitted.

Use modern IDEs with features like Just My Code, which already help a lot. https://learn.microsoft.com/en-us/visualstudio/debugger/just... Also, there are scenarios where debugging without optimizations isn't an option. The issue with std::move has been solved for a while and was a VC++ bug, not C++. https://devblogs.microsoft.com/visualstudio/a-year-of-cpp-im...

Can Just My Code help if it is precisely my code that I want to skip over? I believe it does not -- IIUC it works based on modules i.e. the DLL that contains the machine code. IOW it doesn't even help if I move the "zero-cost" stuff to a separate source file -- templates and other stuff that have to be instanciated or inlined won't be separable from the code that I want to debug based on the module they're running in…

[[gnu:: artificial]]
Post reply on HN