Tag: gdb

gdb可以使函数指针指向另一个位置吗?

我会解释一下: 假设我有兴趣替换某个应用程序使用的rand()函数。 所以我将gdb附加到此进程并使其加载我的自定义共享库(具有自定义的rand()函数): call (int) dlopen(“path_to_library/asdf.so”) 这会将自定义的rand()函数放在进程的内存中。 但是,此时符号rand仍将指向默认的rand()函数。 有没有办法让gdb将符号指向新的rand()函数,强制进程使用我的版本? 我必须说我也不允许使用LD_PRELOAD (linux)或DYLD_INSERT_LIBRARIES (mac os x)方法,因为它们只允许在程序执行开始时注入代码。 我想替换rand()的应用程序,启动几个线程,其中一些启动新进程,我有兴趣在其中一个新进程上注入代码。 正如我上面提到的,GDB非常适合这个目的,因为它允许代码注入特定的进程。

无法访问内存 – gdb

这是我的disas代码: Dump of assembler code for function main: 0x00000000000006b0 : push %rbp 0x00000000000006b1 : mov %rsp,%rbp 0x00000000000006b4 : sub $0x10,%rsp 0x00000000000006b8 : movl $0xa,-0xc(%rbp) 0x00000000000006bf : lea -0xc(%rbp),%rax 0x00000000000006c3 : mov %rax,-0x8(%rbp) 0x00000000000006c7 : lea 0x96(%rip),%rdi # 0x764 0x00000000000006ce : mov $0x0,%eax 0x00000000000006d3 : callq 0x560 0x00000000000006d8 : mov $0x0,%eax 0x00000000000006dd : leaveq 0x00000000000006de : […]

gdb – 按预定义规则跳过某个文件的进一步步骤?

假设我有这个文件: xb@dnxb:/tmp/c$ cat helloworld.h void hello(); xb@dnxb:/tmp/c$ cat helloworld.c #include void hello() { printf(“Hello world!\n”); printf(“Next line\n”); } xb@dnxb:/tmp/c$ cat main.c #include #include “helloworld.h” int main(void) { hello(); return 0; } 并编译: xb@dnxb:/tmp/c$ gcc -g3 -shared -o libhello.so -fPIC helloworld.c -std=c11 xb@dnxb:/tmp/c$ gcc -g3 main.c -o main -Wl,-rpath,”$PWD” -L. -lhello 然后用gdb调试: xb@dnxb:/tmp/c$ gdb -q -n […]

在gdb调试器中运行程序时出错

当我在gdb中运行程序时,它会给出错误“程序正常退出”,任何人都可以帮我解决这个问题。

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

我目前正在调试内核模块,为此,我用调试信息构建了整个内核(生成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来检查发生了什么(效果很好)。

gnu gdb malloc返回不可访问的指针

运行一些代码后,gdb调试会话中的malloc返回不可访问的地址。 首先在主要function开始时rest。 一切都好。 Breakpoint 9, main (argc=5, argv=0x7fffffffe418) at src/ose/sdv/ose_sdv/linux/main.c:557 557 char *cfgfile = NULL; (gdb) call malloc(4) $50 = 23293968 (gdb) x 23293968 0x1637010: 0x00000000 (gdb) c 在运行一些行后,它开始返回无法访问的内存地址,该地址从0xffffffff~开始 Program received signal SIGINT, Interrupt.0x00007ffff70c1f4d in read () from /lib64/libc.so.6 (gdb) call malloc(4) $52 = -1811110576 (gdb) x -1811110576 0xffffffff940ca550: Cannot access memory at address 0xffffffff940ca550 […]

双指针在函数中没有得到malloc’d

所以我在C中工作,我在一个函数内部有一个int ** ,它在另一个函数中被修改。 当我运行这个问题时,我得到了一个SegFault,所以我决定用gdb调试它。 我发现内存从未分配给这个数组。 我的function是这样的 void declarer() { int ** a; alocator(a, 4, 5); for (int i = 0; i < 4; i++) for (int j = 0; j < 5; j++) printf("%d\n", a[i][j]); } void alocator(int ** a, int b, int c) { a = (int **)malloc(sizeof(int *) * b); for (int i […]

特定内存地址的内容与gdb中预期的不同

我有类型为int的变量i,其值为129.我在gdb中使用了此变量的各种表示。 # Decimal format of i (gdb) p/di $18 = 129 # Binary format of i (gdb) p/ti $19 = 10000001 # Address of variable i (gdb) p &i $20 = (int *) 0xbffff320 # Binary format displayed at one byte (gdb) x /tb &i 0xbffff320: 10000001 # Decimal format displayed at four bytes (one […]

如何在GDB中调试libgcc源代码? Ubuntu 14.04.1

我想在Ubuntu 14.04.1的源代码级别的GDB中调试libgcc_s.so.1 。 所以我下载了libgcc1-dbg并获得了gcc的源代码。 在GDB中,我使用directory来指定gcc源目录。 但是当我在GDB中出现一些问题,并在libgcc_s.so.1中断时,我无法获得源代码。 Reading symbols from /home/love/pri…(no debugging symbols found)…done. (gdb) directory ~/source/gcc-4.9/ Source directories searched: /home/lovelydream/source/gcc-4.9:$cdir:$cwd (gdb) c The program is not being run. (gdb) run Starting program: /home/lovelydream/prison warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000 > Program received signal SIGINT, Interrupt. 0x00007ffff75e6350 in __read_nocancel () […]

GDB跨越命令

我有以下C代码: #include #include #define SECTSIZE 512 #define ELFHDR ((struct Elf *)0x10000) // scratch space void readsect(void*, unit32_t); void readsec(uint32_t, uint32_t, uint32_t); void bootmain(void) { struct Proghdr *ph, *eph; // read 1st page off disk readseg((uint32_t) ELFHDR, SECTSIZE*8, 0); . . // REST OF CODE . } 我正在使用gdb介入我的代码,看看发生了什么。 我找到了bootmain 0x7d0a的地址,我在那里放了一个断点。 b *0x7d0a c 以上2个命令: b放置断点, c运行直到达到断点。 […]