How to make gdb follow execv? Not working despite “follow-exec-mode”

﹥>﹥吖頭↗ 提交于 2019-12-18 05:50:41

问题


i've written two simple programs:

int main(int ac, char **argv ) {
    execv( "/home/me/Desktop/execvtest2", argv );
}

and

int main(int ac, char **argv ) {
    execv( "/home/me/Desktop/execvtest1", argv );
}

I've compiled them with gcc -g to the according outputfiles. I'm running Ubuntu 10.10 using gcc (Ubuntu/Linaro 4.4.4-14ubuntu5.1) 4.4.5.

When I'm debuging the first program with GNU gdb (GDB) 7.2-ubuntu, I can step until the first execv statement, but then the two files just keep running. Even if I set the follow-exec-mode to new, I can't step into the second program. When I set catch exec, gdb stops at each call to execv (some how without linked source for the second program, and I'm not able to quit gdb, as it kind of hangs!?), but I'm not able to step over the call into the "new" (as exec replaces the process) inferior program.

So how can this be done? There must be a way to step into the new process right? Am I doing something wrong?

Cheers


回答1:


you can use "catch" command. this will give you chance to put some break points after you exec




回答2:


I've been doing something very similar to what you are doing for one of my classes. It is a bit hackish and if you're trying to get things like register values it may mess things up. According to GDB's documentation you can change the symbol file while maintaining the execution file. To do this, simply use the command symbol-file file2. Note that this must be a binary file compiled with the GDB flag (-g in GCC). After you've loaded this symbol file, you will not be able to break or see any of the lines for the original execution file. However, you may set break points for the new symbol file i.e. break file2.c:40 and then step through execution just as before. It is a bit hackish and may not work perfectly because you are essentially catching the execution of a new process and mapping it to the symbol table of it's binary file, without using that binary file to run it directly. I haven't had stellar results but you can see the intermediate values this way. Another thing, in order to return to debugging the original file you will have to do symbol-file file to reload it's symbol table.



来源:https://stackoverflow.com/questions/10671229/how-to-make-gdb-follow-execv-not-working-despite-follow-exec-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!