Share to: share facebook share twitter share wa share telegram print page

GNUデバッガ

GNUデバッガ
開発元 GNUプロジェクト
初版 1986年 (38年前) (1986)
最新版
12.1[1] / 2022年5月1日 (2年前) (2022-05-01)
リポジトリ ウィキデータを編集
プログラミング
言語
C
対応OS Unix-like, Windows
種別 デバッガ
ライセンス GPL
公式サイト gnu.org/software/gdb/
テンプレートを表示

GNUデバッガ(単にGDBとも)は、GNUソフトウェア・システムで動く標準のデバッガである。これは、多くのUnix系システムで動作可能な移植性の高いデバッガであり、AdaC言語C++Objective-CPascalFORTRANFreeBASICGoといったプログラミング言語に対応している[2][3]

歴史

GDBは初め、GNU Emacs が「そこそこ安定化」した後、1986年GNU システムの一部として リチャード・ストールマン が書いた[4]。GDBは、GNU General Public License (GPL) の下でリリースしている フリーソフトウェア である。これは、BSDに付属していたdbx英語版デバッガをモデルにしている[4]

1990年から1993年まではジョン・ギルモアが保守をしていた[5]。現在はFree Software Foundationによって任命されたGDB運営委員会によって保守されている[6]

技術詳細

機能

GDBは、プログラムの実行の変更や追跡といった充実した機能を提供する。プログラム内部の 変数 の値を修正したり、監視したりすることや、プログラムの通常の動作とは別に 関数 を呼び出すことができる。

2003年 現在、GDBのターゲット・プロセッサは、以下のとおりである。

標準リリースでサポートされている、さほど有名でないターゲット・プロセッサには、以下がある。

新しいリリースでは、これらの一部をサポートしていない可能性がある。GDBには、M32RやV850といった、日本製のCPUをターゲットにしたコンパイル済みのシミュレータがある[7]

GDBはまだ活発に開発されている。バージョン7.0の新機能には、Pythonスクリプトのサポートが含まれ[8]、バージョン7.8ではGNU Guileスクリプトもサポートされている[9]。バージョン7.0からは「リバーシブルデバッグ」がサポートされている。これは、クラッシュしたプログラムを巻き戻して何が起こったのかを確認するように、デバッグセッションを後退させることができる[10]

遠隔デバッグ

GDBには「遠隔」モードがあり、しばしば組込みシステムのデバッグで使われる。遠隔操作では、GDBとデバッグ対象のプログラムは別のマシンで動作する。GDBは、GDBプロトコルをシリアルやTCP/IP経由で理解する遠隔「スタブ」と通信することができる[11]。スタブプログラムは、通信プロトコルのターゲット側を実装したGDB付属の適切なスタブファイルにリンクすることで作成できる[12]。または、gdbserver英語版を使用して、プログラムを変更せずにリモートでデバッグすることもできる。

GDBを使い、動いているLinuxカーネルをソース・レベルでデバッグするKGDBでも、同じモードを使っている。KGDBを使い、カーネル開発者は、アプリケーション・プログラムのようにカーネルをデバッグできる。カーネル・コードにブレークポイントを設定でき、ステップ動作ができ、変数を参照できる。ハードウェアのデバッグ・レジスタ (debugging register) が使えるアーキテクチャでは、ウォッチポイントが設定できる。ウォッチポイントとは、特定のメモリー・アドレスを実行したり、アクセスしたときのブレークポイントをかけるものである。KGDBには、シリアルケーブルイーサネットを使ってデバッグ対象マシンに繋がったマシンが必要となる。FreeBSDでは、FireWire DMAを使ったデバッグもできる[13]

グラフィカルユーザーインタフェース

