Gdb print to file instead of stdout

后端 未结 8 1995
醉话见心
醉话见心 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 "$@"
    
    0 讨论(0)
  • 2020-11-29 17:59

    Extending on @qubodup's answer

    gdb core.3599 -ex bt -ex quit |& tee backtrace.log
    

    the -ex switch runs a gdb command. So the above loads the core file, runs bt command, then quit command. Output is written to backtrace.log and also on the screen.

    Another useful gdb invocation (giving stacktrace with local variables from all threads) is

    gdb core.3599 -ex 'thread apply all bt full' -ex quit
    
    0 讨论(0)
提交回复
热议问题