@clam011 (A T)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

gdbでデバッグができません

gdbでのデバッグについて

最近c++を勉強し始めました。cygwin上でgccをコンパイラとして使っています。その際、デバッグをしようと思い、gdbでデバッグしていると、ブレイクポイントを付けようとすると、ほかのよくわからないヘッダファイルにブレイクポイントがついてしまい上手くデバッグができません。
(c++ソースファイル名はb.ccです)

発生している問題・エラー

(gdb) b 21
Breakpoint 1 at 0x100401090: file /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/stl_algobase.h, line 21.
(gdb) r
Starting program: C:\users\at-sh\documents\program\at\a.exe 
[New Thread 19564.0x13d8]
[New Thread 19564.0x4c88]
[New Thread 19564.0x4290]
[New Thread 19564.0x47b0]
warning: cYgFFFFFFFF 18026A780 0
[New Thread 19564.0x4f48]
[New Thread 19564.0x4f70]
[New Thread 19564.0xbfc]
warning: cYgstd 0xffffcb80 d 3

Thread 1 "a" hit Breakpoint 1, main ()
    at /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/stl_algobase.h:21
21      /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/stl_algobase.h: No such file or directory.
(gdb) s
[New Thread 19564.0x5e4]
std::allocator<int>::allocator (this=0xffffcbe7)
    at assignment.cpp:156
(gdb) s
__gnu_cxx::new_allocator<int>::new_allocator (
    this=0xffffcbe7)
    at /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/stl_vector.h:79
79      /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/stl_vector.h: No such file or directory.

該当するソースコード

#include <iostream> // cout, endl, cin
#include <vector> // vector

using namespace std;

int main() {
  vector<int> nums(4);

  for(int i = 0; i < 4; i++) {
      cin >> nums.at(i);
  }
  for(int i = 0; i < 4; i++) {
      cout << nums.at(i) << endl;
  }
}

自分で試したこと

ほかのc++ファイルではデバックできました。↓

#include <iostream> // cout, endl, cin


using namespace std;
int main(){
    int n;
    cin >> n;
    char n1 = n;

    cout << n1 << endl;

}

以下環境です。
os windows11
cygwin gcc-g++ 11.3.0-1

初心者なので、間違ったことを書いているかもしれません。
よろしくお願いします。

0 likes

1Answer

Comments

  1. @clam011

    Questioner

    main関数です。
    本来のコードはinclude文とmain関数の間が空いていたため、main関数が21行目になりました。質問にあたりその所を消していました。すみません
  2. 以下、私が試してみた結果です。参考になれば。

    $ cat b.cc
    #include <iostream> // cout, endl, cin
    #include <vector> // vector

    using namespace std;

    int main() {
    vector<int> nums(4);

    for(int i = 0; i < 4; i++) {
    cin >> nums.at(i);
    }
    for(int i = 0; i < 4; i++) {
    cout << nums.at(i) << endl;
    }
    }

    $ g++ -g -O0 b.cc -o b

    $ gdb b
    GNU gdb (GDB) (Cygwin 11.2-1) 11.2
    Copyright (C) 2022 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-pc-cygwin".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://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"...
    Reading symbols from b...
    (gdb) b main
    Breakpoint 1 at 0x100401090: file b.cc, line 7.
    (gdb) run
    Starting program: /cygdrive/c/Users/ita/b
    [New Thread 11548.0x2dd4]
    [New Thread 11548.0x2b64]
    [New Thread 11548.0x39f0]
    [New Thread 11548.0xb88]

    Thread 1 "b" hit Breakpoint 1, main () at b.cc:7
    7 vector<int> nums(4);
    (gdb) n
    9 for(int i = 0; i < 4; i++) {
    (gdb)
  3. @clam011

    Questioner

    ありがとうございます。
    itatagakiさんができていらっしゃるので、環境構築がうまくいっていないかもしれないですね。。。
    c++のためにダウンロードしたパケットを教えていただいてもいいですか?またgdbのパケットを入れられましたか?
  4. @clam011

    Questioner

    追記です。
    動くようになりました!原因はgdbのバージョンが古かったためでした。
    ご対応ありがとうございました!

Your answer might help someone💌