このデバッガは、グラフィカルユーザインタフェース (GUI) は含まれておらず、デフォルトはコマンドラインユーザインタフェース (CUI) である。UltraGDB、Xxgdb、Data Display Debugger (DDD)、NemiverKDbgXcode デバッガ、GDBtk/Insight、HP Wildebeest Debugger GUI (WDB GUI) など、いくつかのフロントエンドが構築されている。CodeliteCode::BlocksDev-C++GeanyGNAT Programming Studio (GPS)、KDevelopQt CreatorLazarusMonoDevelopEclipseNetBeansVisual Studioなどの統合開発環境は、GDBとインターフェースをとることができる。GNU Emacsには「GUDモード」があり、VIM用のツールが存在する(例: clewn)。これらのツールはIDEにあるデバッガと同様の機能を提供する。

他にも、メモリリーク検出器など、GDBと連動するように設計されたデバッグツールもある。

コマンド例

gdb program "program" をデバッグ (シェル上で操作)
run -v ロードされたprogramをパラメータを指定して実行
bt バックトレース (programがクラッシュした場合)
info registers すべてのレジスタをダンプ
disas $pc-32, $pc+32 逆アセンブル(等価なコマンドは x/64i $pc-32[14] )

セッション例

C言語で書かれた以下のソースコードを考える。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

size_t foo_len( const char *s )
{
  return strlen( s );
}

int main( int argc, char *argv[] )
{
  const char *a = NULL;

  printf( "size of a = %lu\n", foo_len(a) );

  exit( 0 );
}

Linux上のGCCコンパイラを使用する場合、生成されたバイナリに適切なデバッグ情報を含めるために-gフラグを使用して上記のコードをコンパイルしなければならない。これにより、GDBを使用してバイナリを検査できる。上記のコードを含むファイルが example.c という名前であると仮定すると、コンパイルのためのコマンドは次の様になる。

$ gcc example.c -Og -g -o example

そして、バイナリを実行できるようになった。

$ ./example
Segmentation fault

サンプルコードを実行するとセグメンテーションフォールトが発生するので、GDBを使用して問題を検査することができる。

$ gdb ./example
GNU gdb (GDB) Fedora (7.3.50.20110722-13.fc16)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://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:
<https://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /path/example...done.
(gdb) run
Starting program: /path/example

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400527 in foo_len (s=0x0) at example.c:8
8	  return strlen (s);
(gdb) print s
$1 = 0x0

この問題は8行目にあり、strlen関数を呼び出す際に発生する (引数 sNULL であるため)。strlen の実装 (インライン関数かどうか) に応じて出力が異なる場合がある。

コマンド bt でプログラムのスタック・トレースをとると、main関数からソースコードの階層を降りてstrlen関数が呼び出されている流れを確かめられる。

GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://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 "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/gdb/example...done.
(gdb) run
Starting program: /tmp/gdb/example

Program received signal SIGSEGV, Segmentation fault.
0xb7ee94f3 in strlen () from /lib/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7ee94f3 in strlen () from /lib/i686/cmov/libc.so.6
#1  0x08048435 in foo_len (s=0x0) at example.c:8
#2  0x0804845a in main (argc=<optimized out>, argv=<optimized out>) at example.c:16

この問題を修正するには、変数 a (main関数内) に有効な文字列を含まなければならない。コードの修正版は次の通りである。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

size_t foo_len( const char *s )
{
  return strlen(s);
}

int main( int argc, char *argv[] )
{
  const char *a = "This is a test string";

  printf( "size of a = %lu\n", foo_len(a) );

  exit( 0 );
}

GDB内で実行ファイルを再コンパイルして実行すると、正しい結果が得られるようになった。

GDBは printf の出力を画面に表示し、プログラムが正常に終了したことをユーザに知らせる。

