* GDB Python - gdb.execute() - with a timeout?
@ 2015-07-27 12:23 Duane Ellis
2015-07-28 10:09 ` Ofir Cohen
0 siblings, 1 reply; 3+ messages in thread
From: Duane Ellis @ 2015-07-27 12:23 UTC (permalink / raw)
To: gdb
Hi, am trying to script some times using GDB/Python specifically some test cases
The general format of my GDB_PY scripts are:
import gdb
gdb.execute(“load foobar”)
gdb.execute(“break test_breakpoint”)
gdb.execute(“run”)
gdb.execute(“set test_flag=0x1234”)
gdb.execute(“cont”) <— HERE Is where I want a timeout
# At this point, we should eventually hit the “test_breakpoint”
# However in some cases we do not.
the timeout needs to be ‘reasonably programable’ - i.e.: 1 second, 10 seconds, an hour would in some use cases be reasonable.
In other words, if my test case is running properly - I should hit the breakpoint.
I need a means to detect when things go wrong.
This problem is *NOT* limited to the TEST case
Is there some way to do this?
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GDB Python - gdb.execute() - with a timeout?
2015-07-27 12:23 GDB Python - gdb.execute() - with a timeout? Duane Ellis
@ 2015-07-28 10:09 ` Ofir Cohen
2015-07-28 12:14 ` Duane Ellis
0 siblings, 1 reply; 3+ messages in thread
From: Ofir Cohen @ 2015-07-28 10:09 UTC (permalink / raw)
To: Duane Ellis; +Cc: gdb
Hi,
This is achievable via pexpect wrapper.
You can take a look at this example:
http://opensource.apple.com/source/lldb/lldb-76/utils/test/disasm.py
The pexpect.spawn receives timeout as a parameter, so you could adapt it
to your needs.
I don't think this is achievable directly in gdb, i.e. w/o wrappers.
Most of the gdb code _once executed_ is synchronous and doesn't allow timeouts
or that sort of thing.
Correct me if I'm wrong.
- Ofir
On 27 July 2015 at 15:23, Duane Ellis <duane@duaneellis.com> wrote:
> Hi, am trying to script some times using GDB/Python specifically some test cases
>
> The general format of my GDB_PY scripts are:
>
> import gdb
> gdb.execute(“load foobar”)
>
> gdb.execute(“break test_breakpoint”)
>
> gdb.execute(“run”)
> gdb.execute(“set test_flag=0x1234”)
>
> gdb.execute(“cont”) <— HERE Is where I want a timeout
>
> # At this point, we should eventually hit the “test_breakpoint”
> # However in some cases we do not.
>
> the timeout needs to be ‘reasonably programable’ - i.e.: 1 second, 10 seconds, an hour would in some use cases be reasonable.
>
> In other words, if my test case is running properly - I should hit the breakpoint.
>
> I need a means to detect when things go wrong.
>
> This problem is *NOT* limited to the TEST case
>
> Is there some way to do this?
>
> Thanks.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GDB Python - gdb.execute() - with a timeout?
2015-07-28 10:09 ` Ofir Cohen
@ 2015-07-28 12:14 ` Duane Ellis
0 siblings, 0 replies; 3+ messages in thread
From: Duane Ellis @ 2015-07-28 12:14 UTC (permalink / raw)
To: Ofir Cohen, gdb
> This is achievable via pexpect wrapper.
Thanks for the example but that won’t work for my situation - solution needs to run from within a GUI that has already wrapped GDB/LLDB in some form (for example eclipse). The pexpect solution - is external and controls GDB, in my scenario something else is already controlling GDB (i.e.: Eclipse or Emacs-GUD mode)
I have an idea - but don’t know how to implement parts of it
After (X) timeout period I need to simulate pressing “control-C” via the gdb_python solution.
The idea is that Control_C at the GDB command console will cause GDB “cont” to stop - and send a “target halt” command and thus the gdb.excute(‘cont’) call will finish & return.
That would probably be sufficient for my purposes, the idea is sort of this:
Mainline thread:
Set global “timeout period”
FORK - creating new “timeout thread”
perform gdb.execute(“cont”)
*CANCEL* the timeout thread.
Meanwhile, timeout thread
sleeps for “timeout period”
After timeout period - ?? somehow ?? Simulate human pressing Control-C at the GDB console window
Some notes:
(A) I know that GDB is single threaded
(B) I know there is an ‘event queue’ or ‘work queue’
(C) As I understand Python threads must “post” an event to a GDB event/work queue
(D) Eventually when GDB is ‘safe’ that work item would be executed.
Assuming that work item is a call to a Python function, I don’t see how via Python the way to simulate “control-C” at the command console.
Am I missing something? Any suggestions?
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-28 12:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 12:23 GDB Python - gdb.execute() - with a timeout? Duane Ellis
2015-07-28 10:09 ` Ofir Cohen
2015-07-28 12:14 ` Duane Ellis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).