EECS 192: Mechatronics Design Lab Discussion 8: Debugging & - - PowerPoint PPT Presentation

eecs 192 mechatronics design lab
SMART_READER_LITE
LIVE PREVIEW

EECS 192: Mechatronics Design Lab Discussion 8: Debugging & - - PowerPoint PPT Presentation

EECS 192: Mechatronics Design Lab Discussion 8: Debugging & Telemetry GSI: Justin Yim 13 & 14 Mar 2019 (Week 8) 1 Tips 2 GDB 3 Logfiles 4 Summary Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 1 / 16 Tips


slide-1
SLIDE 1

EECS 192: Mechatronics Design Lab

Discussion 8: Debugging & Telemetry GSI: Justin Yim 13 & 14 Mar 2019 (Week 8)

1 Tips 2 GDB 3 Logfiles 4 Summary

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 1 / 16

slide-2
SLIDE 2

Tips Tips

Quick Tips

◮ Don’t forget to order your boards’ components ◮ Make sure individual components are reliable and working well ◮ Software tips:

◮ Follow good coding style practices ◮ Break related source code out into separate files instead of writing one

monster file

◮ e.g. main.c, camera.c, motor control.c, etc. Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 2 / 16

slide-3
SLIDE 3

GDB

GNU Debugger

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 3 / 16

slide-4
SLIDE 4

GDB

Debugging

◮ General idea: locate bugs in your program

by stopping it at particular points and looking at values

◮ GDB (gdb) ”GNU Debugger” for C, C++,

and other languages:

◮ Install GDB ◮ Locate where in your code to debug ◮ Compile for debugging ◮ Examine program with GDB

◮ (Documentation link) ◮ (Link to more detailed slides)

What’s wrong with my code?

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 4 / 16

slide-5
SLIDE 5

GDB

Installing GDB

◮ GDB is not installed in our BBBL Debian distribution:

◮ sudo apt-get update ◮ sudo apt-get install gdb Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 5 / 16

slide-6
SLIDE 6

GDB

Line Numbers

◮ GDB often invovles looking at particular

lines of code

◮ You will want to have line numbers so you

can tell where GDB is working

◮ Cloud9 on Debian (192.168.7.2:3000) has

line numbers

◮ Vim set number ◮ Other configurations for other text editors

Line numbers

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 6 / 16

slide-7
SLIDE 7

GDB

Compiling for GDB

◮ When compiling with gcc, use the -g option

◮ gcc -g (source) -o (output)

◮ For rc library use

make debug

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 7 / 16

slide-8
SLIDE 8

GDB GDB Commands

Commands

◮ To run a program in GDB:

◮ gdb (program name)

OR

◮ gdb

(gdb) file (program name)

◮ (Link to list of some useful commands)

◮ help, file, run, break, watch, delete, continue, step, next, print Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 8 / 16

slide-9
SLIDE 9

GDB GDB Commands

Commands

See the list link for more information

◮ quit - exit gdb ◮ help (topic) - get more information about topics ◮ file (program file) - runs a program compiled for debugging

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 9 / 16

slide-10
SLIDE 10

GDB GDB Commands

Commands

See the list link for more information

◮ run - lets the program run as usual (until breakpoint or other event) ◮ breakpoints:

◮ break (line or function) - sets a breakpoint to stop the program

at a line or function call

◮ watch (variable) - stop each time a watched variable changes ◮ continue - continue running after stopping ◮ info breakpoints - list info about all breakpoints ◮ delete - clear all breakpoints Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 10 / 16

slide-11
SLIDE 11

GDB GDB Commands

Commands

See the list link for more information

◮ What do you do after you’ve hit a

breakpoint?

◮ step - execute the current line (stepping

into a called function)

◮ next - go to the next line (stepping over

a called function)

◮ print (expression) - display value of

an expression (like a variable name)

1 void foo () { 2 printf("world"); 3 } 4 5 int main () { 6 printf("hello"); 7 foo (); 8 printf("!\n"); 9 return 0; 10 } Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 11 / 16

slide-12
SLIDE 12

GDB GDB Commands

GDB Example

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 12 / 16

slide-13
SLIDE 13

Logfiles

Logfiles

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 13 / 16

slide-14
SLIDE 14

Logfiles

Logfiles

◮ Logfiles are useful to see what went on ◮ For debugging “what’s wrong with my ... whole car?” ◮ Two ways to write files while the car runs:

◮ Save data to a variable (like an array or struct).

Save the pre-saved data once the car stops running

◮ See SkeletonBeagle/LineCamera/LineCamera.c ◮ Run a low-priority low-rate loop to save some data ◮ See telem loop in

SkeletonBeagle/rc balance/rc balance2.c

Beautiful telemetry data

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 14 / 16

slide-15
SLIDE 15

Logfiles

But really, why do I want logfiles?

◮ Can help catch odd bugs ◮ e.g.: encoder reading thread accidentally set at very low priority

◮ encoder updates infrequently and sporadically ◮ telemetry will show the sporadic encoder updates

◮ We will eventually ask you to turn in plots of control responses (you

will need to log data somehow)

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 15 / 16

slide-16
SLIDE 16

Summary

Summary

◮ Build simple, robust components ◮ GDB to debug component software ◮ Logfiles to debug integrated systems

Ducky (UCB EECS) Mechatronics Design Lab 13 & 14 Mar 2019 (Week 8) 16 / 16