• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 10, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System CentOS

How To Install GDB on CentOS 6

How VPS by How VPS
October 1, 2019
in CentOS
0
0
SHARES
107
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Log in to your VPS, and set up your user account
  2. If you want to install the officially supported (older) version of GDB
  3. If you want to install a newer version of GDB from source
  4. Want to contribute?


GDB is a debugger for C, C++, Objective-C, Pascal, Fortran, Go, D, OpenCL C, Ada, and Modula-2.

CentOS is based on RHEL (Red Hat Enterprise Linux). One of the main goals of RHEL is to be a stable server operating system, meaning that newer versions of software packages aren’t always available.

At the time of writing, CentOS 6 offers GDB v7.2. The GDB team however, recently released code for v7.91.

It is officially suggested to run a different Linux distro in order to use a newer version of GDB. This isn’t always ideal. Fortunately, it is possible to install the newer versions of GDB on CentOS 6. Since GDB is a debugger rather than a system core component, you are fairly safe to use a newer version.

This article explains how to install both supported and unsupported versions of GDB on CentOS 6.

I will also explain how to set up GDB to give you easier-to-read debugging information when using the C++ Standard Library (like string) and the Standard Template Library (like vector). This feature is called pretty printing.

Log in to your VPS, and set up your user account

  1. Login to your VPS. This can be done by clicking “View Console” in the Vultr control panel, or with an SSH client.

    (a) Login as root.

    (b) Create your own user account. Set the password.

    adduser <username>
    passwd <username>
    

    (c) Grant the user sudo access.

    visudo
        After the line "root   ALL=(ALL)   ALL"
        Add the line "<username>   ALL=(ALL)   ALL"
        --- If you aren't familiar with vi, go to the line "root   ALL=(ALL)   ALL".
        ---   Hit "o" to create a new line after that line and enter insert mode.
        ---   Type "<username>   ALL=(ALL)   ALL".
        ---   Hit ESC.
        ---   Type "ZZ" to save.
    

    (d) Log out as root, then log back in with your user account. It is much more secure to never actually log in as root. Using sudo is a better practice.

If you want to install the officially supported (older) version of GDB

  1. Install GDB.

    sudo yum install gdb
    
  2. Check the installed version, and see its location.

    gdb --version
        May say: GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
    which gdb
        /usr/bin/gdb
    

If you want to install a newer version of GDB from source

  1. Install a C compiler, such as GCC. A C++ compiler is not needed to build GDB from source, but is needed to demonstrate GDB’s pretty printing feature. You can build a more recent version of GCC from source by performing the steps in the article How to Install GCC on CentOS 6. Or, you can install the CentOS 6 officially supported version of GCC by running:

    sudo yum install gcc gcc-c++
    
  2. Install additionally required packages.

    sudo yum install wget tar gzip ncurses-devel texinfo svn python-devel
    
  3. Decide which version of GDB that you want to build from source. Visit the GDB FTP site to see the versions that are available for download.

  4. Get the source of the version of GDB that you want. The rest of this article is written for v7.9.1 and will download the sources into ~/sourceInstallations/gdb-7.9.1/ – you will have to substitute the proper version number for newer versions.

    mkdir ~/sourceInstallations
    cd ~/sourceInstallations
    wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.9.1.tar.gz .
    tar -zxvf gdb-7.9.1.tar.gz
    
  5. Build GDB. If this completes correctly, the last line you will see will say “success”. It is normal to see some error-looking messages scrolling by quickly. These are safe to ignore.

    mkdir gdb-7.9.1.build
    cd gdb-7.9.1.build
    ../gdb-7.9.1/configure --with-python=yes && make && sudo make install && echo success
        --- If your VPS has multiple cores, you can speed up the build by changing the middle part
        ---  of this line from "&& make &&" to "&& make -j <number of cores> &&".
        --- You can see the number of cores your VPS has by running "nproc"
        --- The parameter "--with-python=yes" is necessary for the pretty printing feature
    
  6. Install C++ pretty printing.

    cd ~/
    svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python gdb_printers
    Create a file ~/.gdbinit of:
        python
        import sys
        sys.path.insert(0, '/home/<yourUserName>/gdb_printers/')
        from libstdcxx.v6.printers import register_libstdcxx_printers
        end
    --- One way to create this file is to run "vi ~/.gdbinit", hitting "i" to enter insert mode,
    ---  typing the above file, hitting ESC, and hitting "ZZ" to save.
    
  7. Check the installed version, and its location.

    gdb --version
        May say: GNU gdb (GDB) 7.9.1
    which gdb
        /usr/local/bin/gdb
    
  8. Optionally run GDB and see pretty printing.

    mkdir ~/gdbExample
    cd ~/gdbExample
    Create a file gdbExample.cpp of:
        #include <string>
        #include <vector>
        using namespace std;
    
        int main() {
           string foo = "bar";
           vector<string> vec;
           vec.push_back("foo");
           vec.push_back("bar");
           vec.push_back("foobar");
        }
    --- One way to create this file is to run "vi gdbExample.cpp", hitting "i" to enter insert mode,
    ---  typing the above file, hitting ESC, and hitting "ZZ" to save.
    g++ -ggdb gdbExample.cpp -o gdbExample
    Start GDB traditionally, by running "gdb ./gdbExample".  Or, start GDB by using its terminal user interface (basically a text mode GUI), by running "gdb --tui ./gdbExample".
    Enter "break main" to set a breakpoint at the beginning of function main() -- and it will say:
        Breakpoint 1 at 0x<someAddress>: file gdbExample.cpp, line 6.
    Enter "run" to start the program, which will immediately hit the breakpoint you just set -- and it will say:
        Starting program: /home/<yourUserName>/gdbExample/gdbExample
    
        Breakpoint 1, main () at gdbExample.cpp:6
        6          string foo = "bar";
    Enter "next" and hit enter four times, and gdb will move up to just before executing:
        10         vec.push_back("foobar"); 
    Enter "print foo" and gdb will show:
        $1 = "bar"
    Enter "print vec" and gdb will show:
        $2 = std::vector of length 2, capacity 2 = {"foo", "bar"}
        --- Remember, line 10 hasn't executed yet to add "foobar" to the vector
    Enter "quit" and "y" to quit anyway.
    
  9. Optionally reclaim hard drive space. Your ~/sourceInstallations directory will be taking up around 386MB. It’s probably wise to keep the directories, as there are optional configuration options you may need to use at some point in the future, and it would be faster to have a lot already done. Also, the build process makes logs that you can later check and work from if something goes wrong. But, after running sudo make install earlier, your installed GDB isn’t depending on anything in this directory, and space can be at a premium, so you can do this step and reclaim the 386MB or so. IMPORTANT: do not delete the ~/gdb_printers/ directory! The contents of this directory are loaded each time you run GDB. They were NOT compiled into GDB itself.

    cd ~/
    rm -rf sourceInstallations
    --- Again, if you can spare the space, you may someday be happy to have left it there.
    

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install the Froxlor Server Management Panel on CentOS 7

Next Post

How to Install the Neos CMS on CentOS 7

Next Post

How to Install the Neos CMS on CentOS 7

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet