1

I want to use python to create some interactive script for gdb. It works well in gdb, but it doesn't work if I invoke gdb from emacs.

For example, the python script (test.py) is like below. It simply print what it gets.

def testInput():
    n = raw_input('(gdb) ')
    print n

It works in gdb:

% gdb
GNU gdb (GDB) 7.2.50.20110217
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) source test.py
(gdb) python testInput()
(gdb) 1
1
(gdb) q

But in emacs, it will just hang in "raw_input" and could never get the input:

(gdb) source test.py
(gdb) python testInput()
(gdb) 1
2
...

Is there anyway to make it work just as in gdb?

2 Answers 2

1

Invoking gdb with M-x gud-gdb solved the problem for me. For further details confer chapter 27 of the Emacs manual.

Hope this is still helpful after two years...

Sign up to request clarification or add additional context in comments.

Comments

0

When using an interactive external process in an emacs buffer, the mode needs to be able to recognize from the buffer when the external process is prompting the user for input so that it knows it need to allow the user to input something. Otherwise, emacs will just wait forever for the process to output something it recognizes and the process will be waiting forever for input. Since your python script uses a different prompt, the emacs gdb mode never recognizes that input is being solicited.

Try modifying the value of gdb-prompt-name-regexp. Here's the default value from gdb-mi.el:

(defvar gdb-prompt-name-regexp "value=\"\\(.*?\\)\"")

2 Comments

The problem is the prompt from your script, you need the regexp to match all things you need emacs to recognize as a prompt.
I change the script so it uses the same prompt as the original gdb's, but it still doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.