GDB vs LLDB
Go up to the main documents page (md)
Both gdb and lldb are excellent debuggers. GDB is part of the GNU
framework, and was created to work alongside of g++, which
is the GNU C++ compiler. LLDB is part of the LLVM framework, and was
created to work alongside of clang++, which is the LLVM C++
compiler.
Ideally, you would use the debugger of the same framework that the compiler is part of. However, a bug with LLVM prevents it from working inside a Ubuntu VirtualBox image (see here for the bug tracker about this issue). Thus, we are going to use gdb instead of lldb, even though we will continue to use the clang++ compiler.
Both debuggers can debug code compiled by either compiler. The only real differences, as far as this class is concerned, have to do with some of the commands. There are other differences between the debuggers, but those differences are not commands that we will see in this course. The full list of commands can be found on the GDB command summary page and the LLDB command summary page.
The majority of the commands are the same; this document only highlights the commands that are different between the two debuggers. The categories listed below match those on the two specific debugger pages (GDB command summary and LLDB command summary).
Assembly-specific commands
- displaying the values in the registers:
info registersfor gdb,registers readfor lldb - set the assembly output format to what we are used to in class (and
what we are programming in):
set disassembly-flavor intelfor gdb,settings set target.x86-disassembly-flavor intelfor lldb - prints the assembly code for the supplied function (up until the
next label):
disassemble (function)for gdb,disassemble --name (function)for lldb
Program execution
- starts a program execution, and breaks when it enters the main()
function:
startin gdb; there is no direct equivalent in lldb (but you can do it via two commands:b mainandrun) - shows the lines of source code before and after the point at which
the program paused:
listin gdb,fin lldb
Breakpoints
- show breakpoints:
info breakin gdb,breakpoint listin lldb - delete all breakpoints:
delete(or justd) in gdb,breakpoint deletein lldb - delete the breakpoint indicated by (num):
delete (num)in gdb,breakpoint delete (num)in lldb
Examining data
- display all the local variables and their values:
info localsin gdb,frame variablein lldb - set the variable (var) to the value (value):
set variable (var) = (value)in gdb,expr (var) = (value)in lldb