Bruce Dawson: Valve Getting Started Debugging On Linux
Bruce Dawson: Valve Getting Started Debugging On Linux
VALVE
GETTING STARTED DEBUGGING ON LINUX
(MAKING IT EASY IN LESS THAN AN HOUR)
Linux Debugging
Challenges:
Default debugger is intimidating to new users
Tough to get symbols and source to show up
Many tricks needed for efficient debugging
You can be productive on Linux, quickly
Main Topics
Choosing a debugger
Getting symbols to show up
Getting source code to show up
Tips and tricks
QtCreator Demo
Creating a project
Building
Fixing errors
Debugging
Code exploration
Getting QtCreator
Install from http://qt-project.org/downloads#qt-creator
Latest version is 3.0.0
Must mark the .run file as executable before running
Getting QtCreator
Install from http://qt-project.org/downloads#qt-creator
Latest version is 3.0.0
Must mark the .run file as executable before running
Getting QtCreator
Install from http://qt-project.org/downloads#qt-creator
Latest version is 3.0.0
Must mark the .run file as executable before running
QtCreator
Can use for full edit/build/run/debug cycle
File-> New File or Project-> Import Project-> Import
Existing Project
Imports all files from the specified directory
Will run make in that directory, assumes
makefile
Can use cmake or run any custom build
command you want
QtCreator building
Summarizes warnings and errors in Issues tab
Can double-click to jump to location of
error/warning
QtCreator Debugging
VS compatible keyboard shortcuts (F5, F10, F11, etc.)
Important exception: Ctrl+F5
Can load core files, attach to processes, launch
processes, etc.
Other debug windows available from Window-> Views
Threads window
Registers window
Debugger log (for invoking raw gdb commands)
Symbols!
Symbol Stripping
Symbol Stripping
File paths made from product name, file name, build ID, then file name
again
Archived files contain both binary code and debug info (symbols)
Two links point to each file
/mnt/syms/.build-id/6d/5f7575de387ed72286
/mnt/syms/.build-id/6d/5f7575de387ed72286.debug
/mnt/syms/tf2/client.so.dbg/6d5f7575de387ed72286/client.so.dbg
Source Sanity
Source for locally built binaries will just work
Build machine binaries need remapping
(gdb) set substitute-path /home/buildbot/tf2/build/src /data/clients/tf2/src
Put in ~/.gdbinit
Get libc6 source and add to gdb search paths:
ldd
prints shared library dependencies
Used to diagnose why a module wont load
tf2/game$ ldd hl2_linux
linux-gate.so.1 => (0xf7780000)
libtcmalloc_minimal.so.4 => not found
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2
libc.so.6 => /lib/i386-linux-gnu/libc.so.6
/lib/ld-linux.so.2
Often fixed by setting LD_LIBRARY_PATH
Better On Linux
ValGrind runs process on a virtual CPU, analyzes
every memory access. Finds leaks, overruns, and
uninitialized variables
strace trace system calls. Sample usage:
$ strace -p $(pidof procname)
Attach to process
$ strace -o out.txt ls
Launch process
Dumpbin Replacements
nm list symbols in a shared object
objdump -d disassemble an object file
References
QtCreator:
http://qt-project.org/downloads#qt-creator
http://richg42.blogspot.com/2013/10/a-shout-out-to-qtcreator-28x-on.html
http://richg42.blogspot.com/2013/10/qtcreators-python-debug-visualizers.html
http://linux-debugger-bits.blogspot.com/2014/01/qtcreator-projects.html
http://fedoraproject.org/wiki/Releases/FeatureBuildId#Find_files_by_build_ID
Ptrace hardening:
https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection
Questions?
[email protected]
Ask questions now
Or drop by the Linux break-out session at 5:00 in
this room (6C)
Canmovabs
work around
by right-clicking on EIP in
40059f:
rax,0x400921fb54442d18
4005a9:
mov
QWORD PTR
registers
window
and[rbp-0x8],rax
selecting Open
4005ad:
16
InlineDebugTest();
call
0x400544
<InlineDebugTest()>
Disassembler
at <address>
4005b2:
movsd