This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

[python] Make gdb.search_memory accept keyword arguments.


Hi,

For functions which take more than one optional argument, I enabled
keyword syntax which provides a way to specify some optional arguments
while skipping others. For instance, you can say:

gdb.some_function ('foo', bar = 1, baz = 2)

This and the next three patches deal with this.
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


gdb/
	* python/python.c (gdbpy_search_memory): Accept keyword
	arguments as well.
	(GdbMethods): Change `search_memory' entry to also accept
	keyword arguments.

gdb/testsuite/
	* gdb.python/find.exp: Add tests for keyword arguments.
---
 gdb/python/python.c               |   16 +++++++++-------
 gdb/testsuite/gdb.python/find.exp |   16 ++++++++++++++--
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 4d104c2..d32a9e5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -471,14 +471,13 @@ get_search_pattern (PyObject *obj, int size, char **pattern_bufp,
 }
 
 /* Implementation of
-   gdb.search_memory (start_address, length, pattern|list
-		      [, size] [, max_count]).
+   gdb.search_memory (address, length, pattern [, size] [, max_count]).
    The third argument may be either a pattern, or a list or tupple of patterns
    to be searched.  Size is the size in bytes of each search query value, either
    1, 2, 4 or 8.  Returns a list of the addresses where matches were found.  */
 
 PyObject *
-gdbpy_search_memory (PyObject *self, PyObject *args)
+gdbpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 {
   int size = 0;
   long length;
@@ -486,13 +485,16 @@ gdbpy_search_memory (PyObject *self, PyObject *args)
   long max_count = 0;
   CORE_ADDR start_addr;
   char *pattern_buf;
+  static char *keywords[] = { "address", "length", "pattern", "size",
+			      "max_count", NULL };
   ULONGEST pattern_len, search_space_len;
   PyObject *pattern, *list = NULL, *start_addr_obj;
   volatile struct gdb_exception except;
 
   /* Assume CORE_ADDR corresponds to unsigned long.  */
-  if (! PyArg_ParseTuple (args, "OlO|il", &start_addr_obj, &length, &pattern,
-			  &size, &max_count))
+  if (! PyArg_ParseTupleAndKeywords (args, kw, "OlO|il", keywords,
+				     &start_addr_obj, &length, &pattern,
+				     &size, &max_count))
     return NULL;
 
   if (!max_count)
@@ -1892,8 +1894,8 @@ Return a buffer object for reading from the inferior's memory." },
   { "write_memory", gdbpy_write_memory, METH_VARARGS,
     "write_memory (address, buffer [, length])\n\
 Write the given buffer object to the inferior's memory." },
-  { "search_memory", gdbpy_search_memory, METH_VARARGS,
-    "search_memory (start_address, length, pattern|list [, size] [, max_count]) -> list\n\
+  { "search_memory", (PyCFunction) gdbpy_search_memory, METH_VARARGS | METH_KEYWORDS,
+    "search_memory (address, length, pattern [, size] [, max_count]) -> list\n\
 Return a list with the addresses where matches were found." },
 
   { "write", gdbpy_write, METH_VARARGS,
diff --git a/gdb/testsuite/gdb.python/find.exp b/gdb/testsuite/gdb.python/find.exp
index 30afe41..d563974 100644
--- a/gdb/testsuite/gdb.python/find.exp
+++ b/gdb/testsuite/gdb.python/find.exp
@@ -107,10 +107,22 @@ gdb_test "py print gdb.search_memory (start_addr, 10+3, 'aaaa')" \
 gdb_test "py print gdb.search_memory (start_addr, 10+3+1, \['a', 'a', 'a', 'a'\])" \
   "${one_pattern_found}" "pattern found at end of range"
 
-# Test max-count with size-char.
+# Test max-count with size, with different parameter position
 
 gdb_test "py print gdb.search_memory (start_addr, length, \[0x61, 0x61\], 1, 1)" \
-  "\[\\r\\n\].${dec_number}L]" "size = 1, max_count = 1"
+  "${one_pattern_found}" "size = 1, max_count = 1"
+
+gdb_test "py print gdb.search_memory (start_addr, length, \[0x61, 0x61\], 1, 2)" \
+  "${two_patterns_found}" "size = 1, max_count = 2, normal ordering"
+
+gdb_test "py print gdb.search_memory (start_addr, length, \[0x61, 0x61\], size = 1, max_count = 2)" \
+  "${two_patterns_found}" "size = 1, max_count = 2, normal ordering, with keywords"
+
+gdb_test "py print gdb.search_memory (start_addr, length, \[0x61, 0x61\], max_count = 2, size = 1)" \
+  "${two_patterns_found}" "size = 1, max_count = 2, inverted ordering"
+
+gdb_test "py print gdb.search_memory (start_addr, length, \['a', 'a'\], max_count = 2)" \
+  "${two_patterns_found}" "max_count = 2, with keyword"
 
 # Test 16-bit pattern.
 
-- 
1.5.6.5



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