How to use valgrind for a existing project - macos

Someone told me that valgrind is a great profiling tool for general performance / cache misses.
But how do I use this tool for a large existing c++ project?
I'm working on this project with the XCode IDE (OS-X).
What would be the next step to get valgrind working for this XCode project?

Valgrind has a good documentation.
See e.g. http://www.valgrind.org/docs/manual/QuickStart.html
and http://www.valgrind.org/docs/manual/manual.html
For profiling, see:
http://www.valgrind.org/docs/manual/cl-manual.html

ok i figured out how to use valgrind with xcode:
1) Create new Scheme, no target and enter name (e.g. Valgrind)
2) Info -> Edit Scheme
3) Select Executable -> Other -> to the valgrind executable
(mine e.g: /usr/local/bin/valgrind)
4) Arguments -> add the valgrind arguments (e.g for cache misses
--tool=cachegrind)
5) Add the programm executable as arguement (e.g. /DerivedData/PerformanceTest/Build/Products/Release/PerformanceTest)
It might be possible that XCode automatically stores the Build folder in
/User/username/Libary/Developer/XCode/DerivedData/XXXXXXXXX..
But you can change the destination of this folder somewhere
For me this works perfectly!

Related

Profiling from Xcode

ALL,
I'm trying to find a memory leaks in my software written in C++. Everything is written and compiles fine when I try to run the build.
However, when I try to do "Product->Profile", the compilation fails. The compiler couldn't find some header file.
What is wrong and how do I fix it?
TIA!
Check the Scheme. Product -> Scheme -> Edit Scheme or Command <. See what's different within them.
Another place to look is Project Settings: General -> Linked Frameworks or something under Build Phases.

How can i set what version of a product I'm in Eclipse?

I've created, debugged, and revised a project that I've been working on, but now I want to be able to specify what version of the binary I'm on. I'm using Eclispe-CDT with MinGW to make this project on my local system, so there is no versioning software involved. Does anyone know how to specify this for both Windows and Linux platforms?
On Windows, the idea is to produce a COFF file with the relevant information.
That is done by adding a step to the build, using windres (found also here).
See this thread as an example.
you could add windres via the project properties/Builders as an additional builder and add the generated object file in the C/C++ Build/GCC C++ Linker/Miscellaneous/Other Objects.
Then you
- a) could do a clean build if the resource is changed or
- b) could change the build options (if you have patience) to change to do a clean build every time you save the project.
On Unix, this doesn't seem to be supported in a similar fashion.

Using Xcode for generic C/C++ development

I'd like to use all the power of Xcode for generic C/C++ projects but I can't figure out what are the basic steps to configure a new Xcode project and attach it to an existing source tree of a legacy, plain, C/C++ project.
Creating a new empty project, attaching it to a source tree and configuring a build target (using GNU Make) was a really silly task.
I can't figure out how to enable source code indexing in order to enable source refactoring tools, searching and fast-jumping and all the amenities that makes the Xcode programmer's life great.
Moreover I'd like to use the internal debugging facilities…
Does anyone point me to a tutorial, a hint or whatever could be useful?
Thanx
I've found a (dirty) path to enable refactoring tools:
I've added a new standard «console target» to the project and added all the source files under the Build Phases > Compiled Sources.
Refactoring tools now works. Having two targets doesn't seem to be a relevant issue (elegance apart)
Personally, I wouldn't attempt to use legacy Makefiles, even though I think there's some support for that.
Typically what I do with a traditional C/C++ project is to store my XCode project folder at the root of the project. So it might look like:
--myApp
--src
--inc
--myApp Xcode
I then drag the src folder and inc folder into the project navigator. This gives me an Xcode project to compile with on the Mac, and then I have the traditional Makefile for compiling on Linux (actually, I prefer CMake for other platforms, but either way works).

How to get started with D on Mac OS X 10.6 (Snow Leopard)

