gdb

Gdb jumping some parts of the assembly codes

不打扰是莪最后的温柔 提交于 2020-12-10 07:45:24
问题 I'm having a difficult to debug a program at assembly level because GDB is jumping some parts of the code. The code is: #include <stdio.h> #define BUF_SIZE 8 void getInput(){ char buf[BUF_SIZE]; gets(buf); puts(buf); } int main(int argc, char* argv){ printf("Digite alguma coisa, tamanho do buffer eh: %d\n", BUF_SIZE); getInput(); return 0; } The program was compiled with gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=4 -o exploit1 exploit1.c In gdb, I added break getInput and when

Gdb jumping some parts of the assembly codes

妖精的绣舞 提交于 2020-12-10 07:44:04
问题 I'm having a difficult to debug a program at assembly level because GDB is jumping some parts of the code. The code is: #include <stdio.h> #define BUF_SIZE 8 void getInput(){ char buf[BUF_SIZE]; gets(buf); puts(buf); } int main(int argc, char* argv){ printf("Digite alguma coisa, tamanho do buffer eh: %d\n", BUF_SIZE); getInput(); return 0; } The program was compiled with gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=4 -o exploit1 exploit1.c In gdb, I added break getInput and when

Why does gdb tell me a pointer is 4 bytes on x86-64?

老子叫甜甜 提交于 2020-12-08 05:26:39
问题 Seen with gdb on openSUSE, CentOS, Fedora, and Ubuntu: This gdb was configured as "x86_64-unknown-linux-gnu". (gdb) p sizeof(void *) $1 = 4 (gdb) p sizeof(long) $2 = 4 Why is gdb giving me the wrong answers on all of my 64-bit systems? 回答1: It seems like gdb chooses some surprising defaults when you're not debugging any particular piece of code . If you load up a 64-bit executable as in: gdb /bin/sh you get a less-surprising result: (gdb) p sizeof(void *) $1 = 8 You can also specifically tell

GDB breakpoints with multiple conditions on non-native types

