How to disable all compilation arguments for gdb compile code command?

前端 未结 2 999
梦毁少年i
梦毁少年i 2021-01-24 02:52

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

2条回答
  •  死守一世寂寞
    2021-01-24 03:29

    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 . 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.

提交回复
热议问题