Eclipse/CDT on Linux and Mac OS X
Contents |
[edit] Installation of Eclipse/CDT Europa edition
[edit] Requirements
To run Eclipse you will need JRE 1.5.x or JRE 1.6.x.
[edit] Prepare your source tree
For this documentation we assume that you have your working copy at:
$HOME/work/mysql/mysql-6.0-falcon
Before using the MySQL source tree with Eclipse run the appropriate "BUILD/compile-xyz -c" script (notice the "-c" option). This way we get working Make files without building the whole source tree. These Make files are ready for use by Eclipse/CDT .
[edit] Installation
Installation got easier now: just go to
http://www.eclipse.org/downloads/
and downlad
Eclipse IDE for C/C++ Developers
for your platform. We tested this setup with Linux 32-bit/64-bit and Mac/Intel OS X.
[edit] Setup of development environment to work with MySQL
[edit] Create a project
- In "Project Explorer" create new project with right click "New" -> "Project". In the "Select a wizard" view choose "C++ Project" and click "Next" button.
- In "C++ Project" view choose "Executable" -> "Empty Project" and give your new project a name. In this example we use "Falcon" as name. Click "Next" and then "Finish".
- In "Project Explorer" there should be a new project called "Falcon" now.
- Link in your working copy into the newly created project. Right click on "Falcon" project and choose "New" -> "Folder". Click on "Advanced" button activate "Link to folder in the file system" and choose your working copy directory and click "Finish" button.
[edit] Adjust the build settings
- In "Project Explorer" right click on "Falcon" project and choose "Properties". In the "Properties" -> "C/C++ Build" view disable "Makefile generation" and set "Build location" to the folder you linked in.
[edit] Test the build environment
- From menu bar run "Project" -> "Clean..." it should start a "make clean" and a "make all" afterwards.
[edit] Debug with Eclipse/CDT
[edit] Create debug profile
In the icon bar click the bug symbol and choose "Open Debug Dialog". In the "Create, manage, and run configurations" choose "C/C++ Local Application" and in the "Main" tab tell where the mysqld executable is located.
In the "Arguments" tab declare the options for running mysqld (for instance the parameters of mysql-test-run.pl --manual-debug).
In the "Debugger" tab make sure that you use gdb/mi as debugger.
[edit] Using the Eclipse/CDT debugger
[edit] Starting the debugger
To start debugging mysqld click on the bug symbol in the symbol menu and choose the debug profile, which we have just created.
[edit] The "Debug Perspective"
Eclipse switches to the "Debug Perspective" with 5 view ports and several tabs. We will describe briefly all view ports.
- In the top left "Debug" view port we see the process that is being run by the debugger. As mysqld uses threads, we also see each thread of mysqld.
- In the top right view port we have several tabs. The first tab "Variables" contains variables in the current scope of the debugger. The "Breakpoints" tab is for managing breakpoints. Breakpoints have to be set before starting the debugger by simply double clicking left to the line number in the editor. In the screenshot we see that we have a breakpoint at Database.cpp:608. You can temporarily disable breakpoints by clicking on the check box in the "Breakpoint" tab. The "Register" tab is for examining the CPU registers. The "Modules" tab gives us a list of all loaded libraries.
- The middle left view is the editor view. While stepping throug the code it shows the line that will be executed next.
- The middle right "Outline" view shows all included header files. Double clicking an entry opens the file in the editor.
- The bottom view port shows us the usual status tabs, which we also see in the "C/C++ Perspective".
[edit] Using the Eclipse debugger
We step through the code with the usual options "Step Into", "Step Over", and "Step Return". These options are also bound to the F5, F6, and F7 keys.
The line, which will be executed next is higlighted. Pointing the mouse over a variable shows it's value. If it is a combined variable like Class->member, then pointing on "member" shows the member's datatype and marking "Class->member" and pointing to it shows the value.
You can also Navigate through the code by CTRL-click[1] on a function, which leads you to the function in most cases. You can also right-click on a symbol to get to it's declaration or definition
[1] On Mac OS X it's Apple-click.
[edit] Notes
- Tried on Linux 32-bit/64-bit and Mac/Intel.
- For better results in symbol lookup while debugging run a full build from inside Eclipse/CDT.
- MySQL's datadir has to be writable by the user running Eclipse.
[edit] Things I haven't figured out yet
- How to ignore SCCS/ directories of Bitkeeper in "Project View" and for code lookup?
- How to generate Makefile without running full BUILD/compile-xyz script. Use BUILD/compile-xyz -c (notice the -c option). Thanks to Timour who figured this out.
- Starting debug triggers a "make all" every time, which costs too much time. How to avoid "make all" if no files where changed?







