Jump to content

LLDB (debugger)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2001:4450:43e3:cd00:ed82:f731:8b7f:4099 (talk) at 13:13, 2 December 2019 (An example session). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
LLDB
Developer(s)LLVM Developer Group
Repository
Written inC++
Operating systemmacOS i386 and x86-64, Linux, FreeBSD, Windows
TypeDebugger
LicenseUIUC (BSD-style)
Apache License 2.0 with LLVM Exceptions (v9.0.0 or later)[1]
Websitelldb.llvm.org

The LLDB Debugger (LLDB) is the debugger component of the LLVM project. It is built as a set of reusable components which extensively use existing libraries from LLVM, such as the Clang expression parser and LLVM disassembler. LLDB is free and open-source software under the University of Illinois/NCSA Open Source License,[2] a BSD-style permissive software license. Since v9.0.0, it was relicensed to the Apache License 2.0 with LLVM Exceptions.[1]

Current state

LLDB supports debugging of programs written in C, Objective-C, and C++. The Swift community maintains a version which adds support for the language. It is known to work on macOS, Linux, FreeBSD, and Windows,[3] and supports i386, x86-64, and ARM instruction sets[4]. LLDB is the default debugger for Xcode 5 and later. It can be used from other IDEs, including Visual Studio Code[5], Eclipse,[6] and CLion.[7]

Features matrix [4]
Feature FreeBSD Linux macOS Windows
Backtracing Yes Yes Yes Yes
Breakpoints Yes Yes Yes Yes
C++11: Yes Yes Yes ?
Command-line lldb tool Yes Yes Yes Yes
Core file debugging Yes Yes Yes Yes
Debugserver (remote debugging) Not ported Not ported Yes Not ported
Disassembly Yes Yes Yes Yes
Expression evaluation ? Works with some bugs Yes Works with some bugs
JIT debugging ? Symbolic debugging only Untested No
Objective-C 2.0: ? Yes

An example session

Consider the following source-code written in C:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

size_t foo_len( const char *s )
{
  return strlen( s );
}

int main( int argc, char *argv[] )
{
  const char *a = NULL;

  printf( "size of a = %lu\n", foo_len(a) );

  exit( 0 );
}

Using the Clang compiler on Linux, the code above must be compiled using the -g flag in order to include appropriate debug information on the binary generated, thus making it possible to inspect it using LLDB. Assuming that the file containing the code above is named example.c, the command for the compilation could be:

$ clang example.c -Og -g -o example

And the binary can now be run:

$ ./example
Segmentation fault

Since the example code, when executed, generates a segmentation fault, LLDB can be used to inspect the problem.

$ lldb ./example
(lldb) target create "./example"
Current executable set to './example' (x86_64).
(lldb) run
Process 7652 launched: '/path/example' (x86_64)
Process 7652 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ff75da1b801
    frame #0: 0x00007ff75da1b801 example
->  0x7ff75da1b801: movq   (%rax), %rdx
    0x7ff75da1b804: movq   %r8, %r9
    0x7ff75da1b807: addq   $0x8, %rax
    0x7ff75da1b80b: addq   %rdx, %r9

The problem is occurs when calling the function strlen (because its argument, s, is NULL). Depending on the implementation of strlen (inline or not), the output can be different.

See also

References

  1. ^ a b LICENSE.TXT, llvm.org, retrieved 2019-09-24
  2. ^ "LLVM Release License"
  3. ^ "LLVM Project Blog".
  4. ^ a b "LLDB Status". Retrieved November 28, 2019.
  5. ^ "Add a new tool named "lldb-vscode" that implements the Visual Studio Code Debug Adaptor Protocol".
  6. ^ "CDT/Useer/FAQ".
  7. ^ "LLDB CLion Blog".