如何禁用gdb编译代码命令的所有编译参数

如何禁用gdb编译代码命令的所有编译参数

本文介绍了如何禁用gdb编译代码命令的所有编译参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循此流程来自先前的问题(请参见答案).

Following this processfrom an earlier question (see answer).

gdb是对spim的巨大改进,但是我想使用gdb的编译代码功能,在执行时注入任意mips指令.

gdb is a huge improvement over spim, but I'd like to use the compile code feature of gdb, to inject arbitrary mips instructions at the point of execution.

我已阅读在gdb中编译和注入代码.当我运行run compile code <anything>时,出现错误编译失败,参数-m32无法识别".然后,当我在gdb中运行set debug compile并再次尝试时,我看到参数-m32传递给了mips-linux-gnu-gcc.

I have read Compiling and injecting code in gdb. When I run run compile code <anything>, I get the error "compilation failed, unrecognized argument -m32". Then when I run set debug compile in gdb, and I try compile code <anything> again, I see that the argument -m32 is passed to mips-linux-gnu-gcc.

我尝试使用set compile-args -march=mips32r3覆盖编译参数,这添加了编译参数,但是-m32仍然被传递,仍然给我一个错误.

I tried overriding the compilation arguments using set compile-args -march=mips32r3, which adds the compilation argument, but -m32 is still passed and still gives me an error.

如何防止-m32通过?是否有一个干净的解决方法(缺少在编译前删除-m32的伪脚本?)

How do I prevent -m32 from being passed? Is there a clean workaround (short of making a dummy script that strips -m32 before compiling?)

推荐答案

创建此脚本special-gcc.将其设置为可执行文件,chmod 777 special-gcc.该脚本使用exec将进程替换为gcc调用,而不是生成子进程.参数为$@,存储在数组中,在循环中过滤,然后传递给gcc调用.

Make this script, special-gcc. Make it executable, chmod 777 special-gcc. The script uses exec to have the process replaced with the gcc invocation, as opposed to spawning a child process. Arguments are $@, stored in array, filtered in loop, then passed to the gcc invocation.

#!/bin/bash

declare -a args=()

#!/bin/bash
echo -- "----------------" >> ~/gcc-wrapper-log
for arg in "$@"
do
        if ! [[ "$arg" == '-m32' ]]; then
                echo -- "$arg" >> ~/gcc-wrapper-log
                args+=("$arg")
        fi
done
exec mips-linux-gnu-gcc -static "${args[@]}"

gdb内部,运行命令set compile-gcc /path/to/special-gcc.尝试一些命令compile code <anything>.然后在gcc-wrapper-log中,您可以看到编译的所有参数,可以在脚本中有选择地禁用它们.

Inside gdb, run the command set compile-gcc /path/to/special-gcc. Attempt some command compile code <anything>. Then in gcc-wrapper-log you can see all the arguments to the compilation, can selectively disable them in the script.

对我来说,编译成功,但是由于我使用的是mips-linux-gnu-gcc交叉编译器二进制文件,因此gdb似乎无法正确链接生成的.o文件.有关compile code功能内部的详细信息,请参见文档.在步骤重定位目标文件"中的某个地方,对于我来说,mips-linux-gnu-gcc的过程失败了.

For me, the compilation succeeded, but because I am using the mips-linux-gnu-gcc cross compiler binary, gdb seems not to link the resulting .o file correctly. See the docs for details on the internals of the compile code feature. Somewhere in the steps "Relocating the object file" is where the process failed for me for mips-linux-gnu-gcc.

但是,这仍然是一种精确控制gdb compile code所使用的编译参数的简便方法.

However, this is still a clean and easy way to precisely control the compilation arguments used by gdb compile code.

这篇关于如何禁用gdb编译代码命令的所有编译参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 11:17