这是这个问题的后续问题:Minimal example of Python interpreter embedding segfaults。
当我像这样编译程序时:
gcc -fno-diagnostics-color -Wall -Wno-unused-function \
-I. -fPIC -g3 -shared -I/usr/include/python3.5m \
-I/usr/include/python3.5m -Wno-unused-result \
-Wsign-compare -g \
-fdebug-prefix-map=/build/python3.5-nLrllb/python3.5-3.5.3=. \
-fstack-protector-strong -Wformat -Werror=format-security \
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes \
-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib \
-lpython3.5m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic \
-Wl,-O1 -Wl,-Bsymbolic-functions ./main.o ./binparser.o \
-o protopy出现大量选项的原因是运行:
/usr/bin/python3.5-config --cflags和/usr/bin/python3.5-config --ldconfig并试图将它们合并到构建中( -fPIC似乎是强制性的,如果没有-shared,它就不会链接,因为,我认为这是连接-fPIC库的唯一方法。
然后,当我在GDB中运行编译程序时,main()总是没有任何参数。不管我是做r foo bar还是做set args foo bar。
有什么想法吗?我不知道gcc的选择是怎么做的,所以,也许是其中的一些?
发布于 2018-04-01 21:38:11
期望gdb在共享对象中设置有意义的断点是不合理的,而该对象被调用时就好像它是可执行文件一样。如果您在按strace中描述的二进制文件上使用the linked question,那么在对真正的可执行文件使用strace时,您通常会从动态链接器看到的任何系统调用之前,都会看到一个直接的分段错误。
https://stackoverflow.com/questions/49552246
复制相似问题