Embedded Linux Design and Programming

Download Report

Transcript Embedded Linux Design and Programming

Introduction to
Embedded Systems
Dr. Jerry Shiao, Silicon Valley University
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
1
Section 9 Linux Debugging Tools

Trace Code Debugging
 printf
Inserted at strategic points in the executing code to
show the value of local or global variables.
 Real-time flow of application.
 Compile time macros to remove printfs in
production code.







#ifdef UNIT_TESTING
#define TRACE(flag, format) if(global_debug & flag) printf format
#else
#define TRACE(flag, format)
#endif
Many printfs or macros intermixed in code, can
document code or confuse code flow.
Add debug printfs means rebuild application.
 Slow execution time, affect timing.

Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
2
Section 9 Linux Debugging Tools
 System Tracing



Monitor User Application and Kernel.
Interprocess synchronization problems or time-sensitive issues.
strace: Tracing single process

ptrace() system call intercepts all system calls.



Monitoring system or library calls affects performance of process.
Option “-c”: Count all calls and signals and create a summary
report.
Option “-T”: Print time spent in each system call.
tux@mercury:~> strace -c find /etc -name xorg.conf
/etc/X11/xorg.conf
% time seconds usecs/call calls
errors syscall
-------------------------- --------- --------- ---------------32.38
0.000181 81
1
execve
22.00
0.000123 0
576
getdents64
19.50
0.000109 0
917
31
open
19.14
0.000107 0
888
close
4.11
0.000023 2
10
mprotect
0.00
0.000000 0
1
write [...]
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
3
Section 9 Linux Debugging Tools

Performance Analysis
 Maximize performance on Operating System.

Process Profiling
Compiler Option “ –gp”: Profiling data written to gmon.out upon exit.
 Makefile:
 $(CC) $(LDFLAGS) -pg -o $@ $(OBJS)
 Execute object file (i.e. $(OBJS))
 gmon.out: Cross-platform readable.
 gprof Utility runs on host Operating System.
gprof < options > < executable file > gmon.out
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self
self
total
time seconds seconds calls
ms/call
ms/call
name
33.34
0.02 0.02
7208
0.00
0.00
open
16.67
0.03 0.01
244
0.04
0.12
offtime
16.67
0.04 0.01
8
1.25
1.25
memccpy
16.67
0.05 0.01
7
1.43
1.43
write
0.00
0.06
0.00
47
0.00
0.00
strlen
0.00
0.06
0.00
45
0.00
0.00
strchr
0.00
0.06
0.00
1
0.00
50.00
main
0.00
0.06
0.00
1
0.00
0.00
memcpy
0.00
0.06
0.00
1
0.00
10.11
print
0.00
0.06
0.00
1
0.00
0.00
profil
0.00
0.06
0.00
1
0.00
50.00
report

Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
4
Section 9 Linux Debugging Tools

GDB – GNU DeBugger

Symbolic debugger, Richard Stallman, 1986.
 GDB package needs:



gdb debugger: Runs on the host.
gdbserver: Runs on the target. Executes the commands
received from the gdb debugger.
Debugging capabilities:




Initialize environment before running application.
Stop program execution (breakpoint).
Examine memory when program has stopped.
Change memory to alter running environment.

GNU General Public License.
 http://www.gnu.org/manual
 ftp://ftp.gnu.org/gnu/gdb
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
5
Section 9 Linux Debugging Tools

GDB – GNU DeBugger
 Enhanced


Associates address of symbol to the source code.
Assocates address of machine code to line of source code.
 gcc

compiler –g option (Symbol Table).
gcc –g –o filename filename.c
 gcc

symbol table. Debugging information for:
compiler –o option (Optimization).
gcc –g –o0 … or gcc –g –o …
 Debugging
information does not get loaded into
memory unless gdb loads the executable.


gdb –q filename
NOTE: Performance affected ONLY running within gdb.
 .gdbinit

Spring 2014
file executed by GDB ($HOME, current dir).
Contains any GDB commands.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
6
Section 9 Linux Debugging Tools


GDB – GNU DeBugger
Host
 gdb

–q filename
filename is executable object with enhanced symbol table.
 target
remote 192.168.1.100:9004
 target remote /dev/ttyUSB0

Target
 gdbserver

filename is executable object stripped of enhanced symbol
table.
 gdbserver

Spring 2014
localhost:9004 filename
/dev/tty filename
filename is executable object stripped of enhanced symbol
table.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
7
Section 9 Linux Debugging Tools
 GDB
– GNU DeBugger
1) Image test4 with enhanced symbol table.
2) minicom
gdb –q test4
target remote 192.168.1.101:9004
or
target remote /dev/ttyUSB0
1) Image test4 stripped of enhanced symbol table.
2) gdbserver localhost:9004 test4
or
gdbserver /dev/tty test4
Target
System
Serial Port
Host
System
192.168.1.100
192.168.1.101
Spring 2014
Ethernet
Port
Switch
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
8
Section 9 Linux Debugging Tools

GDB – Software Based Debuggers
 Standard
interface to target (serial line or
Ethernet).
 Active program code on the target (i.e.
gdbserver) waits for debugging requests and
executes the action.
 Debug only one process, kernel and other
processes in target continues.

Inter-process debugging difficult.
 Debugger
executes as part of the target
program, all software restrictions apply.

Spring 2014
Only view address space of the current running
process.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
9
Section 9 Linux Debugging Tools

GDB – Hardware Based Debuggers
 Uses
special hardware to access target,
processor and memory (i.e. JTAG interface).
 No active target software (i.e. no gdbserver
on target).

Allows debugging of system startup.
 Hardware
breakpoint. Whole target system
(i.e. processor) halts.

Debug interrupts or inter-process communications.
 Debugger
access memory physically without
restrictions.

Spring 2014
Access any process data.
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
10
Section 9 Linux Debugging Tools

GDB – JTAG
 Direct
control over hardware for debugging.
 Rely on special on-chip debug JTAG
functionality embedded in the CPU.
Sometimes, specially modified GDB debugger.
 Require special hardware and software.
 CPU pins used for communication between onchip debug system and 3rd party tools.

Read/write memory.
 Read/write CPU register.
 Single step and realtime execution.
 Hardware breakpoints.


Spring 2014
Less expensive and complicated than In-Circuit
Emulators (ICE).
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
11
Section 9 Linux Debugging Tools
1) gdb
Target
System
minicom
gdb
Serial Port
Host
System
OpenOCD
JTAG Probe
USB Port
JTAG Port
gdbserver.Emulation
1) OpenOCD
2) JTAG Probe
JTAG Cable
1) Connecting JTAG debugger to the JTAG pins
of the CPU. Control CPU behavior.
2) Require special JTAG hardware and software.
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
12
Section 9 Linux Debugging Tools
 GDB
– GNU JTAG DeBugger
1) Connecting JTAG debugger to the JTAG pins
of the CPU. Control CPU behavior.
2) Require special JTAG hardware and software.
1) gdbserver Emulation
1) gdb
Serial Port
Target
System
Host
System
JTAG Probe
192.168.1.100
192.168.1.101 JTAG Port
JTAG Cable
Ethernet
Port
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
13
Section 9 Linux Debugging Tools

In-Circuit Debugger (ICD)
 Direct
control over hardware for debugging.
 Rely on special on-chip debug JTAG
functionality embedded in the CPU.
ICD software installed on host.
 Configure ICD environment on the host and target
configuration.
 Require special hardware and software.
 CPU pins used for communication between onchip debug system.

Read/write memory.
 Read/write CPU register.
 Single step and realtime execution.
 Hardware breakpoints.

Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
14
Section 9 Linux Debugging Tools
 In-Circuit
Debugger
Set-up Debug Environment
Select the target CPU.
1) ICD Software
Establish the communcation between
the debugger and the target CPU.
Host PC
1) Connecting JTAG
debugger to the JTAG
pins of the CPU.
Control CPU behavior.
2) Require special JTAG
hardware and software.
USB Cable
Load application for debugging.
JTAG Probe
Target
JTAG Cable
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
15
Section 9 Linux Debugging Tools

In-Circuit Debugger (ICD)
Trace32 ICD:
Host CPU configuring
target CPU.
Spring 2014
SILICON VALLEY UNIVERSITY
CONFIDENTIAL
16