脚注

  1. ^ Brobecker, Joel (2022年5月1日). “GDB 12.1 released!”. 2022年5月17日閲覧。
  2. ^ GDB Documentation - Supported Languages”. 2011年11月28日閲覧。
  3. ^ GDB Documentation - Summary”. 2011年11月28日閲覧。
  4. ^ a b Richard Stallman lecture at the Royal Institute of Technology, Sweden (1986-10-30)”. 2006年9月21日閲覧。 “Then after GNU Emacs was reasonably stable, which took all in all about a year and a half, I started getting back to other parts of the system. I developed a debugger which I called GDB which is a symbolic debugger for C code, which recently entered distribution. Now this debugger is to a large extent in the spirit of DBX, which is a debugger that comes with Berkeley Unix.”
  5. ^ John Gilmore (activist)”. hyperleap.com. 2020年10月19日閲覧。
  6. ^ GDB Steering Committee”. 2008年5月11日閲覧。
  7. ^ GDB Documentation - Summary - Contributors”. 2011年12月1日閲覧。
  8. ^ GDB 7.0 Release Notes”. 2011年11月28日閲覧。
  9. ^ Joel Brobecker (2014年7月29日). “GDB 7.8 released!”. 2014年7月30日閲覧。
  10. ^ Reverse Debugging with GDB”. 2014年1月20日閲覧。
  11. ^ Howto: GDB Remote Serial Protocol: Writing a RSP Server”. 2020年10月19日閲覧。
  12. ^ Implementing a remote stub”. 2020年10月19日閲覧。
  13. ^ Kernel debugging with Dcons”. 2020年10月19日閲覧。
  14. ^ 10.6 Examining Memory”. 2020年12月30日閲覧。

関連項目


外部リンク

ドキュメント

チュートリアル

Read other articles:

TukkaKecamatanPeta lokasi Kecamatan TukkaNegara IndonesiaProvinsiSumatera UtaraKabupatenTapanuli TengahPemerintahan • CamatJulkhaidir Pardede[1]Populasi (2021)[2] • Total14.343 jiwa • Kepadatan95/km2 (250/sq mi)Kode pos22617 - 22618Kode Kemendagri12.01.14 Kode BPS1204031 Luas150,93 km²Desa/kelurahan4 desa5 kelurahan Tukka adalah sebuah kecamatan di Kabupaten Tapanuli Tengah, Sumatera Utara, Indonesia. Ibu kota kecamatan ini bera…

Este nombre sigue la onomástica coreana; el apellido es Hwang. Hwang Jung-eum Información personalNacimiento 25 de diciembre de 1984 (38 años) Seúl, Corea del SurNacionalidad surcoreanaCaracterísticas físicasAltura 1,67 m FamiliaCónyuge Lee Young-don (m.2016)Hijos 2EducaciónEducada en University of SuwonSunhwa Arts High School Información profesionalOcupación ActrizAños activa desde 2002Empleador C-JeS EntertainmentGénero K-pop Instrumento Voz Discográfica SM Entertainment…

Distrito de Lons-le-Saunier Distrito Coordenadas 46°40′00″N 5°33′00″E / 46.6667, 5.55Capital Lons-le-SaunierEntidad Distrito • País  Francia • Región Franco Condado • Departamento JuraCantones 19Comunas 344Prefectura Lons-le-SaunierSuperficie   • Total 2817 km²Población (1999)   • Total 122 373 hab. • Densidad 37,02 hab/km²[editar datos en Wikidata] El distrito de Lons-le-Saunier es u…

هذه مقالة غير مراجعة. ينبغي أن يزال هذا القالب بعد أن يراجعها محرر مغاير للذي أنشأها؛ إذا لزم الأمر فيجب أن توسم المقالة بقوالب الصيانة المناسبة. يمكن أيضاً تقديم طلب لمراجعة المقالة في الصفحة المخصصة لذلك. (يوليو 2023) زاريتان (مدينة)تقسيم إداريالبلد الأردن تعديل - تعديل مصدري …

Struktur kristal saluran kalium Kv1.2/2.1 Chimera. Perkiraan batas hidrokarbon lipid dwilapis diindikasikan dengan garis merah dan biru. Protein membran adalah protein yang berinteraksi dengan, atau bagian dari, membran biologis. Protein membran ini memuat protein membran integral yang tertahan secara permanen atau bagian dari membran dan protein membran periferal yang hanya sementara menempel pada lipid dwilapis atau pada protein integral lainnya.[1][2][3] Protein membra…

Nusa indah putih Bunga dan daunnya Klasifikasi ilmiah Kerajaan: Plantae Divisi: Angiospermae Ordo: Gentianales Famili: Rubiaceae Genus: Mussaenda Spesies: M. pubescens Nama binomial Mussaenda pubescensAit.f. Nusa indah putih (Mussaenda pubescens) adalah perdu yang tergolong familia Rubiaceae atau kopi-kopian. Ia tumbuh liar di lereng bukit, semak-belukar, dan biasanya dipelihara sebagai tanaman hias. Orang Melayu Sumatra menyebut tumbuhan ini daun putri dan nusa indah (saja).[1] Bag…

جائزة إيطاليا الكبرى 2017 Formula 1 Gran Premio Heineken d'Italia 2017[1][2] السباق 13 من أصل 20 في بطولة العالم لسباقات الفورمولا واحد موسم 2017 السلسلة بطولة العالم لسباقات فورمولا 1 موسم 2017  البلد إيطاليا  التاريخ 3 سبتمبر 2017 مكان التنظيم حلبة مونزا، إيطاليا طول المسار 5.793 كيلومتر (3.600 …

Генгам Повна назва En Avant de Guingamp Засновано 1912 Населений пункт Генгам, Франція Стадіон Стад де Рудуру Вміщує 19 033 Президент Фредерік Ле Гран Головний тренер Фредерік Бомпар Ліга Ліга 2 2021/22 6. Домашня Виїзна Запасна Генгам (фр. En Avant de Guingamp, брет. War-raok Gwengamp) — французький футбол…

Manufacturing process in which a liquid is poured into a mold to solidify For molding plastics, see Molding (process). For other uses, see Casting (disambiguation). Cast iron casting Casting is a manufacturing process in which a liquid material is usually poured into a mold, which contains a hollow cavity of the desired shape, and then allowed to solidify. The solidified part is also known as a casting, which is ejected or broken out of the mold to complete the process. Casting materials are usu…

Uruguayan footballer (born 1984) In this Spanish name, the first or paternal surname is Gargano and the second or maternal family name is Guevara. Walter Gargano Gargano training for Napoli in 2009Personal informationFull name Walter Alejandro Gargano Guevara[1]Date of birth (1984-07-23) 23 July 1984 (age 39)[1]Place of birth Paysandú, UruguayHeight 1.67 m (5 ft 6 in)[2]Position(s) Defensive midfielderTeam informationCurrent team River PlateNu…

Province of Indonesia Jabar redirects here. For other uses, see Jabar (disambiguation). Province in BandungWest Java Jawa BaratProvinceProvince of West Java Coat of armsNickname(s): Bumi PasundanHomeland of Sundaics (Sundanese)Motto(s): Gemah Ripah Répéh RapihProsperous, Serene, Peaceful, and Harmonious   West Java in    IndonesiaOpenStreetMapCoordinates: 6°45′S 107°30′E / 6.750°S 107.500°E / -6.750; 107.500CapitalBandungLargest cit…

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此條目需要擴充。 (2012年6月14日)请協助改善这篇條目,更進一步的信息可能會在討論頁或扩充请求中找到。请在擴充條目後將此模板移除。 此條目没有列出任何参考或来源。 (2012年6月14日)維基百科所有的內容都應該可供查證。请协助補充可靠来源以改善这篇条目。无法查证的內容可能會因為異議提出而…

1972 Indian filmSamadhiPosterDirected byPrakash MehraProduced byBhagwant SinghG. L. KhannaStarringDharmendraAsha ParekhJaya BhaduriMusic byR. D. BurmanProductioncompanySangam Arts InternationalRelease date 22 December 1972 (1972-12-22) CountryIndiaLanguageHindiBudget₹0.90 CrBox office₹3.20 Cr[1] Samadhi is a 1972 Hindi film directed by Prakash Mehra. The film stars Dharmendra in double role as father and son, along with Asha Parekh and Jaya Bhaduri as their love intere…

