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'


Hello,

Thanks for taking a look. My comments inline.

Eli > I think this is the first time we receive a proposal for a command
Eli > implemented in Python. ?Perhaps there's a place to discuss whether
Eli > some policy is in order in this regard. ?E.g., the command will be
Eli > unavailable in non-Python builds, which at least needs to be
Eli > documented. ?There may be other aspects that are worth discussing.

This is not the first, I submitted RFC another command called
'explore' few weeks back implemented in Python :-)

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

I couldn't locate any GNU coding conventions for Python. Hence, I
tried to follow the convention I could reverse engineer from the other
Python files in python/lib/gdb/command directory.

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

I agree that if we can pass GDB output to shell, a lot of
functionality in this command is redundant. I was unaware of this
work. However, I have a part of this command extensible. When
'grepping' through unions, the user can define a field selector for
the union and the command will select only that field to grep through.
I have found this very useful in understanding GCC data structures.
Another point is that if we rely the shell grep and the GDB print
command, it cannot grep through pointer values.

Kevin > I didn't really look in depth at the sources, but based on you email
Kevin > description, I wonder how it differs from a generic code like that
Kevin > (not tested)
Kevin >
Kevin > (gdb) grep int ss
Kevin > ss.int_val = (int) 10
Kevin >
Kevin > #assume set print pretty on
Kevin >
Kevin > command = "print %s" % ss
Kevin > to_grep = "int"
Kevin >
Kevin > out = gdb.execute (command, to_string=True)
Kevin > for line in out.split("\n")
Kevin > ?if to_grep in line:
Kevin > ? ?print line

This does most of the job again but for the two points I mentioned
above. And again, I didn't think of this approach before. It seems to
me that we can either have this command I submitted in Python, or
extend the existing commands to support user defined plugins. I am a
newcomer to GDB code and its development: I am probably not thinking
very correctly.

About the name of the command itself, I am OK with 'lookup' instead of
'grep'. I favor 'grep' over 'lookup' because 'lookup' kind of implies
(probably just in my mind) to return a boolean value.

Thanks,
Siva Chandra


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