[Debugging] Netbeans IDE on Mac OSX [17 June 2015]

I know Elco wrote a great tutorial but i decided to create a Mac version that i personally tested.

This makes it easy for me to assist the community for something that i myself wrote and use :smile:

Pre-requisite

DFU-util

    $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    
    Once homebrew is installed, we will install DFU-util
    
    $ brew install dfu-util

st-util [to write a tutorial soon]

$ git clone https://github.com/texane/stlink.git st-util
$ cd st-util
$ ./autogen.sh
$ ./configure
$ make

GNU Tools for ARM Embedded Processors

Download from : https://launchpad.net/gcc-arm-embedded and place it in a PATH accessible

Place the binary in /usr/bin or somewhere in PATH for the command-line```
.
.
.
.
.

Download Netbeans IDE

https://netbeans.org/downloads/

Use the C/C++ version
.
.
.
.
.
Install the GDBserver plugin

  • Press on Available plugins tab
  • search for gdbserver
  • hit install on the bottom left

.
.
.
.
.
Add our toolchain

  • Open the tools page
  • Add our tool and specify the path to file it, name it ARM Embedded
  • Modify the debugger command

.
.
.
.
.
Create a new project

  • C/C++ project with Existing Sources
  • Next
  • Choose the toolchain we added [ARM embedded] and browse to root directory of the firmware

.
.
.
.
.
Close Netbeans and launch from terminal

$ open -a "/Applications/Netbeans/Netbeans 8.0.2.app"

Due to the requirement of /usr path for the toolchain, we need to launch the App via terminal or the path will not be found
.
.
.
.
.
Add USE_SWD_JTAG flag to compiler

  • Right-click on the main folder and click on properties
  • Add in the line USE_SWD_JTAG=y at the end for Build

.
.
.
.
.
Try compiling!

  • Hit on the Clean and build project button
  • You should see a green message :smiley:
  • Copy the build result path and we will paste it in the Build --> Make --> Build Result

.
.
.
.
.
Flash code via STlinkV2 and turn on GDB server

  • create a gdb-run.sh and gdbcommand.txt file
  • Be sure to change the path for your app in gdb-run.sh
  • Run the command ./gdb-run.sh in the gdb folder
  • This will flash code and also turn on the GDB server!

Create a gdb-run.sh file with:

#!/bin/sh

set -m
st-util -p 9025 2>&1 &

sleep 5

arm-none-eabi-gdb ../build/target/main/platform-0/applications/UPDATETHISPATH/xxx.elf -x /PATHWHEREFILEISPLACE/gdbcommand.txt

st-util -p 9025

Create a gdbcommand.txt file with:

# connect remote gdbserver on port 9025 (started with st-util -p 9025)
target remote localhost:9025

# reset core and hold in reset
monitor reset halt

# program core with supplied .elf file
load

# remove all breakpoints
delete

# disconnect from remote. This pauses execution. Detach is not supported.
disconnect

quit

.
.
.
.
.
.
Attaching the debugger

-Once code is flashed, a only a simple step is required to attach the debugger!

  • Be sure the target is remote localhost:9025

2 Likes

:+1: I prefer to use port 4242 (the default for st-util) - less to type.

Also note that once USE_SWD_JTAG=y is specified on the build line, link time optimization is disabled since it prevents step debugging, so the resulting executable will be larger.

Also sometimes the gdb processes end up hanging around, end up consuming a whole core to themselves. I know this has happened when the macbook’s fan starts making a noise. Running ps -x | grep gdb lists the gdb processes, and kill -9 <pid> will get rid of them. (I’m sure we could write a nice script to do this automatically for us.)

1 Like

killall arm-none-eabi-gdb pty does the job to kill all the gdb related processes