Hello and welcome.
In this lecture I'm going to show you how you can set up the gdb debugger inside code light on Ubuntu
Linux.
The first thing you're going to need to do is you're going to need to bring up a terminal.
Remember, you can go to a terminal just by selecting the dot, dot dot and typing in terminal.
I already have a terminal up so what I want to do is I just want to type in which gdb and that's going
to show me the path of the gdb debugger.
That may be important later.
It may not be, but you should know where gdb is installed which is usr bin gdb.
Now you want to bring up code light.
Again, you can bring up code light by going to the show applications searching for code light.
I already have code light up so here it is.
I'm going to go ahead and I'm going to create a new project.
So I just have an older workspace here.
I'm going to right click on the workspace.
I'm going to say new project.
I'm going to name this project, debugger test, debugger test, and I'm going to select the category.
You can select the template, but the template should have the GDB settings in it.
So I'm just going to select the category as console, the type as simple executable GCC compiler, GCC,
whatever version.
And then what's really important is the debugger GDB debugger and then build system by default.
I'm going to go ahead and hit.
Okay.
Now later, if you want to add a new template to make sure you have the GDB debugger set, you can also
do that.
So once I hit okay, you'll notice that my project was created debugger test and I now have main dot
c I double click main.c.
I'll see my templated source code for Hello world.
Now to see if the debugger configuration already works by just selecting that.
And when I created the project I can go on the margin here where the line numbers are and I can select
on line five, I can just right click on it and that will show me a red circle.
This red circle indicates that it's a breakpoint.
We're going to talk about breakpoints in a lot more detail.
But what this is saying is we're going to stop execution of the program on line five, and that will
allow us to look at different information and so forth.
But right now, we're just setting a breakpoint.
This is going to test to see if our debugger configuration is set up correctly.
After we set the breakpoint, we can go up to the debugger and we can say start, continue debugger,
we can say build and debug and this will build and start up the debugger.
And so you'll see that this terminal window came up and what you want to actually do is you want to
move this and you want to make sure that debugger was hit.
So if you look on line five, you'll see the red circle, but you'll also see a green arrow, and that's
indicates that the program has stopped.
And you also don't see any printf statements.
So, you know, the program has stopped right there.
So at this point, you know that your configuration is working, that GDB is all set up correctly for
code light.
Now if you want to stop the debugger, another thing you should notice actually before you stop it is
that a window does come up debugger window where you can now actually start doing things.
But again we're going to talk about this in subsequent videos in much more detail, how to use the debugger.
So now we can just stop the debugger.
We can hit the red rectangle to stop the program and we're all set.
Couple things to notice, right?
If you select a debugger test project, you right click and you say settings and you go to the debugger
tab here on the left, you'll notice that the debugger path is not set.
If you as long as you create the project and you select GDB, you should be good to go.
But if you have any issues, you may have to set this path to what we had earlier right usr bin gdb
when you type in which gdb at the terminal, you can just do that by going to dot, dot dot and setting
up that path.
But it doesn't look like it's necessary only if you have issues.
There's also the settings up here on the main menu where you can go to GDB settings and again you can
set up the debugger path if you have any issues.
I thought this was a global setting that would set for all projects, but it doesn't seem to do that.
There are also settings in here that you can look at if you're interested in all the default settings
should be fine, but that is these are where the configuration happens for GDB.
If you look at your project, you see this dropdown where it says debug.
It's really important to have debug selected and not release, make sure debug is selected because that
will build debugging information and allow you to run and debug.
And then the last thing again if you select your settings.
And you go to your compiler, you want to make sure that your C compiler options are building for debugging.
So G dwarf two and dash zero that those are options for debug information.
Right.
We went through this earlier.
It builds the executable to have debugging information in it, optimize for debugging and g dwarf two.
So if you have all these settings set, you should be ready to go to debug your program.
Just remember that the paths and so forth.
If you have any issues, you may want to set that and make sure that wherever you do, set your breakpoint,
that it's in the right file for the right project that you actually run in your active project.
Okay, happy debugging.
If you have any questions, please ask them in the Q&A forum.
Thank you.