This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] A new command 'grep'


On Mon, Jan 2, 2012 at 9:54 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
> I think this is the first time we receive a proposal for a command
> implemented in Python.  Perhaps there's a place to discuss whether
> some policy is in order in this regard.  E.g., the command will be
> unavailable in non-Python builds, which at least needs to be
> documented.  There may be other aspects that are worth discussing.

I'm also curious about that, and maybe first of all, is there a Python
specific coding convention likely to be enforced in GNU projects
and/or GDB?

>> Date: Mon, 2 Jan 2012 10:30:55 +0530
>> From: Siva Chandra <sivachandra@google.com>
>>
>> Attached is a patch which implements a 'grep' command using the GDB
>> Python API. The idea behind the 'grep' command is as follows. We often
>> have deep data structures and are probably interested in some one
>> particular field or value embedded somewhere deep in that data
>> structure. For such cases, instead of typing the complete expression
>> for the field, we can use the 'grep' command to lookup the field or
>> value of interest.
>
> Thanks.
>
> I think this is the first time we receive a proposal for a command
> implemented in Python. ?Perhaps there's a place to discuss whether
> some policy is in order in this regard. ?E.g., the command will be
> unavailable in non-Python builds, which at least needs to be
> documented. ?There may be other aspects that are worth discussing.
>
> If this is accepted, it will need user-level documentation.
>
> I cannot say I like the name "grep". ?Users will associate that name
> with the Unix command that searches through files, which is radically
> different from what your command does. ?How about "lookup-fields"
> instead?

There was a discussion a few months ago about "Implementation of pipe
to pass GDB's command output to the shell" [1] which would allow to
use the 'real' grep to do a similar job, but I'm not sure about the
status of this patch, it seems not to be in the trunk yet, according
to the ChangeLog.

I didn't really look in depth at the sources, but based on you email
description, I wonder how it differs from a generic code like that
(not tested):

> (gdb) grep int ss
> ss.int_val = (int) 10

#assume set print pretty on

command = "print %s" % ss
to_grep = "int"

out = gdb.execute (command, to_string=True)
for line in out.split("\n")
  if to_grep in line:
    print line


good idea anyway,
thanks,

Kevin

[1]: http://sourceware.org/ml/gdb-patches/2011-08/msg00483.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]