Gdb print to file instead of stdout

后端 未结 8 2002
醉话见心
醉话见心 2020-11-29 17:15

I am running gdb and want to examine one of those unfortunate god objects. It takes many pages (and I have a 24\" monitor turned sideways!) to see the whole thing. For eas

8条回答
  •  鱼传尺愫
    2020-11-29 17:56

    I had a backtrace that was so long (over 100k lines) that holding down the enter key was taking too long. I found a solution to that:

    Andreas Schneider's bt command writes a backtrace to file without any user interaction – just prefix your command with bt .

    Here, I've turned it into a script:

    #!/usr/bin/env bash
    ex=(
        -ex "run"
        -ex "set logging overwrite on" 
        -ex "set logging file gdb.bt" 
        -ex "set logging on" 
        -ex "set pagination off"
        -ex "handle SIG33 pass nostop noprint"
        -ex "echo backtrace:\n"
        -ex "backtrace full"
        -ex "echo \n\nregisters:\n"
        -ex "info registers"
        -ex "echo \n\ncurrent instructions:\n"
        -ex "x/16i \$pc"
        -ex "echo \n\nthreads backtrace:\n"
        -ex "thread apply all backtrace"
        -ex "set logging off"
        -ex "quit"
    )
    echo 0 | gdb -batch-silent "${ex[@]}" --args "$@"
    

提交回复
热议问题