This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] Add example of a Python convenience function.
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: archer ml <archer at sourceware dot org>
- Date: Tue, 16 Dec 2008 13:33:31 -0200
- Subject: [python] Add example of a Python convenience function.
Hi,
I find that an example helps to clarify how the API is to be used. Also,
added a note about importing the gdb module in the gdb.Command example.
Committed.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
2008-12-16 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.texinfo (Commands in Python): Mention need of importing the gdb
Python module.
(Functions In Python): Add example.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d1f3c5e..060b67f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18956,7 +18956,10 @@ HelloWorld ()
@end smallexample
The last line instantiates the class, and is necessary to trigger the
-registration of the command with @value{GDBN}.
+registration of the command with @value{GDBN}. Depending on how the
+Python code is read into @value{GDBN}, you may need to import the
+@code{gdb} module explicitly.
+
@node Parameters In Python
@subsubsection Parameters In Python
@@ -19124,6 +19127,28 @@ expression. If an ordinary Python value is returned, it is converted
to a @code{gdb.Value} following the usual rules.
@end defmethod
+The following code snippet shows how a trivial convenience function can
+be implemented in Python:
+
+@smallexample
+class Greet (gdb.Function):
+ """Return string to greet someone.
+Takes a name as argument."""
+
+ def __init__ (self):
+ super (Greet, self).__init__ ("greet")
+
+ def invoke (self, name):
+ return "Hello, %s!" % name.string ()
+
+Greet ()
+@end smallexample
+
+The last line instantiates the class, and is necessary to trigger the
+registration of the function with @value{GDBN}. Depending on how the
+Python code is read into @value{GDBN}, you may need to import the
+@code{gdb} module explicitly.
+
@node Objfiles in Python
@subsubsection Objfiles in Python