Recently we have started working with Intel's TBB and found that when debugging containers we cannot really watch the elements and their data.
Is there a flag setting, a plugin or a tricky way to enable this? (maybe a script snipit for Visual to work with)
What you are looking for is a expression evaluator. You can't do this with a simple flag, as there are an infinite number of data structures. But an expression evaluator is indeed a kind of plugin, it's definitely code.
I'm not answering your question "is there one" since I don't know, but instead of using an expression evaluator I'd use a custom visualizer. They're a pain to write but work relatively well afterwards.
The best resource is:
http://www.virtualdub.org/blog/pivot/entry.php?id=120
TBB is a relatively new (but exciting) library, and I won't expect extensive tools for debugging right now. You might try to implement a simple ring buffer (http://www.ibm.com/developerworks/aix/library/au-buffer/index.html) for logging and debugging.
Related
I would like to embed a scripting language(js, python, perl, even php, anything that's easy to use) in an OpenGL C++ application. I'd like to do this in order to be able to do things like:
print values of various C++ class members at runtime
cause interrupts that would wake up gdb at runtime
after I find a bug I'd like to write a small script oneliner to replicate it
I'm pretty sure this won't be easy. I want to ask whether this is a good/bad idea, and if it's worth the effort.
Example usecase
Let's suppose I rotate a line until it collides something and my collision detection has some SIGSEGV which occurs upon collision. I print out all the angles, find out which one was the one before the SIGSEGV and I write a small python thingie which displays some values so I can figure out what went wrong etc.
I guess basically What I'm trying to do is to avoid gdb and uhm.. I'd like if the program blows to have a way to check things in Python instead.
It's not that I don't like gdb, it's that I don't like the limited commands it has..
UPDATE: GDB can now be extended with Python out of the box. That solves a lot of the limitations of canned sequences of commands.
I don't think that for the purpose of debugging embedding a scripting language is a good idea. It's definitely possible, but for everything that you'd want to be able to access from the scripting language, you would have to provide some interface, since there's -- to the best of my knowledge at least -- no way to directly call C++ or read C++ data structures from a scripting language. I'd suggest you learn gdb or look for gdb frontends if you don't want to use gdb directly. I've used ddd and found it quite useful. The gdb frontend of Eclipse CDT is usable, too. Using a debugger gives you more flexibility, since the debugger knows about C++ and its data structures and thus allows you to inspect anything at runtime, without having to manually write much support code for that.
First of all: You can print all those out using GDB quite easily. Once in GDB you might want to try what "help data" shows.
Which IDE do you use? You might want to try the cross-platform IDE Code::Blocks, which interfaces GDB quite neatly.
If you want to interface with another language, you might want to have a look on "Lua". It is very easy to learn.
See http://en.wikipedia.org/wiki/Lua_%28programming_language%29
Lua is intended to be embedded into other applications, and accordingly it provides a robust, easy-to-use C API. The API is divided into two parts: the Lua core and the Lua auxiliary library.
This works well with C++, too, of course.
i can´t help with the questions if it´s a good or bad idea.
but you could take a look at Chaiscript that´s really easy to use with c++
Python is a very good choice as application scripting language. Its not a strong argument but I know that lua is widely used in game programming (I d'ont know why), it may be useful since you are using OpenGL.
Use lua - it's simple stack based interpreter. With very clean API.
E.g.: Simple code that add dt_format|dt_convert functions to lua
I tried to find a related question but all previous questions are about profilers for native c++ in windows. I googled a while and learned about gprof, but the output of gprof actually contained lot of obscure internal functions. Is there a good opensource c++ profiler with good documentation?
Valgrind
I totally recommend this
http://en.wikipedia.org/wiki/Valgrind
Don't use gprof, for the reasons given here.
What you need are stackshots, explained here. One way to take stackshots is the pstack utility. Another way is to use "Pause" or ctrl-break under the debugger. Also lsstack, if you can get a copy.
If you want to spend money, RotateRight makes a nice tool based on stack sampling called Zoom.
Compile using the flag -pg and use gprof.
If you don't mind the KDE library dependencies, KCachegrind is very useful with the added visualization. It depends on Callgrind and Valgrind, as one could have guessed, so no special compiler flags required during compile-time.
I've heard oprofile is really, really good for real time apps. Linux only though, AFAIK.
How much detail do you need in your profile reports. If you just want to do some really simple time profiling for a few functions, then the new functionality available via the C++11 chrono classes makes it easy to profile in a cross platform, cross compiler way.
See this article for some simple profiling code that works similarly to Matlab's super easy to use tic and toc functions.
I recently switched form ubuntu to MacOSX.
I also recently started heavily using multi threading.
What good addons/alternatives are there to g++ for debugging multi-threaded apps on MacOSX? In particular, I'm interested in tools that let me "poke" around classes/structs; to follow pointers, expand members, show the value of members, etc ...
Thanks!
Valgrind. Especially Helgrind.
It's not a GUI tool like you suggested, but it'll save you a hell of a lot of time.
Does Xcode with Shark and CHUD not do what you want?
Look into Spin and Promela. Spin is a model checker which runs through every state your code can be in to look for losses in safety and liveness. As you want, with spin you can step through it yourself and choose which option is run next and what values things should have. You need to write out the section you want to test in promela code which is similar to c though. Spin is better than regular debugging tools - multithreaded programs don't run in the same way every time so a model checker is more useful than a standard debugger.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for a good IDE for C++ that has most or all of the following properties (well, the first 4 or 5 ones are mandatory):
cross-platform (at least Mac, Linux)
of course, syntax highlighting and other basic coding editor functionality
reasonably responsive GUI, not too sluggish on mid-size (say, 100 files) projects (both my Linux and Mac computers are 5 years old)
code completion
integration with gdb
SVN integration would be nice too
refactoring (rename a variable semi-automatically throughout the codebase, etc.)
can display class hierarchy
can add hypertext-style links to the code (so you can click on a function/class name and it brings you to the declaration),
can show code parts that (potentially) call my function (I know that's hard to do for C++ so I added the potentially)
So far, I've been using Emacs for everything, but I think advanced features that give me more overview and search capabilities like the last three would be nice. I'm tired of just using grep and find on my codebase.
Basically, I want most of the things for C++ development that Java IDEs usually do.
I see Netbeans can be used for C++, as well as Eclipse. I think they would fit my requirements. Has anyone actually used them for daily coding? What are the differences? What are your experiences? Code::Blocks is more lightweight and doesn't do many of the things listed above, right?
Note: I don't need a GUI builder.
Update: With the bullet point 10 I mean that I can give it a function name (e.g. Foo::setValue), and it shows me all occurrences where this particular function (and not other functions of the same name, like Bar::setValue) is called in my codebase.
Code::Blocks does the first 5 and it's also got class method browsing (though not a heirarchy display). It's a much more lightweight solition thaen Eclipse or NetBeans, but if you like the minimalist approach it's pretty good.
To summarise CB versus your requirements:
Yes
Yes
Yes
Yes
Yes
No - but you can add it easily
No
No, but similar functionality
No
Can go from definition to decl and vice versa, but no callers list
As all the solutions you mention are free, you could always try them all and then make a decision on which one to stick with. That's what I did.
In addition to the ones mentioned, there's QTCreator, which has "Rapid code navigation tools" though I've not used it.
I think though that the non-essential requirements aren't so good, you can easily see where a method is being called using search! (of course, if you have a huge class hierarchy where every class has the same named method, you've only yourself to blame :) if you havn't laid your classes out in an easily understandable way)
I'd recomend Netbeans, in 6.5, its pretty fast IDE and offers all 10 of your requirements.
I recently asked this same question. I ended up choosing Eclipse with the CDT plugin and the Cygwin libraries. I've been pretty happy with it, except I haven't quite got the hang of the debugger. The window for walking through source on the debug perspective is pretty small, for some reason I haven't figured out how to see into arrays, and I think I knocked out one of the windows for displaying variables and don't know how to get it back. I've ended up abandoning the debugger perspective and just walk through debugs in the normal perspective.
Also, I use Eclipse for Java, so the helped minimize the learning curve. It can do refactoring and you can integrate svn.
Java based IDEs (Netbeans and Eclipse) are sometimes somewhat slow. Also their main focus is Java. One problem with Eclipse is that it is difficult to use for small screens, such as in laptops. I prefer to work usually in vim + ctags (to perform the functions of grep and find), and when I have some advanced operations like comparing two directory hierarchies, I use Eclipse. I've not used Code::Blocks much, but I hear good things about it.
Coming from Emacs, I think you'd prefer something lightweight and not heavy-weight. I would consider Code::Blocks then as a good candidate for exploration.
codeblocks is open source !!
http://www.codeblocks.org/
Go for Eclipse. If you have a decent computer, it is fast enough and has best possibilities with its plug-ins.
codeblocks have a lot of features just check them up !
and it is free !
If you already know Emacs, it may be easier to just start using a few more packages, than learn a whole new IDE.
For example, you can easily do #9 with Emacs: just run tags once and then M-. RET anywhere.
You also have to weigh the IDE's features against what you lose. For example, most IDEs don't tend to have Emacs' easy macro capabilities or numeric prefixes, which are often like a more general form of refactoring.
It is not only the IDE that matters - you would probably need to be able to build you application outside of the IDE (i.e. continuous integration).
Consider using CMake to create a cross-platform description of your build scripts. Once you have the CMake Script (which is straightforward) you can generate from it project files for the IDE of your choice - eclipse, kdevelop, Visual Studio, codeblocks, etc.
I would suggest using eclipse as an IDE. There are few options of how to use CMake with eclipse. Play around, and find the best for you.
Once more - CMake is not only cross-platform it is also cross-IDE. And CMake scripts are very readable, a simple make file would look like this:
project(hello)
add_executable(hello hello.cpp)
Now compare that with makefiles, or setting up a project in your favorite IDE!
My two cents (in no particular order ... and not all these options are c++):
Qt ... my first productive GUI building framework
Lazarus ... what a cool name, and very productive tool (not c++ though)
MonoDevelop ... I'm falling in love with c# development (very much like c++)
Java ... ubiquitous ( a bit like c++)
CHEERS!
Sublime Text Editor is the best cross platform editor so far I have seen. Try using it http://www.sublimetext.com/. It comes with unlimited demo period without suppressing any of its functionality. But if you are satisfied with that, please buy and use it to credit the author.
There are plenty of logging/trace systems for letting your program output data or strings or state as it runs. Most of these let you print arbitrary strings which you can view live or after your program runs.
I noticed an ad here on SO for Smartinspect which seems to take this to a higher level, giving stack traces for each log, fancier options like plotting graphs and data values which change over time, and a lot of polish to the basic idea of a simple list of output text strings.
Since I use C++, Smartinspect won't even work for me.
A little googling finds tons of logging frameworks, but nothing that seems to do anything more than text dumps. Are their fancier tools (similar to Smartinspect?) that do more? Commercial or open source is fine, and multiplatform is a big plus.
I know this is not the answer you are most probably looking for but I would suggest that such a framework will be very hard (if not impossible) to find for C++. Doing something like dumping the stack cannot be done in a portable way as it can in a language like Java, which not only shares a common runtime accross all platforms, but provides powerful introspection capabilities too.
I don't program in Java, but my guess is that it can provide a stack-trace in the same way as Python: the stack is probably just another object in the runtime which can be inspected and manipulated.
C++ on the other hand has none of these niceities: its meant to be a close-to-the-metal language that basically adds object-orientism to C (I'm sure others will come up with much more elanorate explanations of C++'s benefit's over C but thats another discussion).
In short, C++ is not rich enough at the level required to provide the kind of features you require in a generic way. There may be some platform-specific code that could get some of this info at defined points for you out there, but it certainly wont be standards compliant, cross-platform C++.
With regards to graphs etc, that sounds much more like post-processing, which you should either be able to find something for, or more likely, you can perhaps output your log messages in a format which can be interpreted by some of these existing tools.
Other things you could look at would be integrating with syslogd, for which again, there may be richer analysis tools for (this would provide you with a capability along the lines of the one advertised for SmartInspect - that is TCP/IP based logging).
NB: a lot of what I said here about C++ comes from previous experiences trying to find decent frameworks in C++ to do tweaky, introspective type things (such as proper mock objects etc).
I wrote a article about dumping the stack in C/C++ with Windows and Unix/Linux at DDJ some years ago. Maybe it helps you:
See http://www.ddj.com/architect/185300443
If you can restrict yourself to a certain platform you can add stack traces to your logs manually. We use e.g. the glibc functionality to get stack traces on Linux to attach stack traces into our exception class. There is similar functionalyty available on Windows, but as mentioned these infrastructures are not portable.