質問

I am working with a blind student. She can run gdb from the command line to debug a window-based program, but the program takes the focus from gdb, so if a breakpoint is hit or the program crashes, the screen reader does not read the gdb result. Ideally, it would like if the focus would go to the terminal when it gets gdb output, but otherwise, is there a way to run a linux command when gdb hits a breakpoint or when the program crashes? Then I could run "espeak gdb" and she would know that gdb needs to get focus.

Seems there should be an easy way to do this using scripting in .gdbinit.

Edited later:

I figure out that you can put this code into .gdbinit:

python
import os
def stop_handler (event):
os.system("espeak gdb")

gdb.events.stop.connect (stop_handler)
役に立ちましたか?

解決

You can install stop hook hook-stop and use shell followed by a command so it get executed when ever the debugger stops, for example running cmd (Windows) so it echo some string from the shell on stop:

define hook-stop
    shell cmd /c echo "hello"
end

Replace cmd /c echo "hello" with the command you want, and copy it and past it in the debugger, now when my program crushes:

#include <stdio.h>

int main(int argc, char **argv) {
  int *p = NULL;

  printf("%d\n", *p);

  return 0;
}

I should see "hello":

> gdb -q a.exe
Reading symbols from a.exe...done.
(gdb) define hook-stop
Type commands for definition of "hook-stop".
End with a line saying just "end".
>    shell cmd /c echo "hello"
>end
(gdb) run
Starting program: a.exe
[New Thread 420.0x430]

Program received signal SIGSEGV, Segmentation fault.
"hello"
0x004013a6 in main ()
(gdb)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top