Gdb 7.9.1 with eclipse on OSX Yosemite - gcc

I am using Eclipse LUNA CDT on my Mac OSX Yosemite and I recently set up GDB 7.9.1 on my machine to debug my applications.
I noticed that the debug session is very poor: no step run per instruction, no stop on break points, I can not watch the variables content or visualise the memory (stack/heap) etc...
Does anyone use GDB for the same purpose?
Is this a limitation of Eclipse or did I install a wrong version somewhere in my development environment?
Thanks for help.
I show the following versions of my development environment:
Eclipse Version: Luna Service Release 2 (4.4.2)
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
gdb --version
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This GDB was configured as "x86_64-apple-darwin14.3.0".

Apple phased out support for GDB 7.9.1 in favor of LLDB beginning with Yosemite. Unfortunately Eclipse CDT doesn't support LLDB.
Try installing the mac ports version of gdb and the apple-gcc
compiler:
$ sudo port install gdb-apple
$ sudo port install apple-gcc42
Code sign gdb-apple after you create a system cert for it:
codesign -s gdb-cert $(which gdb-apple)
Restart the taskgated process.
Set the debugger in eclipse to use gdb-apple instead of gdb , it
should be installed to /opt/local/bin/gdb-apple
More details can be found here
http://ntraft.com/installing-gdb-on-os-x-mavericks/

Related

Homebrew GDB can't open core file on Yosemite 10.10

I installed GDB 7.8.1 and GCC 4.9 through Homebrew.
When I open a core file generated by a GCC-compiled (gcc-4.9 -g xxx.c -o xxx) program, it reports:
→ gdb ./list_test /cores/core.1176
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin14.0.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./list_test...
warning: `/var/folders/r1/3sx4x5k1557g_v5by83k4hg00000gn/T//cchuMtAU.o': can't open to read symbols: No such file or directory.
(no debugging symbols found)...done.
"/cores/core.1176": no core file handler recognizes format
I googled and found someone suggested to use LLDB instead of GDB.
Is is possible to use GDB to debug the core file? And is it because GDB does not support the binary format on Yosemite?
Based on the long GDB developers' discussion thread on this issue, it seems Apple did not merge their changes back to the official GNU mainline, and instead chose to publish the modified source code on their own site. As a result, the Homebrew GDB install (which uses the stock GDB sources) can't load OS X core files.
At this point, I see three choices:
Give in and learn LLDB. There's a GDB to LLDB cheat sheet to help.
Install Apple's custom GDB from MacPorts. I've long forsaken MacPorts, so I can't test it, but if you have MacPorts installed, try the following:
$ sudo port install gdb-apple
$ codesign -s <your_GDB_cert_id> /opt/local/bin/gdb-apple
$ /opt/local/bin/gdb-apple ./list_test /cores/core.1176
Translate MacPorts' GDB patches and build spec into a Homebrew formula. It's theoretically possible, but I don't have the time to do it myself.
Personally, I've opted to just learn LLDB. Apple has moved permanently to LLVM, so it's probably just a matter of time before the old patched GDB stops working with the latest-and-greatest Xcode tools.

Install multiple versions of Apple LLVM on MacOS Maverick (10.9)

To test the portability of a piece of code, I would like to install both Apple/LLVM 4.2 (based on LLVM 3.2svn, from XCode 4), and Apple/LLVM 5.0 (based on LLVM 3.3svn, from XCode 5) on the same machine, running Maverick (10.9). I do not need XCode itself, only the compiler suite. Is there a recommended way to install two different versions of Apple/LLVM?

Debugging Qt app with Qt Creator: <no such value>

I'm using Qt Creator with Qt 5.1.1 in Ubuntu 12.04.
When I'm using the debugger to show content of any variable, the window always show "no such value" on every variable. Also on variables of type QString, int etc.
Is there a configuration problem on my Ubuntu?
Can anybody help me please?
It's been a year and a half ago, but the problem still remains actual for Ubuntu 12.04, Qt Creator 3.4.0 based on Qt 5.4.1.
As mentioned in Qt Creator Manual
Starting with version 3.1, Qt Creator requires the Python scripting extension. GDB builds without Python scripting are not supported anymore and will not work. The minimal supported version is GDB 7.5 using Python version 2.7, or 3.3, or newer.
I suppose that gdb --version gives you 7.4 (the last version of gdb for Ubuntu 12.04). That's why you have no such value issue.
1. Install a fresh gdb (7.8)
Remove the current gdb (to avoid conflicts with new one) and install development packet for python (to build gdb with Python scripting)
sudo apt-get remove gdb
sudo apt-get install python2.7-dev
Install gdb from the sources
wget http://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.xz
tar -xf gdb-7.8.tar.xz
cd gdb-7.8/
./configure --prefix=/usr/local --with-python
make
sudo make install
Now gdb 7.8 is in /usr/local.
2. Update Qt Creator settings
Open menu Tools > Options ...
Select Build&Run, tab Debuggers
Click Add
Type Name you like, write Path: /usr/local/bin/gdb
In tab Kits change Debugger: with that you just created
Hope this help someone who still love Ubuntu 12.04 and Qt.

How to make the "Locals and Expressions" debugging window operational with gcc 4.8?

I am using gcc 4.7 and gcc 4.8 together with QtCreator 2.7.1.
The problem is that when I use gcc 4.8, I am unable to see the values of my variables in the "Locals and Expressions" window in debug mode:
While gcc 4.7 works fine:
I have tried to repair this by playing with the QtCreator options, but to no avail.
I am not sure, if this has actually something to do with the compiler version, but the problem goes away once I rebuild with the older version.
The reason probably is that gcc 4.8 is using by default newer format for storing debugging information (http://gcc.gnu.org/gcc-4.8/changes.html). If you are using gdb version less than 7.5 (see gdb --version) you need to provide -gdwarf-3 argument for compiling with debug info using gcc 4.8.
The same symptom can result from having a debugger that is too new, instead of too old!
In this case it's not about the GDB version, it's about the version of Python which was embedded into it when it was built. Ubuntu 13.10 ships with a GDB that's built with embedded Python3 instead of Python2. Qt Creator (at the time of this writing) is not compatible with that.
You can check to see if you've got a Python2 GDB by running it from a terminal and typing:
(gdb) python print sys.version
If you get an invalid syntax error, you've probably got Python3. That requires parentheses around what to print, so try:
(gdb) python print(sys.version)
When that comes back with a 3.x.x answer, Qt Creator's Python debugging scripts won't work (yet). So you'll need to get a GDB with Python2.
Here's my blog entry about it: QtCreator Debugger Not Showing Locals in Ubuntu 13.10.
In my case, it was what HostileFork described: ubuntu 13.10 + Qt Creator 2.8
This bug has been fixed in Qt Creator 3, not yet released.
To solve this without recompiling GDB, just use the release candidate of Qt Creator 3.
There are builds available on Qt project website or a PPA (ppa:p12/qtcreator) with last git version but build is broken as of today.

Gdb on Mac OS X v10.7 (Lion)

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!

Resources