Following this process from an earlier question (see answer).
gdb is a huge improvement over spim, but I\'d like to use the compile code feature of gdb, to inject arbit
How do I prevent -m32 from being passed?
It looks like this is the case where GDB developers thought that "GDB knows better", and didn't provide any way to override this.
Specifically, the -m32
comes from default_gcc_target_options()
, which unconditionally adds -m%d
with gdb_arch_ptr_bit()
as the argument.
Short of building your own GDB or providing a GCC wrapper that strips -m32
, I don't see any way to get rid of this argument.
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[@]}"
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.
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
.
However, this is still a clean and easy way to precisely control the compilation arguments used by gdb compile code
.