Gdb on Mac OS X v10.7 (Lion) - macos

I am a new Mac user and wonder how to install the latest version of GDB (> 7.1). I prefer to use Homebrew, but I could not find GDB listed.
brew install gdb
Error: No available formula for gdb
What is the best way to do it?
When installed Xcode, it may have installed an older version. Currently,
$ which gdb
/usr/bin/gdb
$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul 1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
But I need version > 7.1
System version,
Model Name: MacBook Air
System Version: Mac OS X 10.7.1 (11B2118)

Homebrew does not provide gcc and the associated development tool formulas over concerns that custom/non-system compilers could break builds. Two possibilities for easiness:
Use http://www.macports.org/
Look here https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
This is probably the command for you:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

Some new users may find themselves in the same situation given the Mac OS X v10.9 (Mavericks) upgrade.
Solution
Install the development tools and Xcode
Then install Homebrew
Then do:
brew install homebrew/dupes/gdb
You will notice that some applications will not allow you to use the newly added GDB.
This is because it is not signed by Apple any more.
To side step this issue: Follow this; thanks to #andre
I've had some people hit me up on IRC for more detailed instructions for this. I made a post on my site. You can find it here.

This does not directly answer the given question, but if you're like me, what you really want is a simple way to run (something very much like) gdb.
Apple now uses Clang as its compiler, and it turns out that the clang debugger, lldb, is installed along with the other command-line tools. It appears that lldb is designed with a user interface that mimics gdb very closely.
So, the answer to your question may in fact be:
just use lldb!

Related

how does compilation work exactly on os x

I just started getting into LLVM and clang compilers and the whole thing. I am following the book "Getting started with llvm core libraries". I was under the impression that OS X comes bundled with llvm. However it seems that is not the case. I need to install llvm separately to get command line tools like llc or lli.
So my question is, when I do a "clang" to compile my c/c++ code, what backend does the work of creating the machine code ? My installation shows commands like llvm-gcc and llvm-g++ . Does it mean that it uses gcc internally for creating machine code? And do i need to brew install llvm to switch completely to llvm ?
If you just want clang, and plan to do mostly high-level language development (C, C++, ObjC), then I recommend installing the Xcode command line tools. You can get those from https://developer.apple.com/downloads/index.action?name=for%20Xcode (or you can install all of Xcode if you prefer).
If you want lower-level tools like llc, then my recommendation is brew, as you suggest.
If you're goal is just Mac development, then Xcode is the better solution. If your goal is working on LLVM, then brew is the better answer (or pull the sources and build it yourself).
If you want both on the same machine, I'd recommend not installing the command line tools. Just install Xcode and LLVM. Then you can run the Xcode versions using xcrun without colliding with your LLVM installation.
clang doesn't use llvm-gcc as a backend. It includes LLVM. llvm-gcc is a modified version of GCC that integrates with the LLVM backend, which allows programs that expect GCC-specific features to work with LLVM.

GDB command not found when installed from MacPorts Mavericks

I am trying to install GDB to work with LiteIDE, on Mavericks.
After some research, I found out that GDB does not come with Xcode anymore, and that you have to install it yourself. Short of actually installing GDB from source, and self code signing (id rather not do this), I would like to use MacPorts to get this done.
I did port install gdb, which ran and succeeded as far as I know. After the install, I closed terminal and then typed gdb and I get -bash: gdb: command not found
Does anyone have a solution for this, using MacPorts???
You should use the command "ggdb" to start the MacPorts' build of gdb.
I don't know why they have renamed it, probably a transient bug/change that will be fixed somehow, I suspect they wanted to avoid a collision with the alias "gdb" launching LLDB.
Edit: Reworded the answer to avoid ambiguities as reported by #trojanfoe
I finally figured it out, with some help from #xryl669. His tip that you have to use the command "ggdb" in order to access this port from macports, is correct. Also, however, I missed a command that displayed after the port installed:
You will need to make sure
/System/Library/LaunchDaemons/com.apple.taskgated.plist has the '-p' option,
e.g.
<key>ProgramArguments</key>
<array>
<string>/usr/libexec/taskgated</string>
<string>-sp</string>
</array>
To do this, type
sudo nano /System/Library/LaunchDaemons/com.apple.taskgated.plist
And then add the "p" after -s. I don't really know what this does, but after this "ggdb" command started working for me
Edit: Adding the p is recommended but simply using "ggdb" should do the trick
I don't have Mavericks yet, but since Xcode 4.3, the command-line tools are optional: https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_3.html
"The command-line tools are not bundled with Xcode 4.3 by default. Instead, they can be installed optionally using the Components tab of the Downloads preferences panel.".
I have Xcode 5.0.1 on OSX 10.8.5 and gdb is definitely there after doing the optional command-line tools install:
$ which -a gdb
/usr/bin/gdb
$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Wed Feb 6 22:51:23 UTC 2013)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
$
I spent some time and figured it out with help of great documentation.
1. Install ggdb using MacPorts: sudo port install gdb, the file will be /opt/local/bin/ggdb.
2. Follow tutorial https://www.ics.uci.edu/~pattis/common/handouts/macmingweclipse/allexperimental/mac-gdb-install.html and it works.
I spent number of days and many various tutorials, this one actually works !
Good luck.

Desperately trying to build open source tools (octave) on a Mac 10.6 Snow Leopard (involves Xcode, gcc, fink)

