#includeの行にブレークポイントを設定すると、gdbは行を無視してメインの次の命令で停止しますmain.cppはg++ -g -O2 -std=c++11
です)。gdbは#includeディレクティブの行で停止しません
プログラムは完璧に動作します(-O2は結果に全く影響しません)。しかし、そのファイル内で何が何か正確に実行されているかを確認したいのですが、gdbでコードを入力できないためファイル。
他のファイル内でコードをデバッグするにはどうすればよいですか?それも可能ですか?
編集:ここではこれは、コードIでコード
main.cppに
#include <iostream>
#include <cstdlib>
#include <chrono>
#include "inc/includes.h"
template <class T>
void PrintVector(T* vector, int size){
for (int i=0; i<size; ++i){
std::cout << vector[i] << " ";
}
std::cout << std::endl;
}
template <class T>
void CheckTime(void (*f)(T*&, int), T* &vector, int size){
std::chrono::high_resolution_clock::time_point tantes, tdespues;
std::chrono::duration<double> transcurrido;
tantes = std::chrono::high_resolution_clock::now();
(*f)(vector, size);
tdespues = std::chrono::high_resolution_clock::now();
transcurrido = std::chrono::duration_cast<std::chrono::duration<double>(tdespues - tantes);
std::cout << size << " " << transcurrido.count() << std::endl;
}
int main(int argc, char * argv[]){
if (argc != 2){
std::cerr << "Formato " << argv[0] << " <num_elem>" << std::endl;
return -1;
}
int n = atoi(argv[1]);
int range;
#if defined RADIXSORTLSD || defined RADIXSORTMSD
unsigned short * array = new unsigned short[n];
range = (n<65536)?n:65536;
#else
unsigned int * array = new unsigned int[n];
range = n;
#endif
srand(time(0));
for (int i = 0; i < n; i++){
array[i] = rand()%range;
}
#ifdef PRINT
PrintVector(array, n);
#endif
#include "inc/select.h" //Here is the problem for debugging
#ifdef PRINT
PrintVector(array, n);
#endif
}
includes.h
#include "../src/radixsortlsd.cpp"
#include "../src/radixsortmsd.cpp"
#include "../src/mergesort.cpp"
#include "../src/bitonicsort.cpp"
#include "../src/insertion.cpp"
#include "../src/slowsort.cpp"
#include "../src/selection.cpp"
select.hですデバッグしたい私はそれが大きくなるので、それをメインから切り離すことに決めました。
// The calls to CheckTime takes the first parameter as the direction to a function, previously defined inside the cpps of includes.h
#ifdef RADIXSORTLSD
CheckTime(&RadixSortLSD, array, n);
#endif
#ifdef RADIXSORTMSD
CheckTime(&RadixSortMSD, array, n);
#endif
#ifdef MERGESORT
CheckTime(&MergeSort, array, n);
#endif
#ifdef INSERTION
CheckTime(&Insertion, array, n);
#endif
#ifdef SLOWSORT
CheckTime(&SlowSort, array, n);
#endif
#ifdef SELECTION
CheckTime(&Selection, array, n);
#endif
#ifdef BITONICSORT
CheckTime(&BitonicSort, array, n);
#endif
このヘルプが欲しいです。
:デバッグ(正しい単語ではありません)によって、私は関数がどのように機能するかを調べることを意味しました。(関数私は完全に理解していない)。
プリプロセッサディレクティブは、どのマシン命令にもマッピングされません。デバッガが何らかの方法でそれらを知覚すると思われるのはなぜですか?別のモジュールの関数をデバッグするには、この関数を呼び出します。 – Drop
したがって、どのようにそのファイルの中にあるものをデバッグできますか? –
ファイルをデバッグすることはできません。実行可能コードをデバッグすることができます。なぜ、関数の中に何かを最初に入れるのですか?これはナンセンスです。 – Drop