From: Taisuke Yamada <tai@rakugaki.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] sys.argv and ipython (interactive python) support in GDB/Python
Date: Fri, 01 Jul 2011 04:00:00 -0000 [thread overview]
Message-ID: <BANLkTi=36=aFZPsBDJacOWvh-2Pk7OHKfQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 793 bytes --]
Hi.
While working with GDB/Python, I wondered if I can use it
interactively by loading ipython (interactive python shell) on
top of it. However, current GDB/Python fails as it does not
initialize sys.argv properly.
So here is a patch to set sys.argv when initializing embedded
Python interpreter. I have tested it by running ipython with
(gdb) python execfile("/usr/bin/ipython")
Python 2.6.6 (r266:84292, Oct 9 2010, 12:40:51)
...
In [1]: import gdb
In [2]: print gdb.lookup_symbol("main")
(<gdb.Symbol object at 0x7ff6f9815b20>, False)
It is quite nice to be able to inspect debuggee interactively
using full-featured language.
This patch should also improve compatibility with other exsiting
python libraries, as some of those expect existance of sys.argv.
Best Regards,
[-- Attachment #2: gdb-python-ipython.patch --]
[-- Type: text/x-patch, Size: 434 bytes --]
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 90d5dc8..c9f2ce9 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1010,7 +1010,9 @@ Enables or disables printing of Python stack traces."),
SLASH_STRING, "python", NULL));
#endif
+ char *argv[] = { "gdb", NULL };
Py_Initialize ();
+ PySys_SetArgvEx (1, argv, 0);
PyEval_InitThreads ();
gdb_module = Py_InitModule ("gdb", GdbMethods);
next reply other threads:[~2011-07-01 4:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-01 4:00 Taisuke Yamada [this message]
[not found] ` <BANLkTimcWKLMOkd0R8bNT-z4yqr0FJ_uog@mail.gmail.com>
2011-07-01 10:31 ` Kevin Pouget
2011-07-01 10:59 ` Phil Muldoon
2011-07-01 14:10 ` Taisuke Yamada
2011-07-01 14:14 ` Phil Muldoon
2011-07-01 14:34 ` Tom Tromey
2011-07-01 14:27 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='BANLkTi=36=aFZPsBDJacOWvh-2Pk7OHKfQ@mail.gmail.com' \
--to=tai@rakugaki.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox