Auto-launch arm-none-eabi-gdb after upload script

Rick Kimball
Mon May 11, 2015 2:46 pm
I put together a script you can use to upload via stlink and then automatically launch gdb. I only made it for linux but you should be able to get an idea of what you need to do to make it work on OS/X and Win32/64 by looking at the scripts. Let’s start with a picture:

Image

When you press the upload button 2 xterms are auto launched after the upload has finished. You can see my Arduino IDE running on the left of the image. It is the lowest window. Next up the window stack and to the right is an xterm that is running the st-util listening on port 4242. Finally, the window we really care about is the top window running the arm-none-eabi-gdb command line program.

In that gdb window you can see I setup a breakpoint on the loop() function:
(gdb) break loop()


mrburnette
Mon May 11, 2015 3:03 pm
Neat.
But, a far cry to the GUI I am accustomed to with the PSoC4200 M0+ debugger under Cypress.

But still a light-year ahead of having to sprinkle Serial.println() throughout the sketch.

Ray


Rick Kimball
Mon May 11, 2015 3:11 pm
I’ve tried PSOC and it is an amazing environment if you are running windows. It is dog slow under VirtualBox though. If it wasn’t for that I’d probably play with those chips more.

If you want a full gui ide experience you could replace the arm-none-eabi-gdb with something like the DDD, the Eclispe standalone thing .. or whatever is the hotest new gdb ui thing. I find the command line stuff is pretty useful once you get a handle on the commands. However, if you aren’t using those commands everyday those things vanish from your memory pretty quickly.


mrburnette
Mon May 11, 2015 3:17 pm
However, if you aren’t using those commands everyday those things vanish from your memory pretty quickly.

Which is why so many of my older friends have their initials on their belt buckles! Sadly, I’m thinking about it myself these days.


Rick Kimball
Mon May 11, 2015 3:56 pm
Yeah that is part of the reason I post on forums now. If I can ever find my way back to the forum I can read what I wrote. :)

-Code flow and breakpoints example-

Some of the common commands you will use to set breakpoints are ones that control when the debugger stops:
run - resets the stm32f103 and starts from the beginning
break - set a breakpoint on a function or a line in a function
continue - tell the debugger to run until a breakpoint is hit or the you press CTRL-C
next - step over a line of c code, if the line of code is a function call, it will run the function but not go into it
step - step into a line of c code, if that is a function it will then stop at each line in the function
finish - exits whatever function you are running and stops at the first line of code in the caller after the function call
where - show the line of code you are on and the call stack
info breakpoints - show all the current breakpoints
delete - deletes all the breakpoints
print - used to display variables and registers.


Rick Kimball
Mon May 11, 2015 6:12 pm
mrburnette wrote:Neat.
But, a far cry to the GUI I am accustomed to with the PSoC4200 M0+ debugger under Cypress.

mrburnette
Mon May 11, 2015 10:00 pm
Rick Kimball wrote:mrburnette wrote:Neat.
But, a far cry to the GUI I am accustomed to with the PSoC4200 M0+ debugger under Cypress.

Rick Kimball
Mon May 11, 2015 10:41 pm
I’ll see if I can work out how to make that automatic. I had to do a lot of hand setup to make the Eclipse CDT Standalone thing work.

Rick Kimball
Tue May 12, 2015 2:07 pm
Well I got it to auto launch and automatically do all the right things. It is still limited to linux though. Although I would think OS/X would work with minimal changes. I noticed an interesting problem. When you use st-util as the gdb server, the eclipse disassembly feature barely works. It doesn’t show the mixed asm/source code feature even if the .elf file has the gdb symbols. If you turn on instruction step mode, it doesn’t seem to track the current program counter and is basically useless.

If you switch to using openocd as the gdb server. It is much faster and shows mixed asm/source as you would expect and you can instruction step very quickly and accurately.

I need to clean up the script some to get rid of my hardcoded hacks. Basically I added 2 scripts, (launch_gdb and gdb) and modified the stlink_uploader. I dropped a shell script gdb into the tools/linux/stlink mainly so i can manipulate the arguments as I didn’t find a way to override the name of launch configuration parameters for the gdb executable.

no pictures .. same looking as before :)


Rick Kimball
Tue May 12, 2015 9:24 pm
More progress, I added a menu option to upload and debug:

Image

Here you can see me debugging the ASCIITable example. I have putty running as a serial terminal on /dev/ttyUSB0. You can see that it has output some data but I’m stepping through the write functions and you can see the next character it is going to output is ‘e’ (the value of *str)

Image

If you are interested in this stuff join IRC to get more info.

-rick


RogerClark
Wed May 13, 2015 11:12 am
Hi Rick,

FYI.

I posted to the Arduino Developers mailing list (i.e the IDE developers), to find out how they intended to support he in-circuit debugging on the Arduino Zero

Well, I havent got a response from the dev’s yet (I may never), but someone suggested I use DDD

I’d tried to compile DDD on windows but it won’t, as it looks like it was never test compiled under MingW on windows

So I thought I’d try compiling on my Linux 32 machine.

Well, its just as bad. :-( but fails differently

Firstly its a sod to get all the necessary development libs installed, there doesn’t seem to be a list of the required libs, or a script to apt-get install them for you. (as far as I can tell)

So I had to run configure over and over again and each time it failed with a cryptic message, I’d have to track down the necessary lib and install it.

When I finally got past the configure script stage, and ran Make, it fails to compile

So…

It looks like DDD is another non starter

Hence Exclipse is looking the best bet at the moment, but…

But I can’t find any docs on whether there is a Windows version of the Eclipse Standalone debugger.

The percentage of Linux users is probably 20% on this forum , possibly lower.

So unless we can get a cross platform solution, I’m not sure how much take up there would be

Albeit if we an get a Windows version working, I think it would be a game changer ;-)


ahull
Wed May 13, 2015 11:01 pm
I don’t want to sound smug, but ddd installs first time and launches without problems on Linux (Ubuntu 14.04.2 LTS )

I think the magic you are looking for is…
sudo apt-get install ddd libmotif-common libmrm4 libuil4 libxm4 ddd-doc pydb glibc-doc


RogerClark
Wed May 13, 2015 11:09 pm
@ahull

Thanks

I’ll give that a try

It does however mean that DDD is a Linux only solution, because we can’t do the same thing

Well, I know it won’t work under MinGW

I’ve posted to the Eclipse forum in the hope someone can help on how to install the debugger under Windows


RogerClark
Thu May 14, 2015 10:08 am
Edit.

I’ve instaleld using the apt-get you sent, and DDD now seems to run, but I’m not going ot have time until the weekend to see how to use it.

BTW. I posted to the Eclipse users forum to find out about the Standalone debugger on windows, but my post has to be moderated so I don’t know when if ever I’ll get a reply


victor_pv
Tue Jun 02, 2015 7:33 pm
To add some to this thread, based on the work from Roger and Rick, I wrote a batch for Windows that launches Texane and GDB after a DFU upload.
I’m sure the same could be done for an stlink upload, I just don’t use that upload method. I want to test it a bit more and then will post the batch and the modified platform file here.

martinayotte
Tue Jun 02, 2015 9:39 pm
Do you mean that after upload using dfu-util, you start texane/st-util for debugging with GDB ?
I will try to linuxify your script when it will become available, because I still didn’t received my STLink clone from China.

victor_pv
Wed Jun 03, 2015 8:23 pm
martinayotte wrote:Do you mean that after upload using dfu-util, you start texane/st-util for debugging with GDB ?
I will try to linuxify your script when it will become available, because I still didn’t received my STLink clone from China.

martinayotte
Tue Jun 09, 2015 10:43 pm
@victor, could you attached your batch file here ? (I’ve just received today my STLink from China :) )

martinayotte
Wed Jun 10, 2015 1:39 am
I’ve started playing with my STLink tonight !
I seems to work fine with STM32F4Stamp board (an F405) with txeane/st-util and gdb, that will be nice for my future debugging.
But trying the same on my Maple Mini Baite clone, st-util responded “stlink-common.c: unknown chip id! 0xe0042000” … :(
Is there something I missed ? Are those Baite clones really use genuine chip ? or is it a bug in texane ?

Rick Kimball
Wed Jun 10, 2015 1:43 am
It is because the maple mini disables the SWD pins.

https://github.com/rogerclarkmelbourne/ … rd.cpp#L48

You can hold the boot1 pin high, and press reset. That will let you at least get in. The better solution is to delete this code and never use the SWD pins except for debugging.

-rick


RogerClark
Wed Jun 10, 2015 1:46 am
Martin

There is a defined in boards.txt which enabled the SWD pins.

On the Maple mini builds, SWD will be off by default.

Do you have this set in the upload flags

-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1

Edit.

Rick we posted at virtually the same time .. (you just beat me ;0)


martinayotte
Wed Jun 10, 2015 2:02 am
Rick Kimball wrote:It is because the maple mini disables the SWD pins.
[…] The better solution is to delete this code and never use the SWD pins except for debugging.

victor_pv
Wed Jun 17, 2015 3:25 am
To launch Texane and GDB in Windows after DFU upload, I modified my platform.txt file to have a new Upload option that is copied from the DFU one, except this last line:
tools.maple_upload_gdb.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" "{runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-gdb" "{build.path}/{build.project_name}.elf"

martinayotte
Wed Jun 17, 2015 7:54 pm
Thanks, Victor !

I will check that when I get chance and I will linuxify the script … ;)

Ciao !


victor_pv
Thu Jun 18, 2015 2:37 pm
Have a look at what Rick did with launching GDB for BlackMagic probe, as I mostly based this off of what he posted.
I haven’t had much time to play with GDB lately, but I really wish it was rather a graphical application :(

martinayotte
Thu Jun 18, 2015 2:44 pm
Me too I wish to have some GDB GUI soon, because I’m a bit rusty with gdb cmdline. :?

martinayotte
Thu Jun 18, 2015 2:46 pm
BTW, folks, just to let you know, I’ve played with openocd with STLink, and I decided to try it also on my LPC1768.
After struggling to get the initial reset, I got it to work ! So, I can debug my LPC1768 too ! :)

michael_l
Mon Aug 31, 2015 8:44 pm
Rick: Could you share your scripts for auto upload & start debugging. Thanks. Also thanks for great tutorial.

On the other thread http://www.stm32duino.com/viewtopic.php?f=29&t=522 I am trying to get Eclipse debugging working using win32 and openocd with ST-link on nucleo board. It works perfectly and is easy to setup with GNU ARM plugins. IDE does all the magic with GNU OpenOCd plugin to connect to target and provide scripts for gdb too. The only and very very annoying problem is that the IDE can’t find the source for .ino! Lol. It can find sources for everything else that I’ve tested. I’d be really grateful to hear comments if you have ideas what to try next. I just feel I’m so close I don’t want to give up yet. Seeing your screenshot with .ino source gave me some more motivation to continue. Ok it was in Linux but anyway … :-) Thanks.


Rick Kimball
Mon Aug 31, 2015 8:48 pm
Did you try adding the directory where the .ino lives to your gdb search path?

At the gdb prompt, you can add to the file search directory using the “directory” command. Here I add the sketch directory blink_std … where /mnt/vbox/shared/Arduino_STM32RK_Sketch is the setting of my arduino sketch preference:
(gdb) directory
Source directories searched: $cdir:$cwd
(gdb) directory /mnt/vbox/shared/Arduino_STM32RK_Sketch/blink_std
Source directories searched: /mnt/vbox/shared/Arduino_STM32RK_Sketch/blink_std:$cdir:$cwd
(gdb) list setup
17 // the setup function runs once when you press reset or power the board
18 void setup() {
19 // initialize digital pin 13 as an output.
20 pinMode(PC13, OUTPUT);
21 }
22
23 // the loop function runs over and over again forever
24 void loop() {


Rick Kimball
Mon Aug 31, 2015 9:06 pm
michael_l wrote:Rick: Could you share your scripts for auto upload & start debugging. Thanks. Also thanks for great tutorial.

mrburnette
Mon Aug 31, 2015 11:43 pm
Oh yeah, and I only care about linux.

Now, that’s a direct statement! :o

I really, really need to toughen up and get away from the M$ crap.

Ray
(MCSE, once upon a time…)


RogerClark
Mon Aug 31, 2015 11:57 pm
I really, really need to toughen up and get away from the M$ crap.

If only it was that easy.

I think its going to be several years (or perhaps never) that I’ll be able to get away from Windows for work stuff, as there is plenty of commercial SW that only runs on Windows :-(

However, unless Windows 10 changes substantially in the next year or two. I suspect that Windows 7 will be the last MS OS I’ll be running for my own use as well as business.
If I every have to use Windows 10, with its intrusive spyware built in, will be resigned to a separate machine just for work.


zmemw16
Tue Sep 01, 2015 12:16 am
with regard to time, it only took me 14yrs or so to get an officially sanctioned linux box on the company network.
i ‘retired’ 4 wks later:-)

the first cracks in the wall were
1 ) gnu ada compiler around ’94 saving i suspect a lot of ada per station costs
2 ) saving the u$ office & windows costs on a ‘something’ rig, also i got to write and play with linux device drivers

stephen


stevech
Tue Sep 08, 2015 3:39 am
Since Linux still, after all these years, has only 1.3% share of desktops, it remains great for web surfers that don’t need MS Office or specialized Windows-only apps. (I tried very hard to use an Office alternative but for non-trival documents as we use in real business work, it just doesn’t work).
And among my large repertoire of apps I use a lot, including embedded system tools, financial management apps, Linux and often too, OS X, are just not viable.

I don’t like Microsoft’s monopoly either, but some of us would prefer to pay $80 every 4 years to them.


zmemw16
Tue Sep 08, 2015 8:36 am
stevech wrote:I don’t like Microsoft’s monopoly either, but some of us would prefer to pay $80 every 4 years to them.

RogerClark
Tue Sep 08, 2015 11:07 am
stevech wrote:I don’t like Microsoft’s monopoly either, but some of us would prefer to pay $80 every 4 years to them.

RogerClark
Wed Oct 12, 2016 8:06 pm
SPAM post was deleted from this thread.

User will be blocked.


Rick Kimball
Wed Oct 12, 2016 8:08 pm
* smells fried SPAM

zmemw16
Wed Oct 12, 2016 8:10 pm
i wonder if his wife knows and what she thinks about it?

srp


arrowmax
Mon Feb 27, 2017 1:42 pm
@Rick Kimball
Could you please share your scripts again for auto upload & start debugging.
Your github repository is down and I couldn’t find it on your github page.

I want to port this linux project to Mac OS X


Rick Kimball
Mon Feb 27, 2017 4:34 pm
I removed the my personal github as it had become too out of date and all the things I wanted changed have been included in the main trunk.

The gdb modifications were just changes to the platform.txt and board.txt. However, those files were changing so frequently it became painful to keep up and not break things. As there wasn’t much interest in this, I kind of let it fall by the wayside and I can’t find the modifications I did.

In platform.txt I added a new tool and its command line did all the magic. For that tools command line, I started two xterms when you did an upload. One xterm ran the stlink utility ( acting as a gdb proxy ), the other xterm ran arm-none-eabi-gdb. The gdb command connected to remote target :4242, erased the flash, loaded the new version of the program and then set a temporary break point on setup and then issued a reset mon init, continue.

In board.txt I added a new menu item that used the new programming method

If you are using linux and BMP as your upload method, you can use this one line change to platform.txt
platform.txt change wrote:tools.bmp_upload.upload.pattern=xterm -e “{path}{cmd}” -q -cd “{build.path}” {upload.verbose} -ex “layout src” -ex “set target-async off” -ex “set confirm off” -ex “set mem inaccessible-by-default off” -ex “target extended-remote {serial.port}” -ex “monitor swdp_scan” -ex “attach 1” -ex “stop” -ex “file {build.project_name}.elf” -ex “load” -ex “tbreak setup” -ex “run”


Leave a Reply

Your email address will not be published. Required fields are marked *