The ironic thing is that all this used to work on my Mac, but Apple no longer supports 10.5.8, so I was forced to update to Snow Leopard, 10.6. And everything broke (thank you Apple).
On the surface, it seems simple. Build an open source package like octave under Snow Leopard (Mac OS X 10.6)
Apple has made this difficult, to say the least. They no longer download XCode for older operating systems unless you are a paid developer. My Macbook pro 2.16Ghz cannot load Lion, so that option is not available.
My old fink doesn't work because it was old. In order to build a new one, I need Xcode 3.2, which I can't get (see above).
I downloaded a free gcc 4.2, and it works fine.
So in order to try to build octave, it's the old style gnu install:
./configure
make
make install
./configure fails because there is no fortran installed. That's a special case because the install of gcc didn't include fortran. So a fallback would be building a complete gcc which I have done in the past.
downloaded gcc 4.9:
gcc-4.9-20130728
inside, gcc49
gcc can't build because it needs the three subsidiary packages gmp, mpfr and mpc
I am now trying to build these, so that I can bootstrap a complete gcc build, but in the meantime, is there any simpler way to bootstrap these things? I find it hard to understand why no binaries are available for:
fink
octave
which would solve part of my current problems.
You can still get XCode. You just have to be registered on Apple Developer, but you do not have to pay for the license. You then download it through the Mac App store, or you can get a link that opens it in the App store here. Finally, you have to install the command line tools from within Xcode. These can be found under the Components tab of the Download Preferences panel.
Let me know if that does not help. My iMac running 10.6 is currently in for repairs, so I am on my 10.7 laptop and cannot test all the specifics yet.

confused about macports

I am using MacBook Pro Mac OS 10.5 with related version of XCode. I am new to this development environment. I am learning macports, and I read information about macports from http://www.macports.org/. But I am still confused what macports is after reading information from this site.
I am previous working on Windows and Linux, could anyone let me know what macports is (in easy words) and what is the similar item on Windows/Linux?
thanks in avdance,
George
macports is a way of getting executables and other compiled code installed on your computer without having to work out the details of compiling/linking each apllication.
It is equivalent to a package manager under Linux and other Unicies. There is no direct equivalent under Windows.
It is just a convenient way to install a lot of *nix soft on your mac book. They are installed separately (not overwriting) from binaries/daemons/libs already installed on your mac (by default in folder /opl/local). Also they are much fresher than those installed on your mac.
For example 10.6 ships with bash 3.2, but after running sudo port install bash, you will get version 4.x (to make it your default shell add /opt/local/bin/bash to file /private/etc/shells, run chsh -s /opt/local/bin/bash and reopen terminal).
Note other os x package managers: fink and homebrew (superuser question)

Using 'make' on OS X

I have a MacBook Pro that I'm trying to do some development on.
I have a program I want to build, and when I went to use make to build it, I got a "command not found" error. I did some googling and Stack Overflow searches and it doesn't look like this is a common problem. Why don't I have make installed and how do I get it?
I'm extra confused, because I know I used it relatively recently (in the past month or so) when I was on this laptop.
For those of you who get to this page using Xcode 4.3 and Lion, the command line tools are no longer bundled by default, and there is no /Developer anymore. To install them, open Xcode, go to Preferences -> Downloads -> Components -> Command Line Tools. This should install make, gcc etc.
Have you installed the Apple developer tools?
What happens if you type gcc -v ?
It look as if you do not have downloaded the development stuff. You can get it for free (after registration) from http://developer.apple.com/
There is now another way to install the gcc toolchain on OS X through the osx-gcc-installer this includes:
GCC
LLVM
Clang
Developer CLI Tools (purge, make, etc)
DevSDK (headers, etc)
The download is 282MB vs 3GB for Xcode.
You will have to install the "Developer Tools" that are provided as optional packages in OS X installation disks.
For Xcode 4.1 you can simply add /Developer/usr/bin to the PATH environment variable. This is easily done:
$ export PATH=$PATH:/Developer/usr/bin
Also be certain to update your ~/.bashrc (or ~/.profile or ~/.bash_login) file.
In addition, if you have migrated your user files and applications from one mac to another, you need to install Apple Developer Tools all over again. The migration assistant does not account for the developer tools installation.
If you've installed Xcode 4.3 and its Command Line Tools, just open Terminal and type the following: On Xcode 4.3, type the following in Terminal:
export PATH=$PATH:/Applications/Xcode.app/Contents/Developer/usr/bin
#Daniel's suggestion worked perfectly for me. To install make, open Xcode, go to Preferences -> Downloads -> Components -> Command Line Tools.You can then test with gcc -v
I agree with the other two answers: install the Apple Developer Tools.
But it is also worth noting that OS X ships with ant and rake.
I believe you can also get just the Xcode command-line tools which is about 170 MB.. It's described in the 'brew' setup guide: https://github.com/mxcl/homebrew/wiki/installation and can be found here: https://developer.apple.com/downloads/index.action#
Edit: this was already mentioned above by #josh
I found the Developer Tools not as readily available as others. In El Capitan, in terminal I just used gcc -v, it then said gcc wasn't available and asked if I wanted to install the command line Apple Developer Tools. No downloading of Xcode required. Terminal session below:
Pauls-MBP:~ paulhillman$ gcc -v
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
Pauls-MBP:~ paulhillman$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Resources