Professional Documents
Culture Documents
Click to Presentation
edit Master title
style
•Welcome, we will
Click to edit thebegin shortly!
outline text format
•Your phone will be muted throughout the
Second Outline Level
presentation, kindly keep it muted.
Third
•This session Outline
will be Level
recorded for future
reference. Fourth Outline Level
•Questions? Please use theOutline
Fifth Chat functionality
Level
on WebEx to submit questions. They will be
Sixth Outline
answered toward the end of the presentation.
Level
SeventhThankOutline
youLevelClick to edit
for attending!
Master subtitle
Click to edit Masterstyles
presenter style
1 Copyright © Ciena Corporation 2014. All rights reserved. Confidential & Proprietary.
The Gnu Debugger
Basic program building blocks
code
data
context
On-target usage
Embedded debugging with gdbserver
Core file handling
What Constitutes a Process?
A process contains:
Program code.
Executable and library ELF text segments.
Program data.
Executable and library ELF data segments:
global/static variables.
Specialised structures, e.g. the heap: dynamic data.
Execution context.
CPU registers.
Stack (a memory contraption to save/restore
registers).
GDB Building Blocks
GDB understands ELF (Executable and Linkable
Format).
Part of the SysV ABI since release 4 (1988).
Container for programs, shared libraries and core
files.
GDB uses ptrace() to control user processes.
Stop and resume execution.
Intercept signals.
Examine or modify memory.
Examine or modify registers.
Executable ELF Segments
> cat /proc/$(pgrep sleep)/maps
00100000-00103000 r-xp 00000000 00:00 0 [vdso]
0fe64000-0ffd9000 r-xp 00000000 b3:01 454447 /lib/libc-2.20.so
0ffd9000-0ffe8000 ---p 00175000 b3:01 454447 /lib/libc-2.20.so
0ffe8000-0ffea000 r--p 00174000 b3:01 454447 /lib/libc-2.20.so
0ffea000-0ffee000 rwxp 00176000 b3:01 454447 /lib/libc-2.20.so
0ffee000-0fff0000 rwxp 00000000 00:00 0
10000000-10008000 r-xp 00000000 b3:01 146126 /bin/sleep
10017000-10018000 rwxp 00007000 b3:01 146126 /bin/sleep
48000000-48021000 r-xp 00000000 b3:01 454284 /lib/ld-2.20.so
48027000-48028000 rw-p 00000000 00:00 0
48030000-48031000 r--p 00020000 b3:01 454284 /lib/ld-2.20.so
48031000-48033000 rwxp 00021000 b3:01 454284 /lib/ld-2.20.so
bfafa000-bfb1b000 rw-p 00000000 00:00 0 [stack]
PC CPSR
LR special-purpose registers
N >
Z C V Q > I F T mode: usr
CTR
31 26 8 4 0
x86 mips
local variables
saved registers
process
stops
continue
process
resumes
ctrl-c
process
stops
info reg
x/40xw $sp
b <address>
continue
process
resumes
process
stops
Remote GDB
library ELF
library ELF
program ELF
GDB is too heavyweight GDB
to run on embedded
target systems.
ELF symbol and debug
workstation
hog.
A lightweight process
runs on target and
target
relays GDB commands. process
GDB runs on a
workstation with access
Cross-Compilation Considerations
The default workstation gdb can debug native
(x86_64) programs.
Must use cross-compiled gdb included in
architecture-specific toolchain.
By default, cross-compiled gdb loads the
workstation (x86_64) system libraries.
Must supply cross-compiled gdb with appropriate file
system paths.
dbg.sh
Helper script dbg.sh invokes toolchain gdb, cross-
compiled for the target, with appropriate shared
library paths.
saos-8.x CTX:
shell> make/tools/dbg.sh gdb saos-
thorin releasefs ctx 10.1.24.124:65000
bin/cesd-ctm
saos-6.x dernhelm:
shell> make/tools/dbg.sh gdb saos-sds
tarfs dernhelm 10.1.25.119:2159
ciena/bin/leos
on any target, use “ddd” instead of “gdb” to
Firewall Considerations
workstation target system
On saos-6.x, the
firewall must be opened GDB gdbserver
/proc/<pid>/mem
GDB intercepts the
SIGTRAP and halts the
process.
Breakpoint Commands
Insert a breakpoint
(gdb) break healthAgentUptimeGet
(gdb) break *0x109aa1f0
Remove a breakpoint, all breakpoints
(gdb) delete 1
(gdb) delete breakpoints
Define breakpoint commands
(gdb) commands
print healthAgentData.uptime
continue
end
Single-step: source, opcode
(gdb) s # awkward on optimised code
Death Signals
SIGABRT SIGABR
T
SIGSEGV MMU
The program tried to program
access an invalid
memory location. SIGBU
S
SIGBUS MMU IO
The program failed an program
IO operation.
GDB with Core Files
When a process library ELF
library ELF
Execution context.
GDB obtains this data
by reading yet another
ELF file.
dbg.sh (again)
With a static core file, the toolchain GDB and
proper shared library paths must still be set. The
same helper script can be used.
saos-8.x CTX:
shell> make/tools/dbg.sh gdb saos-
thorin releasefs ctx /path/to/core
bin/cesd-ctm
saos-6.x dernhelm:
shell> make/tools/dbg.sh gdb saos-sds
tarfs dernhelm /path/to/core
ciena/bin/leos
GDB Helper Scripts
The tedious bits of core analysis are simplified by
useful helper scripts.
(gdb) cd /your/view/src/software/saos-
sds/tools/gdb
saos_helper.py
(gdb) source saos_helper.py
(gdb) help lsig
(gdb) help lps
glibc_heap.py
(gdb) source glibc_heap.py
(gdb) help heap_check
(gdb) help heap_dump
Core Examination Tip
Here is the most useful gdb command for
SIGSEGV and SIGBUS:
(gdb) x/i $pc
Shows the instruction that caused the error.
Was it a read or a write?
Where does the address come from?
Once the source of the address is figured out (i.e.
mapped to a variable or to a function parameter),
move up one stack frame and repeat.
Attitude Tip