gdb

What is __libc_start_main and _start?

让人想犯罪 __ 提交于 2021-02-18 16:58:08
问题 From the past few days I have been trying to understand what happens behind the curtain when we execute a C program. However even after reading numerous posts I cannot find a detailed and accurate explanation for the same. Can someone please help me out ? 回答1: You would usually find special names like this for specific uses when compiling and linking programs. Typically, something like _start would be the actual entry point for an executable, it will be located in some object file or library

How can I make GDB print 64 bit variables?

亡梦爱人 提交于 2021-02-17 07:05:46
问题 I'm using GDB to debug code that was assembled with nasm -felf64 -Fdwarf when I want to examine the value at a label symbol, say var_h: dq -1 using print var_h GDB assumes that the value is 32-bit and only gives me the lowest 4 bytes x \1gx $var_h gives an error along the lines of "cannot convert value to integer' Very grateful for any ideas! 回答1: This should work: (gdb) x/gx &var_h Your other commands, as well as "along the lines of ..." make no sense. Details matter , and you should always

How to prevent gdb to stop after next command

房东的猫 提交于 2021-02-17 04:01:10
问题 I am trying to define a chain of commands, which shall be invoked after a breakpoint in gdb: break some_function commands up next printf "some_string" continue end In this case (for example) I want to break at some_function, go up in the stack frame and jump right behind this function via the next command, then print "some_string" (or maybe some variable, which was changed by the function) and then just to continue. But that doesn't work, since gdb will just stop after the next command and

How to prevent gdb to stop after next command

故事扮演 提交于 2021-02-17 04:00:14
问题 I am trying to define a chain of commands, which shall be invoked after a breakpoint in gdb: break some_function commands up next printf "some_string" continue end In this case (for example) I want to break at some_function, go up in the stack frame and jump right behind this function via the next command, then print "some_string" (or maybe some variable, which was changed by the function) and then just to continue. But that doesn't work, since gdb will just stop after the next command and

“Hacking: The Art of Exploitation” - Assembly Inconsistencies in book examples vs. my system's gcc

怎甘沉沦 提交于 2021-02-16 09:18:07
问题 I am studying "Hacking: The Art of Exploitation". I am trying to follow the code examples, but for some reason the assembly codes simply does not match the one on my actual Linux (running on Virtual Box as Guest). I have made sure that I have installed 32 bit Linux OS. Is there any args that I can pass to gcc that lets me compile the code into an assembly that matches closely with the ones given in the book? I would be fine reconciling the code differences between the book & what I see if

qemu创建vm和vcpu进入kvm的流程

谁说我不能喝 提交于 2021-02-14 23:00:04
kvm是一个内核模块,它实现了一个/dev/kvm的字符设备来与用户进行交互,通过调用一系列ioctl函数可以实现qemu和kvm之间的切换。 1、qemu发起KVM_CREATE_VM的ioctl创建虚拟机 qemu从vl.c/main开始,通过configure_accelerator根据当前current_machine调用对应的accel_init_machine,如果是kvm则具体是 kvm_init 。当要创建虚拟机,kvm_init函数中会s->fd = qemu_open(" /dev/kvm ", O_RDWR);打开/dev/kvm设备,获取虚拟机句柄fd,在该fd上ret = kvm_ioctl (s, KVM_CREATE_VM , type); s->vmfd = ret;此ioctl函数在kvm中的实现为kvm_main.c中kvm_dev_ioctl函数。当传入的参数为KVM_CREATE_VM时,该函数会创建一个VM,并且返回一个vm_fd,通过该vm_fd可以操作虚拟机。 2、qemu中创建虚拟机的vcpu和qemu线程关系,并切换到kvm中 在vl.c/main的最开始会module_call_init(MODULE_INIT_MACHINE)本质就是把pc_init1赋值给了mc->init。在kvm_init创建完虚拟机后,会返回到main中

GDB调试原理——ptrace系统调用

时光总嘲笑我的痴心妄想 提交于 2021-02-13 03:48:31
引子: gdb基本上大家都在用,你有没有想过它的实现原理是什么?为什么它可以控制程序执行、中断、访问内存甚至直接使程序流程改变? 在使用gdb调试程序时,程序的进程状态是”T”,但又似乎并非接到了SIGSTOP信号,那么这个”T”是什么呢? 追根溯源,我们今天来研究一下Linux下这个强大的系统调用:ptrace() 首先,linux的进程状态大体分为以下几种: D (TASK_UNINTERRUPTIBLE),不可中断的睡眠状态。 R (TASK_RUNNING),进程执行中。 S (TASK_INTERRUPTIBLE),可中断的睡眠状态。 T (TASK_STOPPED),暂停状态。 t (TASK_TRACED),进程被追踪。 w (TASK_PAGING),进程调页中,2.6以上版本的内核中已经被移除。 X (TASK_DEAD – EXIT_DEAD),退出状态,进程即将被销毁。 Z (TASK_DEAD – EXIT_ZOMBIE),退出状态,进程成为僵尸进程。 (以上内容来自ps命令的manual手册,原文请看↓) 其中上面的5就是我们要讨论的,gdb调试程序时的t状态,程序被追踪。(关于进程的其他状态请自行百度)。 请看ptrace系统调用手册↓ ptrace的原型可以看到是: long ptrace(enum __ptrace_request request,

How to debug underlying C++ library from Python interface?

寵の児 提交于 2021-02-11 13:14:37
问题 I am using apollocaffe and Reinspect. Apollocaffe is in c++ library and Reinspect is in python. Reinspect called apis from apollocaffe. I like to debug those apis inside apollocaffe. From python code, I used python -m pdb train.py But I can't go inside api from apollocaffe. I do like cout << "test" << endl; in apollocaffe . But nothing is printed to console. How can I debug c++ code, at least if I can print, it will be great. 回答1: If you are interested to debug just the C++ part, you can just

How to debug underlying C++ library from Python interface?

半城伤御伤魂 提交于 2021-02-11 13:12:05
问题 I am using apollocaffe and Reinspect. Apollocaffe is in c++ library and Reinspect is in python. Reinspect called apis from apollocaffe. I like to debug those apis inside apollocaffe. From python code, I used python -m pdb train.py But I can't go inside api from apollocaffe. I do like cout << "test" << endl; in apollocaffe . But nothing is printed to console. How can I debug c++ code, at least if I can print, it will be great. 回答1: If you are interested to debug just the C++ part, you can just

How to debug underlying C++ library from Python interface?

巧了我就是萌 提交于 2021-02-11 13:05:34
问题 I am using apollocaffe and Reinspect. Apollocaffe is in c++ library and Reinspect is in python. Reinspect called apis from apollocaffe. I like to debug those apis inside apollocaffe. From python code, I used python -m pdb train.py But I can't go inside api from apollocaffe. I do like cout << "test" << endl; in apollocaffe . But nothing is printed to console. How can I debug c++ code, at least if I can print, it will be great. 回答1: If you are interested to debug just the C++ part, you can just