CentOS7.6でgdb-dashboardを利用する方法

投稿者: | 2019年3月17日

はじめに

gdbを少し楽にする「gdb-dashboard」という、gdbの設定ファイルが公開されています。

https://github.com/cyrus-and/gdb-dashboard

2019年3月時点での「gdb-dashboard」は「gdb version 7.7」以降の機能を使用しています。
しかし、CentOS7.6上で、baseリポジトリからインストールできるバージョンは「gdb version 7.6.1」と古いので「gdb-dashboard」が使えません。

$ gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 423, in start
  File "<string>", line 307, in load_modules
  File "<string>", line 541, in __init__
  File "<string>", line 571, in add_subcommands
  File "<string>", line 1567, in commands
AttributeError: 'module' object has no attribute 'COMPLETE_EXPRESSION'
/home/vagrant/.gdbinit:1595: Error in sourced command file:
Error while executing Python code.
>>> dashboard -layout
assembly

Global    (default)

assembly  (default)
>>> 

「『COMPLETE_EXPRESSION』という属性が無い」とエラーメッセージが出力され、設定ファイルのpythonスクリプトがエラーとなります。
「COMPLETE_EXPRESSION」は「gdb version 7.6.2」から追加された定数です。これが「gdb-dashboard」が使えない原因です。

解決するには「gdb version 7.7」以降が必要で、インストール方法は以下の2つがあります。

  1. SCL(Software Collection)リポジトリからのインストール
  2. ソースファイルからのインストール

より簡単なSCLリポジトリからのインストールを方法をまとめます。

gdbをSCL(Software Collection)リポジトリからのインストール

SCLリポジトリのgdbは「devtoolset-7」パッケージに含まれています。

https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7

パッケージをインストールする

$ sudo yum install -y centos-release-scl
$ sudo yum update -y
$ sudo yum install -y devtoolset-7 

コマンドを有効化して実行する

# SCLリポジトリからインストールしたコマンドを有効化したシェルを起動する
$ scl enable devtoolset-7 bash

# SCLリポジトリからインストールしたコマンドが呼び出されることが確認できます
$ which gdb
/opt/rh/devtoolset-7/root/usr/bin/gdb

# gdbが新しいバージョンの「8.0.1」になり、エラーが出ないことが確認できます
$ gdb
GNU gdb (GDB) Red Hat Enterprise Linux 8.0.1-36.el7
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.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-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
>>> dashboard -layout
assembly expressions history memory registers source stack threads

Global       (default)

assembly     (default)
expressions  (default)
history      (default)
memory       (default)
registers    (default)
source       (default)
stack        (default)
threads      (default)
>>> 

おまけ

CentOS7.6以外の環境として、macOSとUbuntuを確認したらは以下のような状態でした。 結果は、どちらも「gdb-dashboard」が利用できるバージョンがインストールできます。

  • macOS Mojave 10.14.3上で、Homebrewによりgdbをインストールした場合は「gdb version 8.2.1」
  • Ubuntu 14.04 LTS上で、apt-getによりgdbをインストールした場合は「gdb version 7.7.1」