Serie A1 2023/2024Serie A1 Superlega Credem Banca 2022/2023 2024/2025 Szczegóły Państwo  Włochy Organizator Lega Pallavolo Serie A maschile Poziom ligowy najwyższy Edycja LXXVIII Liczba zespołów 12 Termin 22.10.2023 – 2024 Liczba kolejek 22 Liczba obiektów sportowych 12 (w 12 miejscowościach) Serie A1 siatkarzy 2023/2024 – 79. sezon walki o mistrzostwo Włoch organizowany przez Lega Pallavolo Serie A pod egidą Włoskiego Związku Piłki Siatkowej (wł. Federazione Italiana Pal…

2018 book on the philosophy of W. V. Quine Working from Within AuthorSander VerhaeghCover artistMarjorie Boynton QuineCountryUnited StatesLanguageEnglishSubjectsHistory of philosophyWillard Van Orman QuineNaturalismPublisherOxford University PressPublication date2018Pages218ISBN978-0-190-91315-1OCLC1039630975Dewey Decimal191LC ClassB945.Q54WebsiteOxford Academic Working from Within: The Nature and Development of Quine's Naturalism is a 2018 book by Dutch philosopher and historian of an…

2004 novella by Simon Clark The Dalek Factor AuthorSimon ClarkSeriesDoctor Who book:Telos Doctor Who novellasRelease number15SubjectFeaturing:unknown DoctorPublisherTelos Publishing Ltd.Publication dateMarch 2004Pages120ISBN1-903889-30-8 (standard)ISBN 1-903889-31-6 (deluxe)Preceded byBlood and Hope  The Dalek Factor is an original novella written by Simon Clark and based on the long-running British science fiction television series Doctor Who. It features a Doctor whose incarnati…

Video game service by Sega Sega ForeverDeveloperSegaTypeOnline serviceLaunch dateJune 22, 2017Platform(s)Android, iOSStatusActiveWebsiteforever.sega.com Sega Forever is a service from the Japanese video game developer Sega for re-releasing past games from the company on modern platforms. The service was launched for Android and iOS devices on June 22, 2017. By 2020, the service included over 30 games. Background Sega Forever is a service by Sega to re-release their previously developed video gam…

Blade Cosplayer como el personaje.Primera aparición Tomb of Dracula #10 (julio de 1973) Marvel ComicsCreado por Marv Wolfman y Gene ColanInterpretado por Wesley Snipes (1998 - 2004) Sticky Fingaz (2006) Mahershala Ali (2021-presente)Lugar de nacimiento Soho, Londres, Inglaterra, Reino UnidoInformación personalEstatus actual ActivoNombre de nacimiento Eric Darren Brooks[1]​Alias Caminante Diurno, Frank Blade, SwitchBlade, Spider Hero, Ronin, CazavampirosNacimiento 24 de octubre de 1929Nac…

This article is about indigenous peoples of Chile. For other indigenous peoples, see List of indigenous peoples. Indigenous peoples in Chile or Native Chileans form about 13% of the total population of Chile. According to the 2017 census, almost 2,200,000 people declare having indigenous origins.[1] Most Chileans are of partially indigenous descent; however, indigenous identification and its legal ramifications are typically reserved to those who self-identify with and are accepted withi…

American TV series or program Famous in 12GenreReality televisionSocial experimentPresented byHarvey LevinCountry of originUnited StatesOriginal languageEnglishNo. of seasons1No. of episodes5ProductionExecutive producersDavid GarfinkleHarvey LevinJay RenfroeCamera setupMultipleRunning time42 minutesProduction companiesHarvey Levin ProductionsRenegade 83 EntertainmentTelepicturesWarner Horizon TelevisionOriginal releaseNetworkThe CWReleaseJune 3 (2014-06-03) –July 1, 2014 (2…

Kembali kehalaman sebelumnya