I've been interested in "D" for a couple of years now and recently decided to start actually playing with it. I've been able to grasp the basics quite easily, I love the basic feature set of the language and the more I read about it, the more impressed I get.
Now, I'm very interested in writing a custom web application server as a hobby project and I want it to be a simple binary, using dynamically linked libraries for the actual web applications. I believe D to be the perfect language for this venture.
There is only one big problem... over the past couple of days, I have been completely unable to get any kind of IDE setup working. I can compile and run everything just fine on the command line, but everything I try in any of the IDE's available (Code::Blocks, eclipse+descent, Xcode with D plugin, and even the windows D-IDE running in VirtualBox on Windows XP Pro) the only thing that ever happens is:
object.d: Error: module object cannot read file 'object.d'
After two days of trying different things and following tutorials, this is really getting on my nerves. I want to learn to use D efficiently, but I need some comfy tool chain that includes code completion in the editor if I want to keep my sanity, which I obviously do.
[edit:added emphasis to the really important bit]
Is there anyone that can help me set up eclipse or (preferably) netbeans (but no plugin seems to be publicly available) to give me compile and run abilities in the IDE, along with code completion? on my Mac, running Mac OS X 10.6?
I want to use the phobos libraries (and therefor a 2.0 compiler) but I don't really care if its dmd or gdmd (gdcmac).
[addition]
I believe we can assume that my dmd compiler installation is in order because it works from the commandline. I just don't want to use it from the commandline because its tedious. The question is about and IDE, the compiler works, its just IDEs that won't
Well, the persistent bugger in me could not leave the problem alone and I finally got it to work.
The required components to get it all working on Mac OS X 10.6 are:
DMD compiler
Eclipse "Galileo" (version 3.4)
Descent
DSSS
a change to /usr/etc/rebuild/default
a new file i hacked together /usr/etc/rebuild/macosx.conf
global and per-project settings for Eclipse
After following these instructions you'll have Eclipse able to do code completion on your D projects and you'll be able to build/run from within the IDE as well.
The actual steps to get it operational are as follows.
install the digitalmars dmd 2.0 compiler
download the binary distribution from digitalmars.com (direct link to 2.041)
unzip the downloaded file into ~/somefolder (that created a ~/somefolder/dmd2 folder for me which I'll use for the duration of this example.)
in the terminal (/Applications/Utilities/Terminal.app) move the files to their destination
sudo mv ~/somefolder/dmd2/osx/bin/* /usr/bin/ enter your login password when asked
move the just copied dmd.conf to its location: sudo mv /usr/bin/dmd.conf /etc/dmd.conf
sudo mv ~/somefolder/dmd2/osx/lib/* /usr/lib/
sudo mv ~/somefolder/dmd2 /usr/
use your favorite text editor to edit /etc/dmd.conf to contain the following:
[Environment]
DFLAGS=-I/usr/dmd2/src/phobos -I/usr/dmd2/src/druntime/import -L-L/usr/lib
Download and install your favorite Mac OS X version of eclipse out of the umpteen hundreds available at http://www.eclipse.org/downloads/ (I picked a cocoa version for c/c++)
Install Descent (almost as per the normal instructions in the wiki)
run Eclipse (don't bother running as root)
goto Help -> Install New Software from the menu bar. (wtf does that do in the Help menu?!)
copy/paste http://downloads.dsource.org/projects/descent/update-site into the url field.
follow on screen instructions to finish installation.
install dsss from sourceforge (direct link to .dmg)
use the installer package on the disk image like any other.
create a file /usr/etc/rebuild/macosx.conf and paste the following snippet into it. (and save, duh)
profile=phobos
compiler=dmd
inifile=dmd.conf
exeext=
objext=o
version=DigitalMars
noversion=GNU
version=MacOSX
version=linux
noversion=Unix
noversion=Posix
noversion=Windows
noversion=Win32
noversion=Win64
version=X86
noversion=PPC
noversion=X86_64
version=D_InlineAsm
version=D_InlineAsm_X86
noversion=D_InlineAsm_PPC
noversion=D_InlineAsm_X86_64
version=LittleEndian
noversion=BigEndian
[compile]
cmd=dmd -version=MacOSX -c $i
flag=$i
incdir=-I$i
libdir=-L-L$i
optimize=-O
version=-version=$i
[link]
oneatatime=yes
#cmd=dmd -L-lphobos $i -of$o
cmd=dmd $i -of$o
# cmd=dmd -L--start-group -L-lphobos $i -of$o
libdir=-L-L$i
lib=-L-l$i
flag=-L$i
[liblink]
safe=yes
oneatatime=yes
cmd=if [ ! -z "$o" ]; then ar rc $o $i; fi
libdir=
lib=
flag=
[postliblink]
cmd=ranlib $i
[shliblink]
shlibs=no
[dyliblink]
dylibs=no
change the /usr/etc/rebuild/default file to read: profile=dmd-macosx
Set up Eclipse to have code completion
In the global eclipse preferences navigate tp D => Build Path => User Libraries
click New, type "std", press OK select the newly created entry, click Add Directory
navigate to /usr/dmd2/src/phobos/std and add it.
Set up Eclipse project.
You have to do this manually for every D project you'll make
Create a new project with the "D => D Project" wizard (thanks to Descent)
Go into project properties (right click project in the Project Explorer and choose Properties)
In the list to the left select D Build Path and in the panel that appears choose the Include Path tab.
Click the Add Library button and choose std in the second page of the wizard.
Configure the extarnal build tool
Go to External tools configurations... (from the dropdown in the little green play button with the toolbox in front of it in the build/run/debug toolbar thingy)
In the list to the left right click Program and choose New from the context menu.
give your config a decent name like "Build with dsss" and set the following options:
Location: /usr/bin/dsss
Working Directory: full path to directory with your dsss.conf file for the project
(if you don't have a dsss.conf file create one on the commandline: dsss genconfig)
Arguments: build (or rebuild, or clean, or...)
repeat steps 2 and 3 above for as many build/run options as you require.
Congratulations, everything should work now.
If for some reason this does not work for you, let me know and I'll be happy to figure out where it went wrong and help you to get it working. If there's a better or simpler way, I'd love to know about it as well.
object.d: Error: module object cannot read file 'object.d'
clearly indicates that it can't find the libraries properly. So, the first question is how your dmd.conf is set up. You need to make sure that it's pointing to the correct places for src/phobos, src/druntime/import, and osx/lib - wherever you put those. Personally, I put the dmd code in a subfolder of home and don't try and install it in /usr, but the instructions do tell you to install them there as the default, so it should work.
Assuming that your dmd.conf looks okay, the most likely situation is that it's actually using the wrong dmd.conf. Per the instructions on the digital mars site ( http://www.digitalmars.com/d/2.0/dmd-osx.html ):
dmd will look for the initialization file dmd.conf in the following sequence of directories:
1. current working directory
2. directory specified by the HOME environment
3. variable directory dmd resides in
4. /etc/
My guess is that you put dmd.conf in /etc and have been editing that one but left the original dmd.conf in
/where_dmd_is/dmd2/osx/bin/
Certainly, I've had that happen to me a time or two. In any case, the first thing that you need to make sure of is that the dmd.conf that you're editing is the one that dmd is using (so make sure that the places where dmd looks first don't have a dmd.conf), and the second thing that you need to make sure of is that the paths in your dmd.conf correctly point to where the dmd stuff is. If those two things are correct, then dmd should find the libraries correctly.
On a side note, I would point out, however, given your comment about wanting to use shared libraries is that shared libraries don't work correctly with D2 right now (I have no idea whether they work with D1 since I don't use D1 - I suspect that they don't though). There have been discussions about it on the D newsgroup ( http://www.digitalmars.com/NewsGroup.html ), so you can look there. It is something on the radar and is being looked into, but doesn't fully work yet. Also, you can look to the newsgroup for further help on D-related issues. It's probably the best place to ask right now.
If it's a question of an IDE, as far as eclipse goes, I believe that the plugin to look at is descent: http://www.dsource.org/projects/descent
Unfortunately, I haven't tried it myself yet, so I don't know how good it is. According to its wiki page, it's primarily intended for D1 but does support D2 to at least some extent.
If you wanna get started quickly (aka Double-click-install): D for Xcode
Requirements:
Xcode
That's it. Installs the latest dmd compiler, so it works in Terminal too etc.
As i keep seeing this question coming back in my search results every now and then, I figured I'd keep it relevant.
Nowadays; In the Mountain Lion era, a much easier solution exists in the Mono-D project
Just install MonoDevelop (or Xamarin Studio) and follow the five minute installation manual
(You can use Phobos on D 1.0. Anyway…)
Where did you install the Phobos and druntime headers?
<the .zip file>/src/druntime/
<the .zip file>/src/phobos/
Usually I copy them into /usr/include.
(Also, try to edit dmd.conf to use the absolute path:
[Environment]
DFLAGS=-I/usr/include/phobos -I/usr/include/druntime/import -L-L/usr/lib
)

Xcode makefile or compilation options

I am new to Xcode. Once I configure my C++ command line application to build, and it builds successfully, I have sometimes no clue about how Xcode calls GNU C++.
Is it possible to get the makefile that Xcode creates or how to see the compilation options created by Xcode?
Thanks
Xcode doesn't actually create a makefile; among it's other functionality, Xcode replaces make. But you can see all the options, etc., Xcode uses to build you code. Just open the project in Xcode, and select Get Info from the File menu. Browse the resulting dialog box for almost anything you could possibly want to know about Xcode build settings.
Or you could use a tool likePBTOMAKE, an OS X application that can convert Xcode projects into makefiles, but it hasn't been updated in a few years.

Resources