寵の児 提交于 2020-12-06 12:56:27
问题 I'm debugging a C/C++ program where I want to set a single break point with a condition depending on multiple variables. break foo.cpp:60 if (bar == 3 && i == 5) This doesn't seem to work, as it stops whenever it hits foo.cpp:60 instead of whenever both of the conditions match (it doesn't even match one of the conditions). Is there an easy way to do what I'm trying to achieve? Edit : bar and i are not native C types, they are strongly typed. break foo.cpp:60 if ((A) bar == 3 && (B) i == 5)

《深入理解计算机系统》(CSAPP)实验三 —— Buf Lab

时间秒杀一切 提交于 2020-12-02 15:22:27
这是CSAPP的第三个实验,主要让我们熟悉GDB的使用,理解程序栈帧的结构和缓冲区溢出的原理。 实验目的   本实验的目的在于加深对IA-32函数调用规则和栈结构的具体理解。实验的主要内容是对一个可执行程序“bufbomb”实施一系列缓冲区溢出攻击(buffer overflow attacks),也就是设法通过造成缓冲区溢出来改变该可执行程序的运行内存映像,继而执行一些原来程序中没有的行为,例如将给定的字节序列插入到其本不应出现的内存位置等。本次实验需要你熟练运用 gdb 、 objdump 、 gcc 等工具完成。   实验中你需要对目标可执行程序BUFBOMB分别完成5个难度递增的缓冲区溢出攻击。5个难度级分别命名为 Smoke (level 0)、 Fizz (level 1)、 Bang (level 2)、 Boom (level 3)和 Nitro (level 4),其中Smoke级最简单而Nitro级最困难。 准备工作   编译环境:Ubuntu 16.04,gcc 5.4.0。   在官网下载得到实验所需文件解压后会得到三个不同的文件。对三个文件简要说明如下所示。   README.txt:描述文件夹目录   bufbomb:将要攻击的缓冲区炸弹程序。   makecookie:根据您的用户名生成一个“ cookie”。   hex2raw

How to define offsetof() macro in GDB

一个人想着一个人 提交于 2020-12-02 07:15:17
问题 I want to define some auxiliary marcos in GDB for convenience, one of them is the offsetof() macro. I tried define offsetof if $argc == 2 (int)(&((($arg0 *)0)->$arg1)) end end It doesn't work because: A type such as struct node will be splitted into Struct and node , so $arg0 = Struct , $arg1 = node . I am not sure if gdb's command can return a value. Can anyone give me a hand? 回答1: Rather than define offsetof as a command, I think it's better to define it as a function. That way you can use

GDB info registers command - Second column of output

只谈情不闲聊 提交于 2020-12-01 09:44:16
问题 Upon running info registers in gdb, we get an output similar to the following: rax 0x1c 28 rbx 0x0 0 rcx 0x400a60 4196960 rdx 0x7fffffffde88 140737488346760 rsi 0x1 1 rdi 0x400932 4196658 rbp 0x0 0x0 rsp 0x7fffffffde68 0x7fffffffde68 r8 0x400ad0 4197072 r9 0x7ffff7dea560 140737351951712 r10 0x7fffffffdc30 140737488346160 r11 0x7ffff7732dd0 140737344908752 r12 0x4007f0 4196336 r13 0x7fffffffde80 140737488346752 r14 0x0 0 r15 0x0 0 rip 0x7ffff7732dd0 0x7ffff7732dd0 eflags 0x202 [ IF ] cs 0x33

GDB info registers command - Second column of output

[亡魂溺海] 提交于 2020-12-01 09:44:03
问题 Upon running info registers in gdb, we get an output similar to the following: rax 0x1c 28 rbx 0x0 0 rcx 0x400a60 4196960 rdx 0x7fffffffde88 140737488346760 rsi 0x1 1 rdi 0x400932 4196658 rbp 0x0 0x0 rsp 0x7fffffffde68 0x7fffffffde68 r8 0x400ad0 4197072 r9 0x7ffff7dea560 140737351951712 r10 0x7fffffffdc30 140737488346160 r11 0x7ffff7732dd0 140737344908752 r12 0x4007f0 4196336 r13 0x7fffffffde80 140737488346752 r14 0x0 0 r15 0x0 0 rip 0x7ffff7732dd0 0x7ffff7732dd0 eflags 0x202 [ IF ] cs 0x33

面试经验:腾讯C++后台开发面试笔试知识点总结参考笔记

限于喜欢 提交于 2020-11-29 10:13:15
文末提供本文学习资源获取方式,需要请自取。 文章是由我笔试面试腾讯笔记整理而来,主要是针对面试的C++后台开发岗位,涵盖了大部分C++后台开发相关可能会考察和被问到的技术点。 自认为这篇笔记比较全面的总结,不管你是已经工作准备参加社招,还是在校学生准备参加校招,笔记都可以作为技术面试准备阶段参考查阅,查缺补漏。 这篇笔记是基础C++知识点总结,没有过多的阐述后台开发的系统架构和分布式后台服务设计相关,还有c++11新特性,这些笔试面试也会被问到但不在这篇讨论范围,可以关注我后面有时间再补上。 阅读提示 文章约12839字,阅读时长预计33分钟。建议关注收藏方便回头查阅。 gdb调试命令 step和next的区别? 当前line有函数调用的时候,next会直接执行到下一句 ,step会进入函数. 查看内存 (gdb)p &a //打印变量地址 (gdb)x 0xbffff543 //查看内存单元内变量 0xbffff543: 0x12345678 (gdb) x /4xb 0xbffff543 //单字节查看4个内存单元变量的值 0xbffff543: 0x78 0x56 0x34 0x12 多线程调试 (gdb) info threads:查看GDB当前调试的程序的各个线程的相关信息 (gdb) thread threadno:切换当前线程到由threadno指定的线程 break

Where do I find the assembly that creates a static variable in the .data section of my C program?

删除回忆录丶 提交于 2020-11-28 01:41:44
问题 First time poster. 2nd year CS student. I am exploring the creation of static variables in the .data section of the Virtual Address Space in the context of a C source->GCC compilation->Linux execution environment. C program is test.c int main() { register int i = 0; register int sum = 0; static int staticVar[10] = {1,2,3,4,5,6,7,8,9,-1}; Loop: sum = sum + staticVar[i]; //optimized away i = i+1; if(i != 10) goto Loop; return 0; } Asking GDB to ' disass /m ' reveals that there is no code for