📖
Wiki
Back to my personal website
  • Home
  • Equipment and Devices
    • 3D Printer
    • Laser Cutter
    • Motion Capture System
    • Sensors
      • RGB-D Cameras
      • Velodyne LiDAR
      • Zed Camera
      • RealSense D435i
      • IMU
    • eGPU
    • Nvidia AGX Xavier
    • CPU Benchmark
    • Installation Checklist
  • Development
    • Linux
      • Shell
      • GDB
      • Git
      • Tmux
      • Network
      • Tricks
      • Debug FAQ
    • CMake
      • Catkin Tools
      • CMakeLists
      • CMake Variables
      • CMake Commands
      • CMake: find_package()
    • ROS
      • Gazebo
      • wstool
      • roslaunch
      • rosbag
      • multi-threaded spinner
    • ROS2
      • Convert ROS1 bag to ROS2 bag
    • C++
      • C++ 11
      • C++ Examples
      • C++ Debug
      • Factory Method
      • Timing
    • Google Tools
      • GLog
      • GFlags
      • GTest
      • Style Guide
      • Clang Format
    • PCL
      • Point Type
      • Methods
      • Architecture
      • Code Explained
    • Open3D
      • Python API
      • Registration
      • Visualization
      • Tools
    • OpenCV
      • Documentation
      • Modules
    • Other Libraries
      • Eigen
      • Ceres
      • g2o
      • GTSAM
    • Website
  • Algorithm
    • SLAM
      • K-D Tree
      • Octree
      • Bag of Words
      • Distance Measures
      • Coordinate Systems
      • LOAM
      • Iterative Closest Point
      • Generalized ICP
      • Mahalanobis Distance
    • Computer Science
      • Computational Model
      • Sorting
      • Analysis
      • Complexity Classes (P, NP)
      • Divide and Conquer
      • Greedy Algorithm
      • Dynamic Programming
      • Tree
      • Graph
    • Computer Vision
      • Camera Models
      • Distortion
      • Motion Models
      • Shutter
      • Image Sensors
      • Epipolar Geometry
      • Multiple-View Geometry
    • Datasets
      • RGB-D Datasets
      • Point Cloud Datasets
      • LiDAR SLAM Datasets
  • Math
    • Optimization
      • Convex Optimization
      • Descent Methods
    • Probability
      • Moment
      • Covariance Matrix
      • Stochastic Process
    • Topology
      • References
      • Concepts
      • Topological Spaces
      • Representation of Rotations
      • Representation of 3-sphere
    • Algebra
      • Linear Algebra
      • Matrix Factorization
      • Condition Number
      • Matrix Lie Group
    • Differential Geometry
      • Manifold
      • Submanifold
      • Quotient Manifolds
      • Tangent Space
  • Quadrotor
    • PX4 Development
    • Companion Computer
    • Drone Hardware
    • Propeller Lock
    • Debug
  • Favorites
    • Bookmarks
Powered by GitBook
On this page

Was this helpful?

  1. Development
  2. Linux

GDB

gdb

  • make sure debug flag is enabled when compiling the program.

    • e.g., gcc -g

    • e.g., set(CMAKE_BUILD_TYPE RelWithDebInfo) or cmake -DCMAKE_BUILD_TYPE=Debug

  • gdb <program_name>

  • gdb --args <program_name> arg1 arg2 arg3

  • (gdb) break main add a breakpoint at main function

  • (gdb) r run the program

  • (gdb) list list current function (in its original programming language)

  • (gdb) tbreak 48 add a temporary breakpoint at line 48 of current function

  • (gdb) c continue running the program

  • (gdb) bt print backtrace (of current stack)

  • (gdb) print <var> print a variable

  • (gdb) info locals print all local variables (of current stack)

  • (gdb) x /x 0x7fffffffd9b0 exam the memory at this address using hex format

  • (gdb) q quit

More useful commands

  • (gdb) s step into next function

  • (gdb) n go to next instruction

  • (gdb) bt full print full stack info including variables

  • (gdb) info args print local argc and argv information

  • (gdb) whatis v check variable type

  • (gdb) disas disassemble current function into assembly language

  • (gdb) list <filename:function_name> list a function

  • (gdb) list <filename:line_number> list a file around this line number

  • (gdb) tbreak 0x000055555576bf00 add a temporary breakpoint at the address (of an instruction)

  • (gdb) x /2xw 0xffff print two-word length of the memory at this address using hex format

    • b byte, h half-word (2 bytes), w word (4 bytes), g giant word (8 bytes)

    • x hex, a pointer, c char, d integer, u uint, s string, t binary, f float, o octal

Fancy usage of extended gdb commands

  • need to download and source stl-views-1.0.3.gdb ; can be added to ~/.gdbinit

  • (gdb) pvector <name> print information about the STL vector class std::vector<T>

  • (gdb) pmap <name> print information about the STL map class std::map<T,T>

PreviousShellNextGit

Last updated 4 years ago

Was this helpful?

references: ; ; ; ;

gdb cheatsheet
gdb commands
gdb STL support
download stl-views-1.0.3.gdb