- Install Gdb Server
- Install Gdb Server Android
- Install Gdb Sierra Software
- Install Gdb Sierra Download
- Install Gdb Mac High Sierra
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes - or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act.
- This videos explains the step by step process to insall gdb debugger and gcc in windows 10.First of all you need to go to download page of minGW by clicking.
- Once you have Homebrew, you can install gdb. If you're using High Sierra (macOS 10.13) or later, be aware that gdb 8.1 and 8.2 are not compatible. You can either use gdb 8.0.1 or one of the latest versions, starting from 8.3. In this tutorial, I'm going to use gdb 8.3.
- Unfortunately, GDB doesn't work out-of-the-box on MacOS Sierra (tested on 10.12.2) as it’s not code-signed. This is unfortunate, as GDB is the de facto standard for debugging C code. After researching the issue for a while, I managed to find a solution and successfully run GDB.
This topic provides details on using the open-source GDB
tool on a dev machine to debug sandboxed apps. This type of remote debugging is useful where resources are limited like in embedded apps.
The sample code uses an app named hw
with one executable hw_exe
and processes created in the same executable (hw_proc1
, hw_proc2
, etc.).
High-level steps to use GDB with a sandboxed app:
To debug a running app which is part of the default system:
- On your dev machine, run.
To debug app startup, or app which is not part of default system: When compiling:
- Building with Debug Symbols Make sure to build debug symbols
On the target device:
- Make sure the devMode app
is
installed and running - Run the sandboxed app without the process you want to debug.
- Start
gdbserver
in the sanboxed app. - Start the process in the sandboxed app with
gdbserver
. - Remove
gdb
from the sandboxed app after you're finished debugging.
On your dev machine:
- Launch
gdb
from the apps make directory. - Remote connect to the target and run
gdb
commands.
See basicTargetConfigIP if you need to setup your host/target communications.
The following simple app sample code is used in examples.
hw.adef
See Tutorials for more info.
.cdef
hw/Component.cdef
hello.c
hw/hello.c
See Tutorials for more info.
When building your app, build as normal, but add
to the mkapp command-line to generate debug symbols in <debug-path>
. You can use the same directory for all your apps -- each program or library will use a unique name.
When building the Legato framework from source, debug symbols for the legato framework are always generated and placed in build/
<target>/debug.
Running the App without a Process
To use GDB, start the sandboxed app excluding the process being debugged:
On the target, run the app excluding the process being debugged, hw_proc3:
Start GDB on an App
On your dev machine, set up port forwarding from local host to the target. This bypasses the firewall on the target and allows GDB server to connect.
- Warning
- Do not end this session to the Target or the port forwarding will end. GDB won't be able to connect to the Target.
On the target, start gdbserver
in the sandboxed /bin
directory by running:
For Example:
Start the Process with GDB enabled
On the target, start gdbserver
by starting the app with the arguments specified after --
(two dashes):
For Example:
If started successfully, the following will be returned:
To start GDB on your Dev Machine:
- Launch
gdb
on the Dev Machine. - Remote connect to the target and run regular
gdb
commands.
Launch gdb from Dev Machine
You need to run the commands from the directory where the hw
app was made. The path _build_hw/wp85/app/hw/staging/read-only/bin/hw_exe
is relative to the app directory; this build directory is generated when an app is made and the gdb commands must be run here.
In this example, we're running the gdb
tool (arm-poky-linux-gnueabi-gdb
) located in our target's toolchain path (/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi
for wp85). Use the findtoolchain
command on your dev machine to determine the toolchain path.
Launch GDB from the toolchain using the following command (substitute your program and path for hw):
Remote Connect
After GDB is launched, use the target
remote
command to connect to the target:
- Note
- If you get an error about connecting make sure you have a ssh -L (port forwarding) session open between the dev machine and target.
The target will display:
Now tell gdb to fetch the libraries to debug across the network, but use local debug symbols:
You should see GDB reading symbols for Legato components.
You can now run any of the standard gdb
debugging commands on hw_exe
.
Once you've finished debugging, remove gdbserver
from the sandbox /bin
directory on the target:
Refer to the many available open source resources if you need help using gdb
.
Copyright (C) Sierra Wireless Inc.
Using gdb debugger on macOS is no longer straightforward since Xcode stopped using it and replaced it with lldb. Starting from Mavericks (macOS 10.9), there are several steps to follow to make it work.
In this guide:
- Install gdb
- Install gdb 8.3 (recommended)
- Install gdb 8.0.1
- Generate a certificate
- Troubleshooting the certificate generation
- Sign the certificate for gdb
- Create a gdb command file
- Set Eclipse for using gdb
- Troubleshooting the Eclipse configuration
Install gdb
The easiest way to install gdb is by using Homebrew: 'the missing package manager for macOS'. If you don't have it installed, open your Terminal prompt and write this command:
Once you have Homebrew, you can install gdb. If you're using High Sierra (macOS 10.13) or later, be aware that gdb 8.1 and 8.2 are not compatible. You can either use gdb 8.0.1 or one of the latest versions, starting from 8.3. In this tutorial, I'm going to use gdb 8.3.
Install gdb 8.3 (recommended)
To install the latest version of gdb, run this command:
Verify that the operation was successfull by running:
Take note of the version: you'll need it later. In my case, it is 8.3.
Install gdb 8.0.1
Should you decide to do so, you can install gdb version 8.0.1 in this way.
The pinning operation makes sure that brew doesn't upgrade gdb to newer versions.
In case you have already a newer version of gdb, you first need to unlink the other version before installing the old one.
To check out your gdb version, run:
Take note of the version: you'll need it later. In my case, it is 8.3.
Generate a certificate
Installing gdb is not enough. If you try debugging a file, you'll get an error since the Darwin kernel doesn't allow gdb to control another process without having special rights. For security reasons, this is the default behaviour.
To give gdb those permissions, you need to generate a self-signed certificate.
- Launch Keychain Access application: Applications > Utilities > Keychain Access.
- From the Keychains list on the left, right-click on the System item and select Unlock Keychain 'System'.
- From the toolbar, go to Keychain Access > Certificate Assistant > Create a Certificate.
- Choose a name (e.g. gdb-cert).
- Set Identity Type to Self Signed Root.
- Set Certificate Type to Code Signing.
- Check the Let me override defaults checkbox.
- At this point, you can go on with the installation process until you get the Specify a Location For The Certificate dialogue box. Here you need to set Keychain to System. Finally, you can click on the Create button.
- After these steps, you can see the new certificate under System keychains. From the contextual menu of the newly created certificate (right-click on it) select the Get info option. In the dialogue box, expand the Trust item and set Code signing to Always Trust.
- Then, from the Keychains list on the left, right-click on the System item and select Lock Keychain 'System'.
- Finally, reboot your system.
Troubleshooting the certificate generation
At the end of the procedure to generate a certificate, you might get the following error message:
Unknown error: -2,147,414,007
This kind of error has bothered a lot of macOS users over the past years, I don't know why Apple has not replaced it with a more meaningful message yet. It seems that the error is related to the creation of the certificate in the System keychain. Here there are a few things you can try to solve the problem.
- Be sure that your System keychain is unlocked. If it is and you're still getting the same error, than you can use a workaround. Create the certificate in the login keychain and then drag and drop the newly created certificate, the public key and the private key from the login keychain to the System keychain.
- If the drag-and-drop option doesn't work for you, then find your certificate in the login keychain, select it, then choose File -> Export items from the toolbarand save the certificate somewhere on your disk. Then, go in the System folder, choose File -> Import items from the toolbar and select your certificate. Finally, delete the certificate originally created in the login folder (it's not done automatically).
Notice that once you have created the certificate using one of the previous workarounds, you still need to go through steps 9 to 11 of the prior section.
I hope that one of the solutions worked well for you. Please leave a comment if you are encountering any other error during the procedure.
Sign the certificate for gdb
It's time to sign the certificate. If you're using maOS Mojave (10.14) or later, create a gdb-entitlement.xml file. This will tell the operating system which operations the gdb process has to be trusted. In this case, just for debugging.
Then, open your Terminal prompt, go to the directory where you saved the xml file and run:
If you're using macOS High Sierra (10.13) or older, you don't need an entitlement configuration. Instead, you need to run this command:
where gdb-cert is the name of your certificate and gdbPath is the full path to your gdb binary file. If you have installed gdb as explained before (using Homebrew), the path should be: /usr/local/Cellar/gdb/version/bin/gdb (replace version with the actual version of your gdb installation, e.g. /usr/local/Cellar/gdb/8.3/bin/gdb).
Create a gdb command file
If you are on macOS Sierra (10.12) or later, you need to do this extra step.
Install Gdb Server
In the home directory, create a new file called .gdbinit and write the following command in it:
Alternatively, from the Terminal, you can do that by running this:
Now you can use gdb for debugging files on your Mac. If you use Eclipse, follow the next step.
Set Eclipse for using gdb
Install Gdb Server Android
If you want to configure gdb for a specific project in Eclipse, you need to set some options:
- Go to Run > Debug Configurations...
- Select a launch configuration from the list on the left (e.g. C/C++ Application)
- Open the Debugger tab from the menu on the right
- Set GDB debugger to the full path of your gdb binary file (the same used for signing the certificate)
- Set GDB command file to the full path of your .gdbinit file: ~/.gdbinit (or the extended form /Users/yourname/.gdbinit, where yourname is your username)
- Click on the Apply button.
Install Gdb Sierra Software
In case you want to define a default configuration for gdb to be used in any Eclipse project, these are the steps to follow:
- Go to Eclipse > Preferences
- From the left menu select C/C++ > Debug > GDB
- Set GDB debugger to the full path of your gdb binary file (the same used for signing the certificate)
- Set GDB command file to the full path of your .gdbinit file: ~/.gdbinit (or the extended form /Users/yourname/.gdbinit, where yourname is your username)
- Click on the Apply button.
Now, you can debug files from inside Eclipse using gdb.
Troubleshooting the Eclipse configuration
Install Gdb Sierra Download
If there is no GDB option in Eclipse > Preferences > C/C++ > Debug, then you need first to debug any C/C++ project. So, open any project and start a debugging session either by clicking the Debug icon on the toolbar. The operation will fail since you haven't configured gdb yet, but in this way, you will be able to see the gdb option in the main Preferences window.
Conclusion
Install Gdb Mac High Sierra
In this tutorial, I've shown you how to install gdb and use it to debug a C/C++ application on macOS.
Special thanks to those people who helped me improve this article by commenting with suggestions and tips.
Resources
Last Update: 30 December 2019