Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
hello-world
tools
Commits
12b118fa
Commit
12b118fa
authored
4 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Add initial gdb content
parent
eeb84fbb
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
gdb/.gitignore
+2
-0
2 additions, 0 deletions
gdb/.gitignore
gdb/Makefile
+12
-0
12 additions, 0 deletions
gdb/Makefile
gdb/README.md
+26
-0
26 additions, 0 deletions
gdb/README.md
gdb/main.cpp
+29
-0
29 additions, 0 deletions
gdb/main.cpp
with
69 additions
and
0 deletions
gdb/.gitignore
0 → 100644
+
2
−
0
View file @
12b118fa
main
main.dSYM
This diff is collapsed.
Click to expand it.
gdb/Makefile
0 → 100644
+
12
−
0
View file @
12b118fa
# Change your compiler here if you're not using gcc.
CXX
=
g++
# The flag -g adds debugging symbols to the executable. These are necessary for debugging with gdb.
CFLAGS
=
-Wall
-g
main
:
main.cpp
$(
CXX
)
$(
CFLAGS
)
-o
$@
$<
.PHONY
:
clean
clean
:
rm
main
This diff is collapsed.
Click to expand it.
gdb/README.md
0 → 100644
+
26
−
0
View file @
12b118fa
# GDB
[
GDB
](
https://www.gnu.org/software/gdb/
)
is a program that looks inside other programs. It's a
really handy tool for tracking down hard to find bugs.
## Setup
First, GDB is only useful if you have a way to compile programs (usually C or C++, but GDB does
support a variety of other languages as well). So to use it on your computer, you'll probably want
to get set up with
[
gcc and make
](
https://gitlab.cba.mit.edu/pub/hello-world/c_cpp_and_make
)
. For
debugging microcontrollers, you'll need a compiler that supports your particular chip (
`gcc-avr`
,
`arm-none-eabi`
, etc.).
To debug your microcontroller, you'll need some on-chip debugging software.
[
OpenOCD
](
https://gitlab.cba.mit.edu/pub/hello-world/tools/-/tree/master/openocd
)
is the option I'm
familiar with.
To install GDB itself, on Linux or Mac you can probably use your system's package manager (
`apt`
or
`yum`
on linux,
[
`homebrew`
](
https://brew.sh/
)
on Mac). If you want complete hacker cred, you could
build it from
[
source
](
https://www.gnu.org/software/gdb/current/
)
.
## Debugging on Your Computer
## Debugging on Your Microcontroller
I'll refrain from
This diff is collapsed.
Click to expand it.
gdb/main.cpp
0 → 100644
+
29
−
0
View file @
12b118fa
#include
<iostream>
// This is a simple function that checks if numbers are prime. Or does it? There may be a bug...
bool
is_prime
(
int
x
)
{
for
(
int
i
=
2
;
i
<
x
/
2
;
++
i
)
{
if
(
x
%
i
==
0
)
{
return
false
;
}
}
return
true
;
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
// If the user didn't give us a number, exit.
if
(
argc
<
2
)
{
printf
(
"Please type a number.
\n
"
);
return
0
;
}
int
x
=
atoi
(
argv
[
1
]);
bool
const
prime
=
is_prime
(
x
);
if
(
prime
)
{
std
::
cout
<<
x
<<
" is prime
\n
"
;
}
else
{
std
::
cout
<<
x
<<
" is not prime
\n
"
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment