Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Languages like Python, MATLAB, E-Lisp have this nice facility for doc-strings.
With this feature using just a few keystrokes in the terminal, you can fetch the documentations of the functions / module you have written and imported into your code.
Now is there any "technique" (library, Editor tricks , whatever to ) to get a similar facility in
C++ / C. Suppose I include the documentation of the function within the source file at
the head of the function,
then I would like to type a command like getinfo at the terminal. (something
like a man page)
I know such a 'man' facility exists for many C functions, but the documentation for these functions are written in separate text files from the source code. I would like the
documentation to be in-place
You can use something like doxygen. It has support for generating man pages, among other formats.
Visual Studio can/will generate popups containing information extracted from DocXml formatted comments. You have to compile with /doc, which will extract the XML from the comments to a .xdc file. Then you have to run xdcmake to compile the .xdc files into an xml file. You'd typically handle all this automatically in the build process, so you don't have to do much manually (except write the comments themselves, of course). The one thing to keep in mind, however, is that the code (at least a declaration) has to build before you get the popups.
I feel obliged to add that IMO, most such comments are generally pretty close to useless. If a corporate standard makes them unavoidable, so be it -- but if they're honestly providing any useful information, I'd consider that an indication of a problem ("Code smell", if you prefer that wording). In most cases, the combination of the name of the function (or whatever) and the names/types of the parameters should make the use of the function quite clear.
If you notate your code with comments in a syntax similar to Javadoc, you can generate a documentation for your code, in various different formats, using Doxygen. It can generate, among other things, man pages, but it seems that the preferred output format people use is HTML pages.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to learn how can I find source codes of __builtin functions like __builtin_cbrt() in C++. If you know, Can you help me?
I want to learn how can I find
First become acquainted with the language you are working with - learn C and C++ programming languages. Learn about the tools like git and autotools and the environment around these programming languages. Become familiar with the tool set needed browsing files - at least grep, but I recommend it's (way) faster alternatives - "the silver searcher" ag or ack, but be aware of tools like ctags or GNU Global.
Then research. GNU projects are available open source - it's very easy to find source code of GNU projects, nowadays they are even mirrored on github.
Then it's just a "feeling" or "experience". Surely a project will have builtins functions in a file named "builtins.c" or something similar. Be curious, reasonable and inventive. If you would want to add a builtin function to a codebase, where would you put it? Become familiar with the project structure you are working with. And expect big and old projects to have stuff scattered all over the place.
First I find gcc sources with builtins.def (BUILT_IN_CBRT, "cbrt", and some references of BUILT_IN_CBRT in builtins.c.
After cloning the gcc repository I scan for BUILT_IN_CBRT macro name. Browsing the code leads me to CASE_CFN_CBRT macro name, which leads me to fold-const-call.c:
CASE_CFN_CBRT:
return do_mpfr_arg1 (result, mpfr_cbrt, arg, format);
By the name of the file fold-const-call.c I suspect this part of code is taken only when folding a constant call.
From there I can browse google about mpfr_cbrt symbol, which leads me to GNU MPFR library. I find clone of MPRF library on github and search for a file named cbrt, I find cbrt.c with mpfr_cbrt() sources with the source of cbrt within MPRF library. This is the code that will be called and will compute cbrt of a number when __builtin_cbrt is folded inside a constant expression, I suspect.
When not in constnat expression, I suspect that [fold_const_call_ss]https://code.woboq.org/gcc/gcc/fold-const-call.c.html#_ZL18fold_const_call_ssP10real_value11combined_fnPKS_PK11real_format) is not called at all, instead some fold_const_* function returns to gcc that the expression cannot be constantly folded so a call to the actual cbrt() standard function is generated.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have a class project where we need to take a 32-bit executable written in C++ and disassemble it and modify the assembly code and then reassemble it. We're supposed to do things like hardcode cheats into the game.
I've been searching for hours and I can't find any software that will do this. I've looked at Ollydbg and spent about two hours with it and couldn't really figure out how to get it to work. I utilized Cheat Engine and that actually worked out really well for me - I was able to isolate the code modifying the addresses I cared about and replace it with code to have a favorable impact on the game, but as far as I can tell Cheat Engine has no ability to recompile the modified code.
This is a fairly lower level Computer Science class so please take into account my ability level when making suggestions but if there is any software out there or alternative ways that will allow me to do this I would greatly appreciate it. Thanks!
Since you mentioned OllyDBG and Cheat Engine I'm going to assume you're using Windows.
First, you can use OllyDBG to save a file, but for some reason I can't find this option in OllyDBG 2, only in older versions (like 1.10). You can right-click on the code window and then copy to executable > all modifications, A new window will open, right-click on the new window and then choose save file.
An alternative that I really like is x64dbg. it's an open source debugger/disassembler and has an option to save changes via "Patches".
Another option is to apply the changes via an hex editor, which allows you to modify any file (including executables) in a binary format. It is, of course, a bit harder to do since you need to translate your changes to op-codes manually, but if your changes are not too big or only consisting of modifying some constants it can be a faster and easier solution. There are a lot of hex editors out there but my favorite is XVI32.
What I personally like to do is to modify the memory via code using Windows API's WriteProcessMemory and ReadProcessMemory since it allows you to do this things dynamically.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
is there such a thing as a (free) tool that would display a graph of all functions call in a given function?
For instance, if I use it on a complex function fun() I'm trying to understand, it would show me all the functions called by fun() in order, then I would have the possibility to see the same thing for the function called by fun(), and so on.
I'm looking for this for C++ code.
Does such a thing even exist?
edit : I am using VS 2008 if that helps, but I was thinking that such a software would work on the source files anyway
Doxygen can do this. See the CALL_GRAPH configuration option:
If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will generate a call dependency graph for every global function or class method. Note that enabling this option will significantly increase the time of a run. So in most cases it will be better to enable call graphs for selected functions only using the \callgraph command.
Yes, Eclipse CDT Call Hierarchy view provides exactly this. Moreover, this view has 2 options:
Show Callers
Show Callees
You are asking about second one, but I am prefer the first one in code analysis.
Intel(R) Single Event API is free open-source project that utilises GraphVis for call-graph visualisation. It takes a bit of labour to do manual or compiler-automated instrumentation, but beside statistics and call-graphs you will get the overtime views as well.
Yes such things exist. Google under the heading static code analysis. There are, for example, tools such as Understand, and it is extremely likely that your compiler can do this too for which I refer you to its documentation.
You can use callgrind, and it's GUI tool kcachegrind.
I don't know of any tool specially desgined for this. However, there are a few ways of doing it:
Using a IDE (QtCreator is free, Visual Studio Express might also be helpful, Eclipse CDT)
Using (ctags)[http://ctags.sourceforge.net/] and a able text editor.
Using callgrind and the several views it brings. Advantage: you get to see the functions that are really called. Disadvantage: only runs in unixes, and you have to profile.
Using Doxygen... this one is really fancy, as it generates an html "view" of your code, provided that you supply the correct options.
g++ and most compilers can do what you want. It is called profiling. Also there is the oprofile. A profiler gives you the call graph of an application after its execution. This is very useful to study code, you can also walk through the [debug] output as you look at the graph. A code analyzer, in contrast, will give you all possible call paths however, you will not be able to see the significant path easily.
VC++2008/2010 profiler generates among others the file *CallerCalleeSummary.csv, that contains this information. And this is the link to the article explaining how to use it with sample program: Profiling of C++ Applications in Visual Studio
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Suppose you have got a bunch of files written in C, C++ or Fortran, by different authors, with different opinions on formatting, how to comment, and so on. I think many people know situations like these.
Are there any free tools for ends like:
uniform format of code (indent, etc.)
create standard comment bodies
rename variables
?
Have a look at
AStyle. It's a command line based formatter/beautifier. It doesn't handle Fortran though it works with C, C++, C# and Java
You can have a look at the indent (unix) command. It doesn't do everything you are asking for , but that's a good start I think
For Fortran there is plusFORT, which can do much more than what you ask for, such as reorganizing code and translating from FORTRAN 77 to Fortran 90. See http://www.polyhedron.com/pf-plusfort0html and http://www.polyhedron.com/pflinux0html
The CDT Plugin for Eclipse has great formatting and refactoring tools for C/C++.
The formatter can be customized to fit almost all needs.
Also the refactoring tools are quite powerful and renaming variables, classes etc. is an easy and safe task with them. (They use the indexer/parser to recognize scope of variables, so its not a simple search and replace. Matching patterns within comments can be changed automatically, too).
However, as far as I know there is no batch processing possible.
Edit: Another - obvious - drawback is, that you have to create a project to make the indexer (and thus the refactoring tools) work. So at least you have to add all include paths and important compiler defines to project settings.
I never tried, but the indexer should work fine without a real compiler available, but it may be necessary to make the project to use the "internal builder", otherwise you cannot set include paths. (I'm unsure about this, because I use the internal builder with gcc in my projects - this works fine.)
I've used Uncrustify with UniversalIndentGui for formatting C++ code. It works pretty well. Uncrustify offers many customization options and UniversalIndentGui "offers a live preview for setting the parameters of nearly any indenter. You change the value of a parameter and directly see how your reformatted code will look like."
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
We have a large amount of C/C++ code that's compiled for multiple targets, separated by #ifdefs. One of the targets is very different from the others and it's often important to know if the code you're editing is compiled for that target. Unfortunately the #ifdefs can be very spread out, so it's not always obvious which code is compiled for which targets.
Visual Studio's #ifdef highlighting can be helpful for visually identifying which code is compiled for which target, but changing the highlighting apparently requires modifications to the project file.
I'm interested in finding a tool or method that can help coders quickly recognize which targets are using each line of code. Even if it requires some sort of manual in-source annotation I think it could still be helpful. Best case it's automated, not tied to a specific editor or IDE, and it could be configured to warn in certain conditions (eg "you modified some code on Target X, be sure to test your code on that platform!").
If your code is getting that big that you can't tell what #ifdef your in then it's time to refactor your code. I would recommend that you refactor it into seperate cpp files per platform.
I noramlly only use #idef when the code is only one or two lines long, any longer and I normally refactor into it's only function or class into there own cpp file. That makes it simple to figure out where you are.
Check out Visual SlickEdit. The "Selective Display" option might be what you are looking for. I can't find any on-line documentation on it, but it will allow you to essentially apply a set of macro definitions to the code. So you can tell it to show you the code as the compiler will see it with a set of macros defined. This is a lot more than preprocessor output since it literally hides blocks of code that would be excluded based on the macro definitions.
This doesn't give you the ability to answer the question "Under what preprocessor conditions is this line of code included in compilation" though. The nice thing is that it applies the selective display filter to searches and printing.
I know for a fact that eclipse cdt does it. It has other nice features and some not-so-nice features for an IDE. Now, I code with vi, so I might be biased.
I don't know if there is a tool for this already, but I'd guess would be fairly easy to roll your own by using the precompiler. Precompile your file with a set of specific #defines and the output is what the compiler sees for that platform. I reckon this is not the same as highlighting the current file, but it can be automated and integrated into your IDE, push a button get a temp file with te current edited one under specific #define. Didn't try it myself, is just an idea.
PS. Yes, I had to read couple times your post to searching for where exactly is 'code coverage' involved lol.
Check XRefactory and Cscout.