C++ Crash Course: a fast-Paced Introduction


GCC and Clang Debugging with GDB and LLDB



Yüklə 7 Mb.
Pdf görüntüsü
səhifə59/71
tarix20.09.2023
ölçüsü7 Mb.
#145939
1   ...   55   56   57   58   59   60   61   62   ...   71
C Crash Course A Fast-Paced Introduction by Josh Lospinoso

GCC and Clang Debugging with GDB and LLDB
The GNU Project Debugger (GDB) is a powerful debugger (https://www 
.gnu.org/software/gdb/). You can interact with GDB using the command line. 
To enable debugging support during compilation with 
g++
or 
clang++
, you 
must add the 
-g
flag. 
Your package manager will most likely have GDB. For example, to 
install GDB with Advanced Package Tool (APT), enter the following 
command:

sudo apt install gdb
Clang also has an excellent debugger called the Low Level Debugger 
(LLDB), which you can download at https://lldb.llvm.org/. It was designed to 
work with the GDB commands in this section, so for brevity I won’t cover 
LLDB explicitly. You can debug programs compiled with GCC debug sup-
port using LLDB, and you can debug programs compiled with Clang debug 
support using GDB.
N O T E
 
Xcode uses LLDB in the background.
To debug the program in Listing 1-8 (on page 20) using GDB, follow 
these steps:
1. In a command line, navigate to the folder where you’ve stored your 
header and source files.


26
Chapter 1
2. Compile your program with debug support:

g++-8 main.cpp -o stepfun -g
3. Debug your program using 
gdb
; you should see the following interactive 
console session:

gdb stepfun
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from stepfun...done.
(gdb)
4. To insert a breakpoint, use the command 
break
, which takes a single 
argument corresponding to the name of the source file and the line 
where you want to break, separated by a colon (
:
). For example, sup-
pose you want to break on the first line of main.cpp. In Listing 1-8, that 
is on line 5 (although you might need to adjust placement depending 
on how you’ve written the source). You can create a breakpoint using 
the following command at the (
gdb
) prompt:
(gdb) 

Yüklə 7 Mb.

Dostları ilə paylaş:
1   ...   55   56   57   58   59   60   61   62   ...   71




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin