在Arch Linux上使用Makepkg
在Arch Linux上使用Makepkg可以避免系统污染,确保仅安装必要的依赖关系。
GDB是C,C ++,Objective-C,Pascal,Fortran,Go,D,OpenCL C,Ada和Modula-2的调试器。
CentOS基于RHEL(红帽企业Linux)。RHEL的主要目标之一是成为一个稳定的服务器操作系统,这意味着并非总是有较新版本的软件包。
在撰写本文时,CentOS 6提供了GDB v7.2。但是,GDB团队最近发布了v7.91的代码。
正式建议运行其他Linux发行版,以使用较新版本的GDB。这并不���是理想的。幸运的是,可以在CentOS 6上安装GDB的较新版本。由于GDB是调试器而不是系统核心组件,因此使用新版本是相当安全的。
本文介绍了如何在CentOS 6上安装受支持和不受支持的GDB版本。
我还将说明如何设置GDB,以便在使用C ++标准库(如字符串)和标准模板库(如矢量)时为您提供易于阅读的调试信息。此功能称为漂亮打印。
登录到您的VPS。可以通过在Vultr控制面板中单击“ View Console”或使用SSH客户端来完成。
(a)以root身份登录。
(b)创建您自己的用户帐户。设置密码。
adduser <username>
passwd <username>
(c)授予用户sudo访问权限。
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)以root用户身份注销,然后使用您的用户帐户重新登录。从不实际以root用户登录更加安全。使用sudo是更好的做法。
安装GDB。
sudo yum install gdb
检查安装的版本,并查看其位置。
gdb --version
May say: GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
which gdb
/usr/bin/gdb
安装C编译器,例如GCC。从源代码构建GDB不需要C ++编译器,但需要使用C ++编译器来演示GDB的漂亮打印功能。您可以通过执行文章如何在CentOS 6上安装GCC中的步骤来从源代码构建GCC的最新版本。或者,您可以通过运行以下命令来安装CentOS 6官方支持的GCC版本:
sudo yum install gcc gcc-c++
安装其他必需的软件包。
sudo yum install wget tar gzip ncurses-devel texinfo svn python-devel
确定要从源代码构建的GDB版本。访问GDB FTP站点以查看可下载的版本。
获取所需的GDB版本的源。本文的其余部分是为v7.9.1编写的,并将源代码下载到~/sourceInstallations/gdb-7.9.1/-您必须用正确的版本号替换较新的版本。
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
建立GDB。如果正确完成,您将在最后一行看到“成功”。通常,看到一些看似错误的消息会快速滚动。这些都是可以忽略的。
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
安装C ++漂亮打印。
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.
检查安装的版本及其位置。
gdb --version
May say: GNU gdb (GDB) 7.9.1
which gdb
/usr/local/bin/gdb
(可选)运行GDB并进行漂亮的打印。
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.
(可选)回收硬盘驱动器空间。您的~/sourceInstallations目录将占用约386MB。保留目录可能是明智的,因为将来可能需要使用一些可选的配置选项,并且完成很多工作会更快。此外,构建过程还会生成日志,以便日后在出现问题时进行检查和处理。但是,在sudo make install较早运行之后,已安装的GDB不再依赖于此目录中的任何内容,并且空间可能非常宝贵,因此您可以执行此步骤并回收386MB左右的内存。重要:请勿删除~/gdb_printers/目录!每次运行GDB时都会加载该目录的内容。它们没有被编译成GDB本身。
cd ~/
rm -rf sourceInstallations
--- Again, if you can spare the space, you may someday be happy to have left it there.
在Arch Linux上使用Makepkg可以避免系统污染,确保仅安装必要的依赖关系。
快速学习如何在Ubuntu 16.04上安装OpenSIPS控制面板,为VoIP提供商提供支持的功能。
学习如何在Fedora 28上安装Akaunting,一款适合小型企业和自由职业者的开源会计软件。
使用其他系统?Mailtrain是一个基于Node.js和MySQL / MariaDB构建的开源自托管新闻通讯应用程序。
了解導致Minecraft延遲的原因和解決方案,包括優化伺服器性能和減少滯後的步驟。
勒索軟件攻擊呈上升趨勢,但人工智能能否幫助應對最新的計算機病毒?AI 是答案嗎?在這裡閱讀知道是 AI 布恩還是禍根
ReactOS,一個開源和免費的操作系統,這裡有最新版本。它能否滿足現代 Windows 用戶的需求並打倒微軟?讓我們更多地了解這種老式但更新的操作系統體驗。
Whatsapp 終於為 Mac 和 Windows 用戶推出了桌面應用程序。現在您可以輕鬆地從 Windows 或 Mac 訪問 Whatsapp。適用於 Windows 8+ 和 Mac OS 10.9+
閱讀本文以了解人工智能如何在小型公司中變得流行,以及它如何增加使它們成長並為競爭對手提供優勢的可能性。
最近,Apple 發布了 macOS Catalina 10.15.4 補充更新以修復問題,但似乎該更新引起了更多問題,導致 mac 機器變磚。閱讀這篇文章以了解更多信息