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

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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:

Code: Select all

(gdb) break loop()

Then I let the debugger run, you could also type 'continue' either should work

Code: Select all

(gdb) run

When the debugger hits the breakpoint, I used the print command (abbreviated p) to display the values of the led class variables. I also used the print command to show the PIN_MAP values for the 32nd item. Then I just quit and closed both windows.

If people are interested I can follow up here with more detailed use of the command line debugger.

Note: I assume arm-none-eabi-gdb is in your path. If it isn't you can modify the launch_gdb script to set the path , or use the full name.

-rick

Download modified tools and extract into tools/linux:


[EDIT: May 11, 2015 7:35 PMI just updated the script to be less hardcoded * I had my personal sketch path in there * It now picks it up from the preferences file, also modified stlink_upload to auto kill the st-util/arm-none-eabi-gdb commands]
Last edited by Rick Kimball on Wed May 13, 2015 4:00 am, edited 4 times in total.
-rick

User avatar
mrburnette
Posts: 1766
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

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

Postby 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

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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.
-rick

User avatar
mrburnette
Posts: 1766
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

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

Postby 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.

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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:

Code: Select all

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.


So here is a typical session showing you how to trace the execution of the code. Where you see (gdb), that is the the command line prompting me to type something. Whatever I typed after the prompt shows up in the text below:

Code: Select all

...Remote debugging using :4242
__start__ ()
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/variants/generic_stm32f103c/wirish/start.S:51
51           ldr r1,=__msp_init
(gdb) b setup
Breakpoint 1 at 0x8000142: file sketch_may01a.ino, line 6.
(gdb) b loop
Breakpoint 2 at 0x8000162: file sketch_may01a.ino, line 9.

In that first section I setup some breakpoints (b) on setup and loop. When the code runs it will stop at the first instruction of those functions. After we set the breakpoints we can view them.

Code: Select all

(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08000142 in setup() at sketch_may01a.ino:6
   breakpoint already hit 1 time
2       breakpoint     keep y   0x08000162 in loop() at sketch_may01a.ino:9
   breakpoint already hit 1 time

When gdb prompt you, that means the cpu is halted and waiting on you to do something. To start it executing from the current location you type: 'continue' or use the 'c' for abbreviation. It will then run until you either press CTRL-C or it hits a breakpoint.

Code: Select all

(gdb) continue
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, setup () at sketch_may01a.ino:6
6     led.begin();
(gdb)

We have hit the first breakpoint on setup .. and you can see the code it is going to run next. We can tell it to step into the led.begin function and that will execute one C statement and then come back (Note: one C statement may be a boat load of asm instructions)... and because the platform.txt cflags has the -0s ( optimized for small code ) it may actually behave strangely as the asm code may be re arranged and not match the c code.. hmm .. this is actually a long topic I should talk about later.

Code: Select all

(gdb) step
begin (this=0x20000d94 <led>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:19
19       if ( !_initialized ) {
(gdb)

Here you can see it is now on the first line of the begin() metho of the ActiveLowLED class. We can list out the c code using list

Code: Select all

(gdb) list
14     ActiveLowLED(const int pin=32) : _pin(pin), _initialized(0) {
15       // setup handled by initialization list
16     }
17   
18     void begin() {
19       if ( !_initialized ) {
20         pinMode(_pin, OUTPUT);   // make it an output
21         off();
22         _initialized=1;     
23       }
(gdb) finish
Run till exit from #0  begin (this=0x20000d94 <led>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:19
main () at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/cores/maple/main.cpp:41
41           loop();
(gdb) list
36   
37   int main(void) {
38       setup();
39   
40       while (1) {
41           loop();
42       }
43       return 0;
44   }
(gdb) next

Breakpoint 2, loop () at sketch_may01a.ino:9

Here you can see the commands I used and see how they might be useful in tracking the flow in your program:

Code: Select all

9   void loop() {
(gdb) next
38     void blink(int msecOn=100, int msecOff=400) {
(gdb) list
33   
34     void toggle() {
35       digitalWrite(_pin,(digitalRead(_pin) == HIGH ? LOW : HIGH));
36     }
37     in the list here is what I typed
38     void blink(int msecOn=100, int msecOff=400) {
39       on();
40       delay(msecOn);
41       off();
42       delay(msecOff);
(gdb) step
15         led.blink(500,500);
(gdb) step
blink (msecOff=500, msecOn=500, this=0x20000d94 <led>) at sketch_may01a.ino:15
15         led.blink(500,500);
(gdb) step
on (this=<optimized out>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:27
27       digitalWrite(_pin,LOW);
(gdb) l
22         _initialized=1;     
23       }
24     }
25    
26     void on() {
27       digitalWrite(_pin,LOW);
28     }
29    
30     void off() {
31       digitalWrite(_pin,HIGH);
(gdb) where
#0  on (this=<optimized out>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:27
#1  blink (msecOff=500, msecOn=500, this=0x20000d94 <led>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:39
#2  loop () at sketch_may01a.ino:15
#3  0x080021ec in main ()
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/cores/maple/main.cpp:41
(gdb) up
#1  blink (msecOff=500, msecOn=500, this=0x20000d94 <led>) at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:39
39       on();
(gdb) finish
Run till exit from #1  blink (msecOff=500, msecOn=500, this=0x20000d94 <led>)
    at /tmp/build8946637453487957752.tmp/ActiveLowLED.h:39
14       do {in the list here is what I typed
(gdb) list
9   void loop() {
10       static unsigned indx = 0;
11      
12       unsigned x;
13       x = 3;
14       do {
15         led.blink(500,500);
16       } while(--x);
17       delay(1000);
18      
(gdb)
19       x = 6;
20       do {
21         led.toggle();
22         delay(250);
23       } while(--x);
24       delay(1000);
25   }
(gdb)


Hopefully this can get you started. I'll add more about display and modifying variables in the next post.

[Edit: I've attached the arduino program I was using here:]
sketch_may01a.zip
(1.12 KiB) Downloaded 29 times
-rick

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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.


Maybe something like this is better to your liking:

Image
-rick

User avatar
mrburnette
Posts: 1766
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

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

Postby 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.


Maybe something like this is better to your liking: <img>



Yes! Me like.
That is what I have come to expect because the Cypress Development (free) is capable of that level of detail. I'm no stranger to command-line tools, but I spent a lifetime working with them, old 'n set in my ways, I now like the sleek 'n shinny stuff. :lol:

Ray

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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

User avatar
Rick Kimball
Posts: 722
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Postby 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
-rick


Return to “STLink”

Who is online

Users browsing this forum: No registered users and 1 guest