Tag: 调试

调试器向指针显示错误的值

我有以下代码: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; char str[] = “this.is.a.test”; char str2[] = “this.is.another.test”; typedef struct { size_t count; char** strings; } Tokens; Tokens Tokenize(char* String, char Split) { Tokens t; t.count = 1; for (size_t i = […]

为什么缺少某些调试符号以及如何跟踪它们?

我目前正在调试内核模块,为此,我用调试信息构建了整个内核(生成kallsyms等…)。 当我尝试nm my_module.ko ,我得到了我的模块包含的符号列表。 一切都很好,除了一些符号有点丢失,因为它们没有出现在符号列表中。 我对此的感觉是相关function正在自动内联。 无论如何,当使用qemu-kgdb / gdb运行内核时,我能够看到调用“missing”函数。 这意味着编译器没有将其擦除,因为它从未在任何代码路径中使用(因此我的“感觉”)。 由于符号没有出现,我无法在其上设置断点,gdb不会展开它,以便我可以看到正在运行的代码路径 – 了解我不知道如何告诉gdb展开它 。 不幸的是,我想看到代码路径的这一部分……我怎么能这样做? 编辑 :正如汤姆的回答中所建议的,我尝试使用file:line语法如下: 我的代码文件如下所示: int foo(int arg) // The function that I suspect to be inlined – here is line 1 { /* Blabla */ return 42; } void foo2(void) { foo(0); // Line 9 } 我尝试了b file.c:1 ,并且断点被击中但foo()函数未展开。 当然,我正在生成调试符号,因为我还设置了一个断点到foo2来检查发生了什么(效果很好)。

C中的链表实现(调试 – 输出不正确)

我在C中创建了这个链表程序。它从a3data.txt中读取数据(此文本文件的内容在输出后粘贴,如下所示)。 在文本文件中,INSERT和REMOVE是命令。 我希望能够读取命令INSERT,并将下一个整数(下一行)插入到列表中。 REMOVE命令应从列表中删除最后一个节点。 如您所见,我的删除function无法正常工作,我不明白为什么。 有人请帮我调试一下吗? OUTPUT linux@computer ~/Documents/Data Structures/a3/code $ gcc exercise4.3.3.c linux@computer ~/Documents/Data Structures/a3/code $ ./a.out INSERT 0 5 INSERT 0 5 3 INSERT 0 5 3 19 REMOVE 0 5 3 19 INSERT 1 REMOVE 0 REMOVE 0 REMOVE 0 INSERT 4 INSERT 4 25 INSERT 4 25 5 REMOVE 0 25 […]

如何在Eclipse CDT应用程序中分配输入文件而不是stdin?

我的应用程序是一个从命令行使用的简单可执行文件,并将stdin作为输入, stdout作为输出,因此它的行为与许多GNU工具一样。 为了测试它,我想设置一个Eclipse CDT DEBUG配置来将文件传递给stdin ,将另一个文件传递给stdout 。 我在DEBUG Configuration GUI中尝试了一些解决方案,但没有成功: 在Common / Standard Input and Output / Input File:我把inputfile.txt放在同一节Output file:我Output file: outputfile.txt 。 由于GUI指示工作目录是${workspace_loc:/myprogram} ,它应该没问题,但是当调试器启动时,它会发出警告: [Invalid file specified for console output: test/WittenACM87ArithmCoding-1.txt.coded] [Invalid file specified for stdin file: test/WittenACM87ArithmCoding-1.txt] 在Arguments我放了 outputfile.txt ,这显然不是为此设计的 当然,这两个文件都在工作目录中。 所有尝试都失败了ch = getc(stdin); 带有一些奇怪消息的代码行: Can’t find a source file at “/build/glibc-p3Km7c/glibc-2.24/io/../sysdeps/unix/syscall-template.S” Locate […]

如何知道ac程序的堆栈溢出?

我在c中模拟了一个问题(3d Ising模型),但是当问题大小变大时,程序停止并出现以下错误: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) 在程序中我有一个递归函数,完成所有工作,我怀疑错误是由于堆栈溢出(在递归函数中)但我不知道如何确定。 如果是因为堆栈溢出,有没有办法解决这个问题而不改变程序设计? 我正在使用Clion IDE。 /* * recursive function to form Wolff Cluster(= WC) */ void grow_Wolff_cluster(lattic* l, Wolff* wolff, site *seed){ /*a neighbor of site seed*/ site* neighbor; /*go through all neighbors of seed*/ for (int i = 0 ; i neighbors[i]; […]

如何知道一个进程是否已经启动但是在Linux中崩溃了

请考虑以下情况: – 我正在使用Linux。 我怀疑我的应用程序崩溃了。 我没有启用核心转储。 日志中没有信息。 我怎么能确定,在系统重启后我的应用程序启动了,但现在它没有运行,因为它已经崩溃了。 我的应用程序配置为服务,用C / C ++编写。 在某种程度上: 如何获得自系统启动以来执行的所有进程/服务名称? 它甚至可能吗? 我知道,我可以启用日志记录并再次启动进程以获取崩溃。

打印双类型结构成员时LLDB中的奇怪行为

在某些iOS代码中,我在一个对象上有一个C struct ivar。 此结构的一个成员是double类型。 如果我在一个方法中,分配给这个struct成员,当我打印struct本身时,调试器会报告这个struct成员的值的虚假值(就像变量的列表视图一样),但是当我直接打印struct成员时, ( p structWithDouble.doubleMember ),我得到了正确的值。 此外,如果我将此成员的值分配给本地自动double变量,我会在列表视图中和打印时看到正确的值。 我认为这是LLDB的一个问题,但令人不安和令人沮丧。 这是一个已知的问题? 如果是这样,有解决方法吗? 例子 typedef struct { double doubleMember; } structWithDouble; @interface MyClass : NSObject { structWithDouble structAsIvar; } @end @implementation – (void)someMethod { structAsIvar.doubleMember = 200.0; double localDouble = structAsIvar.doubleMember; } 在someMethod: ,调试器变量列表显示以下值: structAsIvar.doubleMember (double) 1.65865e-307 localDouble (double) 200 在LLDB中,在someMethod:中断时,我得到以下输出: (lldb) p structAsIvar.doubleMember (double) […]

在Visual C ++中进行调试时,main()中的参数被忽略

到目前为止,我已经能够使用Visual C ++中的debugging命令正确查看我的C代码的输出。 但是,当脚本依赖于main函数中的参数(例如/ argc , argv )时,调试器似乎忽略这两个参数并将它们视为未初始化。 例如,在以下代码中,输出始终为printf(“Usage: find pattern\n”); 。 #include #include #define MAXLINE 1000 int getline(char *line, int max); /* find: print lines that match pattern from 1st arg */ main(int argc, char *argv[]) { char line[MAXLINE]; int found = 0; if (argc != 2) printf(“Usage: find pattern\n”); else while (getline(line, MAXLINE) […]

声明变量堆栈

我有2个文件名为auth_overflow&auth_overflow2,唯一的区别是变量声明的序列。 我的问题是,声明序列是否会根据FILO影响它们的堆栈序列(先排在后面)? auth_overflow bash-4.2$ gdb -q auth_overflow Reading symbols from /home/reader/hacking/auth_overflow…done. (gdb) list 5 int check_authetication (char *password) { 6 int auth_flag = 0; 7 char password_buffer[16]; 8 9 strcpy(password_buffer, password); (gdb) break 9 Breakpoint 1 at 0x804850d: file auth_overflow.c, line 9. (gdb) run AAAAAAAAAAAA Starting program: /home/reader/hacking/auth_overflow AAAAAAAAAAAA Breakpoint 1, check_authetication (password=0xbffff7f3 ‘A’ ) […]

如何在使用gdb调试递归函数时跳过一部分

这是我程序中的一个function void quicksort (int *num, int p, int r, int june) { int q, bbc, ccd; if (p < r) { call++; q = partition (num, p, r, june);//<–I want to skip this call in gdb session bbc = q – 1 – p + 1;//<– and want to continue execution step by step from […]