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]

[RFC] A new command 'grep'


Hi all,

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. A simple example is as follows:

struct SimpleStruct
{
  int int_val;
  double double_val;
};

struct SimpleStruct ss;
ss.int_val = 10;
ss.double_val = 1.11;

Examples of grepping for fields:

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

(gdb) grep dou ss
ss.double_val = (double) 1.11

Examples of grepping for values:

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

(gdb) grep "1\\." ss
ss.double_val = (double) 1.11

In general, one can grep for any matching regular expression in any
valid expression. Few points to note:
1. To restrict searches to values or fields, one can use the sub
commands 'grep value' or 'grep field' respectively.
2. The value grep looks for matches in scalar and string values only.
3. The search goes as deep as the data structure of the expression
with one exception; It does not grep through union values unless it
finds a field selector for that union value. A field selector is a
user defined class with a specific interface which helps the grep
command select the appropriate field of the union to grep through. The
patch includes a field selector, which selects all fields, as an
example.

Thanks,
Siva Chandra

2012-01-02 Siva Chandra <sivachandra@google.com>

        New command 'grep' which helps to grep through field names and values
        of expressions in scope.
        * data-directory/Makefile.in: Add gdb/command/grep.py
        * python/lib/gdb/command/grep.py: Implemention of the 'grep'
        command using the GDB Python API.
        * testsuite/gdb.python/Makefile.in: Add py-grep to EXECUTABLES
        * testsuite/gdb.python/py-grep.c: C program used for testing
        the new 'grep' command.
        * testsuite/gdb-python/py-grep.exp: Tests for the new 'grep'
        command.

Attachment: grep_command_patch_v1.txt
Description: Text document


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