public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Add solib_address and decode_line Python functionality
@ 2010-07-19 15:43 Phil Muldoon
  2010-07-27 16:26 ` Joel Brobecker
  2010-08-18 23:55 ` Pedro Alves
  0 siblings, 2 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-07-19 15:43 UTC (permalink / raw)
  To: gdb-patches ml

This patch imports the (last) two utility functions from archer (the
other missing section from archer is the event posting code, but that
is another email ...)

These are general purpose utilities to make script hackers life a
little easier.  

solib_address -- lookup an address and if it resides in an solib
reports that libs name, or None.

decode_line -- provide decode_line_1 like functionality.  Useful for
Python commands

Tested on x8664 with no regressions.

Comments?

Cheers,

Phil

ChangeLog:

2010-07-19  Phil Muldoon  <pmuldoon@redhat.com>
            Thiago Jung Bauermann  <bauerman@br.ibm.com>
	    Tom Tromey  <tromey@redhat.com>

	* python/python.c (gdbpy_solib_address):  New function.
	(gdbpy_decode_line): Likewise.

Documentation ChangeLog:

2010-07-19  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.texinfo (Basic Python): Describe solib_address and
          decode_line Python APIs

Testsuite ChangeLog:

2010-07-19  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/python.c: New File.
	* gdb.python/python-sl.c: New File.
	* gdb.python/python.exp: Test solib_address and decode_line
	* functions.

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ba5ab75..b75dc23 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20532,6 +20532,35 @@ Return the name of the current target wide character set
 never returned.
 @end defun
 
+@findex gdb.solib_address
+@defun solib_address address
+Return the name of the shared library holding the given @var{address}
+as a string, or @code{None}.
+@end defun
+
+@findex gdb.decode_line
+@defun decode_line @r{[}expression@r{]}
+Decode the optional argument @var{expression} the way that
+@value{GDBN}'s inbuilt 'break' or 'edit' commands do.  Return a Python
+tuple holding all the locations that match the expression represented
+as @code{gdb.Symtab_and_line} objects, or @code{None}.  If
+@var{expression} is not provided, the current location is returned.
+This function is useful for decoding line, file and function arguments
+for Python commands (@pxref{Commands In Python}).  The expected
+format of @var{expression} is:
+
+@table @code
+@item FILE:LINENUM
+A location indicated at that line in that file.
+@item FUNCTION
+A location at the beginning of that function.
+@item FILE:FUNCTION
+A location to distinguish among like-named static functions.
+@item ADDRESS
+A location containing that address.
+@item VARIABLE
+A location containing that variable.
+@end table
+@end defun
+
 @node Exception Handling
 @subsubsection Exception Handling
 @cindex python exceptions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6680126..8a9a374 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -42,7 +42,10 @@ static int gdbpy_should_print_stack = 1;
 #include "cli/cli-decode.h"
 #include "charset.h"
 #include "top.h"
+#include "solib.h"
 #include "python-internal.h"
+#include "linespec.h"
+#include "source.h"
 #include "version.h"
 #include "target.h"
 #include "gdbthread.h"
@@ -413,6 +416,105 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   Py_RETURN_NONE;
 }
 
+/* Implementation of gdb.solib_address (Long) -> String.
+   Returns the name of the shared library holding a given address, or None.  */
+
+static PyObject *
+gdbpy_solib_address (PyObject *self, PyObject *args)
+{
+  unsigned long long pc;
+  char *soname;
+  PyObject *str_obj;
+
+  if (!PyArg_ParseTuple (args, "K", &pc))
+    return NULL;
+
+  soname = solib_name_from_address (current_program_space, pc);
+  if (soname)
+    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
+  else
+    {
+      str_obj = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return str_obj;
+}
+
+/* A Python function which is a wrapper for decode_line_1.  */
+
+static PyObject *
+gdbpy_decode_line (PyObject *self, PyObject *args)
+{
+  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
+  struct symtab_and_line sal;
+  char *arg = NULL;
+  int free_sals = 0, i;
+  PyObject *result = NULL;
+  volatile struct gdb_exception except;
+
+  if (! PyArg_ParseTuple (args, "|s", &arg))
+    return NULL;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      if (arg)
+	{
+	  char *copy;
+
+	  arg = strdup (arg);
+	  copy = arg;
+
+	  sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
+	  free_sals = 1;
+	}
+      else
+	{
+	  set_default_source_symtab_and_line ();
+	  sal = get_current_source_symtab_and_line ();
+	  sals.sals = &sal;
+	  sals.nelts = 1;
+	}
+    }
+  if (arg)
+    xfree (arg);
+
+  if (except.reason < 0)
+    {
+      if (free_sals)
+	xfree (sals.sals);
+      /* We know this will always throw.  */
+      GDB_PY_HANDLE_EXCEPTION (except);
+    }
+
+  if (sals.nelts)
+    {
+      result = PyTuple_New (sals.nelts);
+      for (i = 0; i < sals.nelts; ++i)
+	{
+	  PyObject *obj;
+	  char *str;
+
+	  obj = symtab_and_line_to_sal_object (sals.sals[i]);
+	  if (! obj)
+	    {
+	      Py_DECREF (result);
+	      result = NULL;
+	      break;
+	    }
+
+	  PyTuple_SetItem (result, i, obj);
+	}
+    }
+
+  if (free_sals)
+    xfree (sals.sals);
+
+  if (result)
+    return result;
+  Py_RETURN_NONE;
+}
+
 /* Parse a string and evaluate it as an expression.  */
 static PyObject *
 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
@@ -864,6 +966,14 @@ a boolean indicating if name is a field of the current implied argument\n\
 `this' (when the current language is object-oriented)." },
   { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
     "Return the block containing the given pc value, or None." },
+  { "solib_address", gdbpy_solib_address, METH_VARARGS,
+    "solib_address (Long) -> String.\n\
+Return the name of the shared library holding a given address, or None." },
+  { "decode_line", gdbpy_decode_line, METH_VARARGS,
+    "decode_line (String) -> Tuple.  Decode a string argument the way\n\
+that 'break' or 'edit' does.  Return a tuple holding all the\n \
+locations that match, represented as gdb.Symtab_and_line objects\n\
+(or None)."},
   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
     "parse_and_eval (String) -> Value.\n\
 Parse String as an expression, evaluate it, and return the result as a Value."
diff --git a/gdb/testsuite/gdb.python/python-sl.c b/gdb/testsuite/gdb.python/python-sl.c
new file mode 100644
index 0000000..579a74e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-sl.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c
new file mode 100644
index 0000000..750a90a
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library function */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index d0e6c63..0d7b4bf 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -20,12 +20,44 @@ if $tracelevel then {
     strace $tracelevel
 }
 
-# Start with a fresh gdb.
+set testfile "python"
+set srcfile  ${testfile}.c
+set libfile  "python-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
 
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
+
+# Start with a fresh gdb.
 gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+  gdb_test_multiple $cmd $name {
+      -re "Traceback.*$gdb_prompt $"  { fail $name }
+      -re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+  }
+}
+
 gdb_test_multiple "python print 23" "verify python support" {
     -re "not supported.*$gdb_prompt $"	{
       unsupported "python support is disabled"
@@ -87,3 +119,46 @@ gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/li
 gdb_test_no_output \
     "python x = gdb.execute('printf \"%d\", 23', to_string = True)"
 gdb_test "python print x" "23"
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.decode_line.
+gdb_test "python gdb.decode_line(\"main.c:43\")" \
+    "RuntimeError: No source file named main.c.*" "test decode_line no source named main"
+
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line current location"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
+gdb_test "python print symtab\[0\].line" "22" "Test decode_line current location line number"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26\")" "test decode_line python.c:26" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
+gdb_test "python print symtab\[0\].line" "26" "Test decode_line python.c:26 line number"
+
+gdb_test "python gdb.decode_line(\"randomfunc\")" \
+    "RuntimeError: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line func1 length"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[0\].line" "19" "Test decode_line func1 line number"
+
+# Test gdb.solib_address
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_address(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_address(long(main))" "None" "test main solib location"


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-19 15:43 [patch] Add solib_address and decode_line Python functionality Phil Muldoon
@ 2010-07-27 16:26 ` Joel Brobecker
  2010-07-28 11:35   ` Phil Muldoon
  2010-08-18 23:55 ` Pedro Alves
  1 sibling, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-07-27 16:26 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches ml

Just my 2 cents on the API and doc...

> solib_address -- lookup an address and if it resides in an solib
> reports that libs name, or None.

IMO, the name that was chosen for this function implies the opposite
of what it does (it implies that it returns the solib (base?) address).
I would personally prefer solib_name or solib_name_from_address.

> +for Python commands (@pxref{Commands In Python}).  The expected
> +format of @var{expression} is:
> +
> +@table @code
> +@item FILE:LINENUM
> +A location indicated at that line in that file.
> +@item FUNCTION
> +A location at the beginning of that function.
> +@item FILE:FUNCTION
> +A location to distinguish among like-named static functions.
> +@item ADDRESS
> +A location containing that address.
> +@item VARIABLE
> +A location containing that variable.
> +@end table
> +@end defun

ISTM that we would be better off not duplicating the various forms
a linespec can take. How about using a cross reference?

-- 
Joel

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-27 16:26 ` Joel Brobecker
@ 2010-07-28 11:35   ` Phil Muldoon
  2010-07-28 17:39     ` Joel Brobecker
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-07-28 11:35 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches ml

On 27/07/10 17:25, Joel Brobecker wrote:
> Just my 2 cents on the API and doc...
> 
>> solib_address -- lookup an address and if it resides in an solib
>> reports that libs name, or None.
> 
> IMO, the name that was chosen for this function implies the opposite
> of what it does (it implies that it returns the solib (base?) address).
> I would personally prefer solib_name or solib_name_from_address.

Yeah, I agree (looking at it now).  Attached a patch with the new name.


>> +for Python commands (@pxref{Commands In Python}).  The expected
>> +format of @var{expression} is:
> 
> ISTM that we would be better off not duplicating the various forms
> a linespec can take. How about using a cross reference?

Thanks, I added a cross reference to the documentation (As well as a
few other edits, including a missing cross reference to
gdb.Symtab_and_line).

What do you think?

Cheers,

Phil

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ba5ab75..404d372 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20532,6 +20532,22 @@ Return the name of the current target wide character set
 never returned.
 @end defun
 
+@findex gdb.solib_name
+@defun solib_name address
+Return the name of the shared library holding the given @var{address}
+as a string, or @code{None}.
+@end defun
+
+@findex gdb.decode_line
+@defun decode_line @r{[}expression@r{]}
+Decode the optional argument @var{expression} the way that
+@value{GDBN}'s inbuilt 'break' or 'edit' commands do (@pxref{Specify
+Location}).  Return a Python tuple holding all the locations that
+match the expression represented as @code{gdb.Symtab_and_line} objects
+(@pxref{Symbol Tables In Python}), or @code{None}.  If
+@var{expression} is not provided, the current location is returned.
+@end defun
+
 @node Exception Handling
 @subsubsection Exception Handling
 @cindex python exceptions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6680126..79179e3 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -42,7 +42,10 @@ static int gdbpy_should_print_stack = 1;
 #include "cli/cli-decode.h"
 #include "charset.h"
 #include "top.h"
+#include "solib.h"
 #include "python-internal.h"
+#include "linespec.h"
+#include "source.h"
 #include "version.h"
 #include "target.h"
 #include "gdbthread.h"
@@ -413,6 +416,105 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   Py_RETURN_NONE;
 }
 
+/* Implementation of gdb.solib_name (Long) -> String.
+   Returns the name of the shared library holding a given address, or None.  */
+
+static PyObject *
+gdbpy_solib_name (PyObject *self, PyObject *args)
+{
+  unsigned long long pc;
+  char *soname;
+  PyObject *str_obj;
+
+  if (!PyArg_ParseTuple (args, "K", &pc))
+    return NULL;
+
+  soname = solib_name_from_address (current_program_space, pc);
+  if (soname)
+    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
+  else
+    {
+      str_obj = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return str_obj;
+}
+
+/* A Python function which is a wrapper for decode_line_1.  */
+
+static PyObject *
+gdbpy_decode_line (PyObject *self, PyObject *args)
+{
+  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
+  struct symtab_and_line sal;
+  char *arg = NULL;
+  int free_sals = 0, i;
+  PyObject *result = NULL;
+  volatile struct gdb_exception except;
+
+  if (! PyArg_ParseTuple (args, "|s", &arg))
+    return NULL;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      if (arg)
+	{
+	  char *copy;
+
+	  arg = strdup (arg);
+	  copy = arg;
+
+	  sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
+	  free_sals = 1;
+	}
+      else
+	{
+	  set_default_source_symtab_and_line ();
+	  sal = get_current_source_symtab_and_line ();
+	  sals.sals = &sal;
+	  sals.nelts = 1;
+	}
+    }
+  if (arg)
+    xfree (arg);
+
+  if (except.reason < 0)
+    {
+      if (free_sals)
+	xfree (sals.sals);
+      /* We know this will always throw.  */
+      GDB_PY_HANDLE_EXCEPTION (except);
+    }
+
+  if (sals.nelts)
+    {
+      result = PyTuple_New (sals.nelts);
+      for (i = 0; i < sals.nelts; ++i)
+	{
+	  PyObject *obj;
+	  char *str;
+
+	  obj = symtab_and_line_to_sal_object (sals.sals[i]);
+	  if (! obj)
+	    {
+	      Py_DECREF (result);
+	      result = NULL;
+	      break;
+	    }
+
+	  PyTuple_SetItem (result, i, obj);
+	}
+    }
+
+  if (free_sals)
+    xfree (sals.sals);
+
+  if (result)
+    return result;
+  Py_RETURN_NONE;
+}
+
 /* Parse a string and evaluate it as an expression.  */
 static PyObject *
 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
@@ -864,6 +966,14 @@ a boolean indicating if name is a field of the current implied argument\n\
 `this' (when the current language is object-oriented)." },
   { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
     "Return the block containing the given pc value, or None." },
+  { "solib_name", gdbpy_solib_name, METH_VARARGS,
+    "solib_name (Long) -> String.\n\
+Return the name of the shared library holding a given address, or None." },
+  { "decode_line", gdbpy_decode_line, METH_VARARGS,
+    "decode_line (String) -> Tuple.  Decode a string argument the way\n\
+that 'break' or 'edit' does.  Return a tuple holding all the\n \
+locations that match, represented as gdb.Symtab_and_line objects\n\
+(or None)."},
   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
     "parse_and_eval (String) -> Value.\n\
 Parse String as an expression, evaluate it, and return the result as a Value."
diff --git a/gdb/testsuite/gdb.python/python-sl.c b/gdb/testsuite/gdb.python/python-sl.c
new file mode 100644
index 0000000..579a74e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-sl.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c
new file mode 100644
index 0000000..750a90a
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library function */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index d0e6c63..e1187bf 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -20,12 +20,44 @@ if $tracelevel then {
     strace $tracelevel
 }
 
-# Start with a fresh gdb.
+set testfile "python"
+set srcfile  ${testfile}.c
+set libfile  "python-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
 
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
+
+# Start with a fresh gdb.
 gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+  gdb_test_multiple $cmd $name {
+      -re "Traceback.*$gdb_prompt $"  { fail $name }
+      -re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+  }
+}
+
 gdb_test_multiple "python print 23" "verify python support" {
     -re "not supported.*$gdb_prompt $"	{
       unsupported "python support is disabled"
@@ -87,3 +119,46 @@ gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/li
 gdb_test_no_output \
     "python x = gdb.execute('printf \"%d\", 23', to_string = True)"
 gdb_test "python print x" "23"
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.decode_line.
+gdb_test "python gdb.decode_line(\"main.c:43\")" \
+    "RuntimeError: No source file named main.c.*" "test decode_line no source named main"
+
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line current location"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
+gdb_test "python print symtab\[0\].line" "22" "Test decode_line current location line number"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26\")" "test decode_line python.c:26" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
+gdb_test "python print symtab\[0\].line" "26" "Test decode_line python.c:26 line number"
+
+gdb_test "python gdb.decode_line(\"randomfunc\")" \
+    "RuntimeError: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
+gdb_test "python print len(symtab)" "1*" "Test decode_line func1 length"
+gdb_test "python print symtab\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[0\].line" "19" "Test decode_line func1 line number"
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-28 11:35   ` Phil Muldoon
@ 2010-07-28 17:39     ` Joel Brobecker
  2010-07-28 17:48     ` Eli Zaretskii
  2010-07-29 20:39     ` Tom Tromey
  2 siblings, 0 replies; 20+ messages in thread
From: Joel Brobecker @ 2010-07-28 17:39 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches ml

> What do you think?

Looks very good to me :).  But I did not review the code itself, because
of lack of familiarity with the Python part.  I can take a look, if
it helps, but this will have to wait until I get back to a normal
schedule, which might not be until the end of Aug :-(.

-- 
Joel

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-28 11:35   ` Phil Muldoon
  2010-07-28 17:39     ` Joel Brobecker
@ 2010-07-28 17:48     ` Eli Zaretskii
  2010-07-29 20:39     ` Tom Tromey
  2 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-07-28 17:48 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: brobecker, gdb-patches

> Date: Wed, 28 Jul 2010 12:34:58 +0100
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: gdb-patches ml <gdb-patches@sourceware.org>
> 
> +Decode the optional argument @var{expression} the way that
> +@value{GDBN}'s inbuilt 'break' or 'edit' commands do (@pxref{Specify
> +Location}).            ^^^^^^^    ^^^^^^

The command names should be in @code and without the quotes, as in
@code{break}.

The doco patch is okay with that change.  Thanks.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-28 11:35   ` Phil Muldoon
  2010-07-28 17:39     ` Joel Brobecker
  2010-07-28 17:48     ` Eli Zaretskii
@ 2010-07-29 20:39     ` Tom Tromey
  2010-08-06 13:55       ` Phil Muldoon
  2 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-07-29 20:39 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Joel Brobecker, gdb-patches ml

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> +static PyObject *
Phil> +gdbpy_solib_name (PyObject *self, PyObject *args)
Phil> +{
Phil> +  unsigned long long pc;

I don't think it is ok to use 'long long'.
Maybe you can use `unsigned PY_LONG_LONG', but see the Python API
manual; it seems that is not always available.  If it is not available
then I think this function could probably revert to 'unsigned long' and
the 'k' format.

Phil> +  TRY_CATCH (except, RETURN_MASK_ALL)
Phil> +    {
Phil> +      if (arg)
Phil> +	{
Phil> +	  char *copy;
Phil> +
Phil> +	  arg = strdup (arg);

Needs xstrdup and a cleanup.

I think we may want this function to also return the unparsed part of
the argument string.  For example we could return a tuple whose first
element is a string and whose second element is the return value as in
this patch.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-29 20:39     ` Tom Tromey
@ 2010-08-06 13:55       ` Phil Muldoon
  2010-08-06 15:36         ` Eli Zaretskii
  2010-08-06 22:39         ` Tom Tromey
  0 siblings, 2 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-08-06 13:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Joel Brobecker, gdb-patches ml

On 29/07/10 21:38, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
> Phil> +static PyObject *
> Phil> +gdbpy_solib_name (PyObject *self, PyObject *args)
> Phil> +{
> Phil> +  unsigned long long pc;
> 
> I don't think it is ok to use 'long long'.
> Maybe you can use `unsigned PY_LONG_LONG', but see the Python API
> manual; it seems that is not always available.  If it is not available
> then I think this function could probably revert to 'unsigned long' and
> the 'k' format.

I looked at the documentation and PY_LONG_LONG is only available on
some platforms (namely, 64 bit platforms).  I used unsigned long, and
'k' instead.


> 
> Phil> +  TRY_CATCH (except, RETURN_MASK_ALL)
> Phil> +    {
> Phil> +      if (arg)
> Phil> +	{
> Phil> +	  char *copy;
> Phil> +
> Phil> +	  arg = strdup (arg);
> 
> Needs xstrdup and a cleanup.
> 
> I think we may want this function to also return the unparsed part of
> the argument string.  For example we could return a tuple whose first
> element is a string and whose second element is the return value as in
> this patch.

I've modified this function to return the tuple as you requested, and
updated the documentation and testsuite accordingly.

What do you think?

Cheers,

Phil

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 03b59a3..fbe1d47 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20562,6 +20562,26 @@ Return the name of the current target wide character set
 never returned.
 @end defun
 
+@findex gdb.solib_name
+@defun solib_name address
+Return the name of the shared library holding the given @var{address}
+as a string, or @code{None}.
+@end defun
+
+@findex gdb.decode_line
+@defun decode_line @r{[}expression@r{]}
+Decode the optional argument @var{expression} the way that
+@value{GDBN}'s inbuilt @code{break} or @code{edit} commands do
+(@pxref{Specify Location}).  This function returns a Python tuple
+containing two elements.  The first element contains a string holding
+any unparsed section of @var{expression} (or @code{None} if the
+expression has been fully parsed).  The second element contains either
+@code{None} or another tuple that contains all the locations that
+match the expression represented as @code{gdb.Symtab_and_line} objects
+(@pxref{Symbol Tables In Python}).  If @var{expression} is not
+provided, the current location is returned.
+@end defun
+
 @node Exception Handling
 @subsubsection Exception Handling
 @cindex python exceptions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6680126..d4f782d 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -42,7 +42,10 @@ static int gdbpy_should_print_stack = 1;
 #include "cli/cli-decode.h"
 #include "charset.h"
 #include "top.h"
+#include "solib.h"
 #include "python-internal.h"
+#include "linespec.h"
+#include "source.h"
 #include "version.h"
 #include "target.h"
 #include "gdbthread.h"
@@ -413,6 +416,131 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   Py_RETURN_NONE;
 }
 
+/* Implementation of gdb.solib_name (Long) -> String.
+   Returns the name of the shared library holding a given address, or None.  */
+
+static PyObject *
+gdbpy_solib_name (PyObject *self, PyObject *args)
+{
+  unsigned long pc;
+  char *soname;
+  PyObject *str_obj;
+
+  if (!PyArg_ParseTuple (args, "k", &pc))
+    return NULL;
+
+  soname = solib_name_from_address (current_program_space, pc);
+  if (soname)
+    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
+  else
+    {
+      str_obj = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return str_obj;
+}
+
+/* A Python function which is a wrapper for decode_line_1.  */
+
+static PyObject *
+gdbpy_decode_line (PyObject *self, PyObject *args)
+{
+  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
+  struct symtab_and_line sal;
+  char *arg = NULL;
+  char *copy = NULL;
+  struct cleanup *cleanups;
+  PyObject *result = NULL;
+  PyObject *return_result = NULL;
+  PyObject *unparsed = NULL;
+  volatile struct gdb_exception except;
+
+  if (! PyArg_ParseTuple (args, "|s", &arg))
+    return NULL;
+
+  cleanups = ensure_python_env (get_current_arch (), current_language);
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      if (arg)
+	{
+	  arg = xstrdup (arg);
+	  make_cleanup (xfree, arg);
+	  copy = arg;
+	  sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
+	  make_cleanup (xfree, sals.sals);
+	}
+      else
+	{
+	  set_default_source_symtab_and_line ();
+	  sal = get_current_source_symtab_and_line ();
+	  sals.sals = &sal;
+	  sals.nelts = 1;
+	}
+    }
+  if (except.reason < 0)
+    {
+      do_cleanups (cleanups);
+      /* We know this will always throw.  */
+      GDB_PY_HANDLE_EXCEPTION (except);
+    }
+
+  if (sals.nelts)
+    {
+      int i;
+
+      result = PyTuple_New (sals.nelts);
+      if (! result)
+	goto error;
+      for (i = 0; i < sals.nelts; ++i)
+	{
+	  PyObject *obj;
+	  char *str;
+
+	  obj = symtab_and_line_to_sal_object (sals.sals[i]);
+	  if (! obj)
+	    {
+	      Py_DECREF (result);
+	      goto error;
+	    }
+
+	  PyTuple_SetItem (result, i, obj);
+	}
+    }
+  else
+    {
+      result = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return_result = PyTuple_New (2);
+  if (! return_result)
+    {
+      Py_DECREF (result);
+      goto error;
+    }
+
+  if (copy && strlen (copy) > 0)
+    unparsed = PyString_FromString (copy);
+  else
+    {
+      unparsed = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  PyTuple_SetItem (return_result, 0, unparsed);
+  PyTuple_SetItem (return_result, 1, result);
+
+  do_cleanups (cleanups);
+
+  return return_result;
+
+ error:
+  do_cleanups (cleanups);
+  return NULL;
+}
+
 /* Parse a string and evaluate it as an expression.  */
 static PyObject *
 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
@@ -864,6 +992,16 @@ a boolean indicating if name is a field of the current implied argument\n\
 `this' (when the current language is object-oriented)." },
   { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
     "Return the block containing the given pc value, or None." },
+  { "solib_name", gdbpy_solib_name, METH_VARARGS,
+    "solib_name (Long) -> String.\n\
+Return the name of the shared library holding a given address, or None." },
+  { "decode_line", gdbpy_decode_line, METH_VARARGS,
+    "decode_line (String) -> Tuple.  Decode a string argument the way\n\
+that 'break' or 'edit' does.  Return a tuple containing two elements.\n\
+The first element contains any unparsed portion of the String parameter\n\
+(or None if the string was fully parsed).  The second element contains\n\
+a tuple that contains all the locations that match, represented as\n\
+gdb.Symtab_and_line objects (or None)."},
   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
     "parse_and_eval (String) -> Value.\n\
 Parse String as an expression, evaluate it, and return the result as a Value."
diff --git a/gdb/testsuite/gdb.python/python-sl.c b/gdb/testsuite/gdb.python/python-sl.c
new file mode 100644
index 0000000..579a74e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-sl.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c
new file mode 100644
index 0000000..750a90a
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library function */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index d0e6c63..9c5bb6e 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -20,12 +20,44 @@ if $tracelevel then {
     strace $tracelevel
 }
 
-# Start with a fresh gdb.
+set testfile "python"
+set srcfile  ${testfile}.c
+set libfile  "python-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
 
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
+
+# Start with a fresh gdb.
 gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+  gdb_test_multiple $cmd $name {
+      -re "Traceback.*$gdb_prompt $"  { fail $name }
+      -re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+  }
+}
+
 gdb_test_multiple "python print 23" "verify python support" {
     -re "not supported.*$gdb_prompt $"	{
       unsupported "python support is disabled"
@@ -87,3 +119,50 @@ gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/li
 gdb_test_no_output \
     "python x = gdb.execute('printf \"%d\", 23', to_string = True)"
 gdb_test "python print x" "23"
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.decode_line.
+gdb_test "python gdb.decode_line(\"main.c:43\")" \
+    "RuntimeError: No source file named main.c.*" "test decode_line no source named main"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line current location"
+gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
+gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number"
+
+gdb_test "python gdb.decode_line(\"randomfunc\")" \
+    "RuntimeError: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-06 13:55       ` Phil Muldoon
@ 2010-08-06 15:36         ` Eli Zaretskii
  2010-08-06 22:39         ` Tom Tromey
  1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-08-06 15:36 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: tromey, brobecker, gdb-patches

> Date: Fri, 06 Aug 2010 14:54:32 +0100
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: Joel Brobecker <brobecker@adacore.com>,        gdb-patches ml <gdb-patches@sourceware.org>
> 
> +@findex gdb.decode_line
> +@defun decode_line @r{[}expression@r{]}
> +Decode the optional argument @var{expression} the way that
> +@value{GDBN}'s inbuilt @code{break} or @code{edit} commands do
> +(@pxref{Specify Location}).  This function returns a Python tuple
> +containing two elements.  The first element contains a string holding
> +any unparsed section of @var{expression} (or @code{None} if the
> +expression has been fully parsed).  The second element contains either
> +@code{None} or another tuple that contains all the locations that
> +match the expression represented as @code{gdb.Symtab_and_line} objects
> +(@pxref{Symbol Tables In Python}).  If @var{expression} is not
> +provided, the current location is returned.

This is okay, but I would suggest to explain what happens without the
argument first.  Readers shouldn't need to read all the description of
how the argument is parsed if they don't want to pass it.

Something like

  @findex gdb.decode_line
  @defun decode_line @r{[}expression@r{]}
  Return location of the line specified by @var{expression}, or of the
  current line if no argument was given.  This function returns a Python
  tuple containing two elements.  The first element contains a string
  holding any unparsed section of @var{expression} (or @code{None} if
  the expression has been fully parsed).  The second element contains
  either @code{None} or another tuple that contains all the locations
  that match the expression represented as @code{gdb.Symtab_and_line}
  objects (@pxref{Symbol Tables In Python}).  If @var{expression}
  provided, it is decoded the way that @value{GDBN}'s inbuilt
  @code{break} or @code{edit} commands do (@pxref{Specify Location}).

Thanks.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-06 13:55       ` Phil Muldoon
  2010-08-06 15:36         ` Eli Zaretskii
@ 2010-08-06 22:39         ` Tom Tromey
  2010-08-10 11:17           ` Phil Muldoon
  1 sibling, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-08-06 22:39 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Joel Brobecker, gdb-patches ml

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> I looked at the documentation and PY_LONG_LONG is only available on
Phil> some platforms (namely, 64 bit platforms).  I used unsigned long, and
Phil> 'k' instead.

I think PY_LONG_LONG should be available in other situations too -- in
particular if the compiler supports "long long", which GCC does.

It is important to use PY_LONG_LONG if it is available.  E.g., consider
if gdb is hosted on a 32-bit machine but debugging a 64-bit executable.
In this case an address will be 64 bits.

So, could you make this conditional?

The rest looks good to me.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-06 22:39         ` Tom Tromey
@ 2010-08-10 11:17           ` Phil Muldoon
  2010-08-10 17:07             ` Eli Zaretskii
  2010-08-10 18:24             ` Tom Tromey
  0 siblings, 2 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-08-10 11:17 UTC (permalink / raw)
  To: gdb-patches ml; +Cc: Tom Tromey, Joel Brobecker, Eli Zaretskii

On 06/08/10 23:39, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
> Phil> I looked at the documentation and PY_LONG_LONG is only available on
> Phil> some platforms (namely, 64 bit platforms).  I used unsigned long, and
> Phil> 'k' instead.
> 
> Tom> I think PY_LONG_LONG should be available in other situations too -- in
> Tom> particular if the compiler supports "long long", which GCC does.
> 
> Tom> It is important to use PY_LONG_LONG if it is available.  E.g., consider
> Tom> if gdb is hosted on a 32-bit machine but debugging a 64-bit executable.
> Tom>In this case an address will be 64 bits.
> 
> Tom> So, could you make this conditional?

Sure, what do you think of the attached patch?

> Eli> This is okay, but I would suggest to explain what happens without the
> Eli> argument first.  Readers shouldn't need to read all the description of
> Eli> how the argument is parsed if they don't want to pass it.

I've used your re-ordering in this patch, too.

OK?

Cheers,

Phil

--
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 867c06c..7dc7137 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20564,6 +20564,25 @@ Return the name of the current target wide character set
 never returned.
 @end defun
 
+@findex gdb.solib_name
+@defun solib_name address
+Return the name of the shared library holding the given @var{address}
+as a string, or @code{None}.
+@end defun
+
+@findex gdb.decode_line 
+@defun decode_line @r{[}expression@r{]}
+Return locations of the line specified by @var{expression}, or of the
+current line if no argument was given.  This function returns a Python
+tuple containing two elements.  The first element contains a string
+holding any unparsed section of @var{expression} (or @code{None} if
+the expression has been fully parsed).  The second element contains
+either @code{None} or another tuple that contains all the locations
+that match the expression represented as @code{gdb.Symtab_and_line}
+objects (@pxref{Symbol Tables In Python}).  If @var{expression} is
+provided, it is decoded the way that @value{GDBN}'s inbuilt
+@code{break} or @code{edit} commands do (@pxref{Specify Location}).
+
 @node Exception Handling
 @subsubsection Exception Handling
 @cindex python exceptions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 7346fba..16c3cba 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -42,7 +42,10 @@ static int gdbpy_should_print_stack = 1;
 #include "cli/cli-decode.h"
 #include "charset.h"
 #include "top.h"
+#include "solib.h"
 #include "python-internal.h"
+#include "linespec.h"
+#include "source.h"
 #include "version.h"
 #include "target.h"
 #include "gdbthread.h"
@@ -374,6 +377,137 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   Py_RETURN_NONE;
 }
 
+/* Implementation of gdb.solib_name (Long) -> String.
+   Returns the name of the shared library holding a given address, or None.  */
+
+static PyObject *
+gdbpy_solib_name (PyObject *self, PyObject *args)
+{
+  char *soname;
+  PyObject *str_obj;
+#ifdef PY_LONG_LONG
+  unsigned PY_LONG_LONG pc;
+  const char *format = "K";
+#else
+  unsigned long pc;
+  const char *format = "k";
+#endif
+
+  if (!PyArg_ParseTuple (args, format, &pc))
+    return NULL;
+
+  soname = solib_name_from_address (current_program_space, pc);
+  if (soname)
+    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
+  else
+    {
+      str_obj = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return str_obj;
+}
+
+/* A Python function which is a wrapper for decode_line_1.  */
+
+static PyObject *
+gdbpy_decode_line (PyObject *self, PyObject *args)
+{
+  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
+  struct symtab_and_line sal;
+  char *arg = NULL;
+  char *copy = NULL;
+  struct cleanup *cleanups;
+  PyObject *result = NULL;
+  PyObject *return_result = NULL;
+  PyObject *unparsed = NULL;
+  volatile struct gdb_exception except;
+
+  if (! PyArg_ParseTuple (args, "|s", &arg))
+    return NULL;
+
+  cleanups = ensure_python_env (get_current_arch (), current_language);
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      if (arg)
+	{
+	  arg = xstrdup (arg);
+	  make_cleanup (xfree, arg);
+	  copy = arg;
+	  sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
+	  make_cleanup (xfree, sals.sals);
+	}
+      else
+	{
+	  set_default_source_symtab_and_line ();
+	  sal = get_current_source_symtab_and_line ();
+	  sals.sals = &sal;
+	  sals.nelts = 1;
+	}
+    }
+  if (except.reason < 0)
+    {
+      do_cleanups (cleanups);
+      /* We know this will always throw.  */
+      GDB_PY_HANDLE_EXCEPTION (except);
+    }
+
+  if (sals.nelts)
+    {
+      int i;
+
+      result = PyTuple_New (sals.nelts);
+      if (! result)
+	goto error;
+      for (i = 0; i < sals.nelts; ++i)
+	{
+	  PyObject *obj;
+	  char *str;
+
+	  obj = symtab_and_line_to_sal_object (sals.sals[i]);
+	  if (! obj)
+	    {
+	      Py_DECREF (result);
+	      goto error;
+	    }
+
+	  PyTuple_SetItem (result, i, obj);
+	}
+    }
+  else
+    {
+      result = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  return_result = PyTuple_New (2);
+  if (! return_result)
+    {
+      Py_DECREF (result);
+      goto error;
+    }
+
+  if (copy && strlen (copy) > 0)
+    unparsed = PyString_FromString (copy);
+  else
+    {
+      unparsed = Py_None;
+      Py_INCREF (Py_None);
+    }
+
+  PyTuple_SetItem (return_result, 0, unparsed);
+  PyTuple_SetItem (return_result, 1, result);
+
+  do_cleanups (cleanups);
+
+  return return_result;
+
+ error:
+  do_cleanups (cleanups);
+  return NULL;
+}
+
 /* Parse a string and evaluate it as an expression.  */
 static PyObject *
 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
@@ -825,6 +959,16 @@ a boolean indicating if name is a field of the current implied argument\n\
 `this' (when the current language is object-oriented)." },
   { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
     "Return the block containing the given pc value, or None." },
+  { "solib_name", gdbpy_solib_name, METH_VARARGS,
+    "solib_name (Long) -> String.\n\
+Return the name of the shared library holding a given address, or None." },
+  { "decode_line", gdbpy_decode_line, METH_VARARGS,
+    "decode_line (String) -> Tuple.  Decode a string argument the way\n\
+that 'break' or 'edit' does.  Return a tuple containing two elements.\n\
+The first element contains any unparsed portion of the String parameter\n\
+(or None if the string was fully parsed).  The second element contains\n\
+a tuple that contains all the locations that match, represented as\n\
+gdb.Symtab_and_line objects (or None)."},
   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
     "parse_and_eval (String) -> Value.\n\
 Parse String as an expression, evaluate it, and return the result as a Value."
diff --git a/gdb/testsuite/gdb.python/python-sl.c b/gdb/testsuite/gdb.python/python-sl.c
new file mode 100644
index 0000000..579a74e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-sl.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c
new file mode 100644
index 0000000..750a90a
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library function */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 7aef888..e153ab8 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -20,12 +20,44 @@ if $tracelevel then {
     strace $tracelevel
 }
 
-# Start with a fresh gdb.
+set testfile "python"
+set srcfile  ${testfile}.c
+set libfile  "python-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
+
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
 
+# Start with a fresh gdb.
 gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+  gdb_test_multiple $cmd $name {
+      -re "Traceback.*$gdb_prompt $"  { fail $name }
+      -re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+  }
+}
+
 gdb_test_multiple "python print 23" "verify python support" {
     -re "not supported.*$gdb_prompt $"	{
       unsupported "python support is disabled"
@@ -110,3 +142,50 @@ gdb_test_multiple "python print \"\\n\" * $lines" $test {
     }
 }
 gdb_test "q" "Quit" "verify pagination afterwards: q"
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.decode_line.
+gdb_test "python gdb.decode_line(\"main.c:43\")" \
+    "RuntimeError: No source file named main.c.*" "test decode_line no source named main"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line current location"
+gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
+gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number"
+
+gdb_test "python gdb.decode_line(\"randomfunc\")" \
+    "RuntimeError: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-10 11:17           ` Phil Muldoon
@ 2010-08-10 17:07             ` Eli Zaretskii
  2010-08-10 18:24             ` Tom Tromey
  1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-08-10 17:07 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches, tromey, brobecker

> Date: Tue, 10 Aug 2010 12:17:20 +0100
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: Tom Tromey <tromey@redhat.com>, Joel Brobecker <brobecker@adacore.com>,
>         Eli Zaretskii <eliz@gnu.org>
> 
> > Eli> This is okay, but I would suggest to explain what happens without the
> > Eli> argument first.  Readers shouldn't need to read all the description of
> > Eli> how the argument is parsed if they don't want to pass it.
> 
> I've used your re-ordering in this patch, too.
> 
> OK?

I'm happy now.  Thanks.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-10 11:17           ` Phil Muldoon
  2010-08-10 17:07             ` Eli Zaretskii
@ 2010-08-10 18:24             ` Tom Tromey
  2010-08-11 13:16               ` Phil Muldoon
  2010-08-13 14:07               ` Ken Werner
  1 sibling, 2 replies; 20+ messages in thread
From: Tom Tromey @ 2010-08-10 18:24 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches ml, Joel Brobecker, Eli Zaretskii

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Tom> So, could you make this conditional?

Phil> Sure, what do you think of the attached patch?

Thanks for persevering.  This is ok.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-10 18:24             ` Tom Tromey
@ 2010-08-11 13:16               ` Phil Muldoon
  2010-08-13 14:07               ` Ken Werner
  1 sibling, 0 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-08-11 13:16 UTC (permalink / raw)
  To: gdb-patches ml; +Cc: Tom Tromey, Joel Brobecker, Eli Zaretskii

On 10/08/10 19:24, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

> Eli> This is okay, but I would suggest to explain what happens without the
> Eli> argument first.  Readers shouldn't need to read all the description of
> Eli> how the argument is parsed if they don't want to pass it.
> 
> Phil> > I've used your re-ordering in this patch, too.
> 
> Eli> I'm happy now.  Thanks.
> 
 
> Tom> So, could you make this conditional?
> 
> Phil> Sure, what do you think of the attached patch?
> 
> Tom> Thanks for persevering.  This is ok.


So committed. Thanks

http://sourceware.org/ml/gdb-cvs/2010-08/msg00051.html

Cheers,

Phil

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-10 18:24             ` Tom Tromey
  2010-08-11 13:16               ` Phil Muldoon
@ 2010-08-13 14:07               ` Ken Werner
  2010-08-13 14:14                 ` Phil Muldoon
  2010-08-13 15:48                 ` Tom Tromey
  1 sibling, 2 replies; 20+ messages in thread
From: Ken Werner @ 2010-08-13 14:07 UTC (permalink / raw)
  To: Phil Muldoon, Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 680 bytes --]

On Tuesday, August 10, 2010 08:24:09 pm Tom Tromey wrote:
> >>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> Tom> So, could you make this conditional?
> 
> Phil> Sure, what do you think of the attached patch?
> 
> Thanks for persevering.  This is ok.

Hi,

It looks like the const qualifier of the format string argument of the 
PyArg_Parse* routines has been introduced after the Python 2.4 release: 
http://svn.python.org/view?view=rev&revision=41638
In case gdb is built against libpython 2.4 the current code would generate a 
warning. One solution would be to just remove the const qualifier. A small 
patch is attached. Any comments are appreciated.

Thanks
Ken

[-- Attachment #2: python.patch --]
[-- Type: text/x-patch, Size: 889 bytes --]

ChangeLog:

2010-08-13  Ken Werner  <ken.werner@de.ibm.com>

	* gdb/python/python.c (gdbpy_solib_name): Remove the const qualifier of
	the format strings to be compatible with Python 2.4.


Index: gdb/python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.47
diff -p -u -r1.47 python.c
--- gdb/python/python.c	11 Aug 2010 20:54:11 -0000	1.47
+++ gdb/python/python.c	13 Aug 2010 13:44:16 -0000
@@ -388,10 +388,11 @@ gdbpy_solib_name (PyObject *self, PyObje
   PyObject *str_obj;
 #ifdef PY_LONG_LONG
   unsigned PY_LONG_LONG pc;
-  const char *format = "K";
+  /* To be compatible with Python 2.4 the format strings are not const.  */
+  char *format = "K";
 #else
   unsigned long pc;
-  const char *format = "k";
+  char *format = "k";
 #endif
 
   if (!PyArg_ParseTuple (args, format, &pc))

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-13 14:07               ` Ken Werner
@ 2010-08-13 14:14                 ` Phil Muldoon
  2010-08-13 15:48                 ` Tom Tromey
  1 sibling, 0 replies; 20+ messages in thread
From: Phil Muldoon @ 2010-08-13 14:14 UTC (permalink / raw)
  To: Ken Werner; +Cc: Tom Tromey, gdb-patches

On 13/08/10 15:07, Ken Werner wrote:
> On Tuesday, August 10, 2010 08:24:09 pm Tom Tromey wrote:
>>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>> Tom> So, could you make this conditional?
>>
>> Phil> Sure, what do you think of the attached patch?
>>
>> Thanks for persevering.  This is ok.
> 
> Hi,
> 
> It looks like the const qualifier of the format string argument of the 
> PyArg_Parse* routines has been introduced after the Python 2.4 release: 
> http://svn.python.org/view?view=rev&revision=41638
> In case gdb is built against libpython 2.4 the current code would generate a 
> warning. One solution would be to just remove the const qualifier. A small 
> patch is attached. Any comments are appreciated.

Thanks for catching this.  It looks fine to me; but wait for Tom or
another maintainer to give the official nod first.

Cheers

Phil

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-13 14:07               ` Ken Werner
  2010-08-13 14:14                 ` Phil Muldoon
@ 2010-08-13 15:48                 ` Tom Tromey
  2010-08-13 16:22                   ` Ken Werner
  1 sibling, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-08-13 15:48 UTC (permalink / raw)
  To: Ken Werner; +Cc: Phil Muldoon, gdb-patches

>>>>> "Ken" == Ken Werner <ken@linux.vnet.ibm.com> writes:

Ken> 2010-08-13  Ken Werner  <ken.werner@de.ibm.com>
Ken> 	* gdb/python/python.c (gdbpy_solib_name): Remove the const qualifier of
Ken> 	the format strings to be compatible with Python 2.4.

Thanks, this is ok.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-13 15:48                 ` Tom Tromey
@ 2010-08-13 16:22                   ` Ken Werner
  0 siblings, 0 replies; 20+ messages in thread
From: Ken Werner @ 2010-08-13 16:22 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Phil Muldoon, gdb-patches

On Friday, August 13, 2010 05:48:17 pm Tom Tromey wrote:
> >>>>> "Ken" == Ken Werner <ken@linux.vnet.ibm.com> writes:
> Ken> 2010-08-13  Ken Werner  <ken.werner@de.ibm.com>
> Ken> 	* gdb/python/python.c (gdbpy_solib_name): Remove the const qualifier
> of Ken> 	the format strings to be compatible with Python 2.4.
> 
> Thanks, this is ok.

Thanks, patch checked in.
http://sourceware.org/ml/gdb-cvs/2010-08/msg00068.html

Regards
Ken

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-07-19 15:43 [patch] Add solib_address and decode_line Python functionality Phil Muldoon
  2010-07-27 16:26 ` Joel Brobecker
@ 2010-08-18 23:55 ` Pedro Alves
  2010-08-19 16:32   ` Tom Tromey
  1 sibling, 1 reply; 20+ messages in thread
From: Pedro Alves @ 2010-08-18 23:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

On Monday 19 July 2010 16:43:09, Phil Muldoon wrote:
> 2010-07-19  Phil Muldoon  <pmuldoon@redhat.com>
> 
>         * gdb.python/python.c: New File.
>         * gdb.python/python-sl.c: New File.
>         * gdb.python/python.exp: Test solib_address and decode_line
>         * functions.
> 

This made it so that python.exp is untested on targets that do
not support shared libraries (e.g., arm-eabi), despite the host
supporting python.  I don't suppose you see a problem with
splitting these new tests out into their own files?  I've
added a python-1.c file so that python.exp still sees two
files, in case it is important to have more than one symtab.

I've tested this on x86_64-linux, and I was trying to test
python.exp on i686-mingw32 x arm-none-eabi, though it
appears I'll have to give up on that for the moment due to
system issues...

-- 
Pedro Alves

2010-08-18  Pedro Alves  <pedro@codesourcery.com>

	* gdb.python/py-shared.exp: New file, factored out from
	python.exp.
	* gdb.python/py-shared.c: New file.
	* gdb.python/py-shared-sl.c: New file.
	* gdb.python/python-1.c: New file.
	* gdb.python/python.c: Mention python-1.c.
	* gdb.python/python.exp: Move shared library tests to
	py-shared.exp.

---
 gdb/testsuite/gdb.python/py-shared-sl.c |   26 ++++++++++
 gdb/testsuite/gdb.python/py-shared.c    |   28 +++++++++++
 gdb/testsuite/gdb.python/py-shared.exp  |   77 ++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.python/python-1.c     |   26 ++++++++++
 gdb/testsuite/gdb.python/python.c       |    2 
 gdb/testsuite/gdb.python/python.exp     |   25 +---------
 6 files changed, 162 insertions(+), 22 deletions(-)

Index: src/gdb/testsuite/gdb.python/py-shared-sl.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared-sl.c	2010-08-19 00:10:25.000000000 +0100
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
Index: src/gdb/testsuite/gdb.python/py-shared.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared.c	2010-08-19 00:11:35.000000000 +0100
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library functions */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
Index: src/gdb/testsuite/gdb.python/py-shared.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared.exp	2010-08-19 00:24:46.000000000 +0100
@@ -0,0 +1,77 @@
+# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.
+
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+set testfile "py-shared"
+set srcfile  ${testfile}.c
+set libfile  "py-shared-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
+
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+    gdb_test_multiple $cmd $name {
+	-re "Traceback.*$gdb_prompt $"  { fail $name }
+	-re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+    }
+}
+
+# Start with a fresh gdb.
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/py-shared-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"
Index: src/gdb/testsuite/gdb.python/python-1.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/python-1.c	2010-08-19 00:09:32.000000000 +0100
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
Index: src/gdb/testsuite/gdb.python/python.c
===================================================================
--- src.orig/gdb/testsuite/gdb.python/python.c	2010-08-11 13:48:24.000000000 +0100
+++ src/gdb/testsuite/gdb.python/python.c	2010-08-19 00:11:06.000000000 +0100
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Shared library function */
+/* In python-1.c.  */
 extern void func1 (void);
 extern int func2 (void);
 
Index: src/gdb/testsuite/gdb.python/python.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.python/python.exp	2010-08-18 13:16:41.000000000 +0100
+++ src/gdb/testsuite/gdb.python/python.exp	2010-08-19 00:13:26.000000000 +0100
@@ -22,19 +22,11 @@ if $tracelevel then {
 
 set testfile "python"
 set srcfile  ${testfile}.c
-set libfile  "python-sl"
-set libsrc   ${libfile}.c
-set library  ${objdir}/${subdir}/${libfile}.sl
+set srcfile1  ${testfile}-1.c
 set binfile  ${objdir}/${subdir}/${testfile}
 
-if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
-    untested "Could not compile shared library."
-    return -1
-}
-
-set exec_opts [list debug shlib=${library}]
-
-if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" \
+	  ${binfile} executable {debug}] != "" } {
     untested "Could not compile $binfile."
     return -1
 }
@@ -192,14 +184,5 @@ gdb_test "python gdb.decode_line(\"rando
 gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
 gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
 gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
-gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-1.c.*" "Test decode_line func1 filename"
 gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
-
-# Test gdb.solib_name
-gdb_test "p &func1" "" "func1 address"
-gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
-gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
-
-gdb_test "p &main" "" "main address"
-gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
-gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-18 23:55 ` Pedro Alves
@ 2010-08-19 16:32   ` Tom Tromey
  2010-08-19 17:04     ` Pedro Alves
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-08-19 16:32 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Phil Muldoon

>>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:

Pedro> This made it so that python.exp is untested on targets that do
Pedro> not support shared libraries (e.g., arm-eabi), despite the host
Pedro> supporting python.  I don't suppose you see a problem with
Pedro> splitting these new tests out into their own files?

It is no problem at all.
Please check this in.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] Add solib_address and decode_line Python functionality
  2010-08-19 16:32   ` Tom Tromey
@ 2010-08-19 17:04     ` Pedro Alves
  0 siblings, 0 replies; 20+ messages in thread
From: Pedro Alves @ 2010-08-19 17:04 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Phil Muldoon

On Thursday 19 August 2010 17:31:57, Tom Tromey wrote:
> >>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:
> 
> Pedro> This made it so that python.exp is untested on targets that do
> Pedro> not support shared libraries (e.g., arm-eabi), despite the host
> Pedro> supporting python.  I don't suppose you see a problem with
> Pedro> splitting these new tests out into their own files?
> 
> It is no problem at all.
> Please check this in.

Thanks.  I've also noticed meanwhile that "make clean" was leaving
the binaries behind, so I've updated it too.  Below's what I checked
in.

-- 
Pedro Alves

2010-08-19  Pedro Alves  <pedro@codesourcery.com>

	* gdb.python/py-shared.exp: New file, factored out from
	python.exp.
	* gdb.python/py-shared.c: New file.
	* gdb.python/py-shared-sl.c: New file.
	* gdb.python/python-1.c: New file.
	* gdb.python/python-sl.c: Delete.
	* gdb.python/python.c: Mention python-1.c.
	* gdb.python/python.exp: Move shared library tests to
	py-shared.exp.
	* gdb.python/Makefile.in (EXECUTABLES): Add py-shared and python.
	(MISCELLANEOUS): New.
	(clean mostlyclean): Also remove $MISCELLANEOUS.

---
 gdb/testsuite/gdb.python/Makefile.in    |    7 ++
 gdb/testsuite/gdb.python/py-shared-sl.c |   26 ++++++++++
 gdb/testsuite/gdb.python/py-shared.c    |   28 +++++++++++
 gdb/testsuite/gdb.python/py-shared.exp  |   77 ++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.python/python-1.c     |   26 ++++++++++
 gdb/testsuite/gdb.python/python.c       |    2 
 gdb/testsuite/gdb.python/python.exp     |   25 +---------
 7 files changed, 167 insertions(+), 24 deletions(-)

Index: src/gdb/testsuite/gdb.python/py-shared-sl.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared-sl.c	2010-08-19 17:58:13.000000000 +0100
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
Index: src/gdb/testsuite/gdb.python/py-shared.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared.c	2010-08-19 17:58:13.000000000 +0100
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Shared library functions */
+extern void func1 (void);
+extern int func2 (void);
+
+int
+main (int argc, char *argv[])
+{
+  func1 ();
+  func2 ();
+  return 0;      /* Break to end.  */
+}
Index: src/gdb/testsuite/gdb.python/py-shared.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/py-shared.exp	2010-08-19 17:58:13.000000000 +0100
@@ -0,0 +1,77 @@
+# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.
+
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+set testfile "py-shared"
+set srcfile  ${testfile}.c
+set libfile  "py-shared-sl"
+set libsrc   ${libfile}.c
+set library  ${objdir}/${subdir}/${libfile}.sl
+set binfile  ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+    untested "Could not compile shared library."
+    return -1
+}
+
+set exec_opts [list debug shlib=${library}]
+
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+    untested "Could not compile $binfile."
+    return -1
+}
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+    global gdb_prompt
+
+    gdb_test_multiple $cmd $name {
+	-re "Traceback.*$gdb_prompt $"  { fail $name }
+	-re "$gdb_prompt $"	      { if $report_pass { pass $name } }
+    }
+}
+
+# Start with a fresh gdb.
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# The following tests require execution.
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/py-shared-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"
Index: src/gdb/testsuite/gdb.python/python-1.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/testsuite/gdb.python/python-1.c	2010-08-19 17:58:13.000000000 +0100
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void func1 ()
+{
+  return;
+}
+
+int func2 ()
+{
+  return 0;
+}
Index: src/gdb/testsuite/gdb.python/python.c
===================================================================
--- src.orig/gdb/testsuite/gdb.python/python.c	2010-08-19 17:56:30.000000000 +0100
+++ src/gdb/testsuite/gdb.python/python.c	2010-08-19 17:58:13.000000000 +0100
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Shared library function */
+/* In python-1.c.  */
 extern void func1 (void);
 extern int func2 (void);
 
Index: src/gdb/testsuite/gdb.python/python.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.python/python.exp	2010-08-19 17:56:30.000000000 +0100
+++ src/gdb/testsuite/gdb.python/python.exp	2010-08-19 17:58:13.000000000 +0100
@@ -22,19 +22,11 @@ if $tracelevel then {
 
 set testfile "python"
 set srcfile  ${testfile}.c
-set libfile  "python-sl"
-set libsrc   ${libfile}.c
-set library  ${objdir}/${subdir}/${libfile}.sl
+set srcfile1  ${testfile}-1.c
 set binfile  ${objdir}/${subdir}/${testfile}
 
-if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
-    untested "Could not compile shared library."
-    return -1
-}
-
-set exec_opts [list debug shlib=${library}]
-
-if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" \
+	  ${binfile} executable {debug}] != "" } {
     untested "Could not compile $binfile."
     return -1
 }
@@ -192,14 +184,5 @@ gdb_test "python gdb.decode_line(\"rando
 gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
 gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
 gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
-gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-1.c.*" "Test decode_line func1 filename"
 gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
-
-# Test gdb.solib_name
-gdb_test "p &func1" "" "func1 address"
-gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
-gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
-
-gdb_test "p &main" "" "main address"
-gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
-gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"
Index: src/gdb/testsuite/gdb.python/Makefile.in
===================================================================
--- src.orig/gdb/testsuite/gdb.python/Makefile.in	2010-08-19 17:56:30.000000000 +0100
+++ src/gdb/testsuite/gdb.python/Makefile.in	2010-08-19 17:58:13.000000000 +0100
@@ -2,14 +2,17 @@ VPATH = @srcdir@
 srcdir = @srcdir@
 
 EXECUTABLES = py-type py-value py-prettyprint py-template py-block \
-		py-symbol py-mi py-breakpoint py-inferior py-infthread
+		py-symbol py-mi py-breakpoint py-inferior py-infthread \
+		py-shared python
+
+MISCELLANEOUS = py-shared-sl.sl
 
 all info install-info dvi install uninstall installcheck check:
 	@echo "Nothing to be done for $@..."
 
 clean mostlyclean:
 	-rm -f *~ *.o *.ci
-	-rm -f core $(EXECUTABLES)
+	-rm -f core $(EXECUTABLES) $(MISCELLANEOUS)
 
 distclean maintainer-clean realclean: clean
 	-rm -f Makefile config.status config.log

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-08-19 17:04 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-19 15:43 [patch] Add solib_address and decode_line Python functionality Phil Muldoon
2010-07-27 16:26 ` Joel Brobecker
2010-07-28 11:35   ` Phil Muldoon
2010-07-28 17:39     ` Joel Brobecker
2010-07-28 17:48     ` Eli Zaretskii
2010-07-29 20:39     ` Tom Tromey
2010-08-06 13:55       ` Phil Muldoon
2010-08-06 15:36         ` Eli Zaretskii
2010-08-06 22:39         ` Tom Tromey
2010-08-10 11:17           ` Phil Muldoon
2010-08-10 17:07             ` Eli Zaretskii
2010-08-10 18:24             ` Tom Tromey
2010-08-11 13:16               ` Phil Muldoon
2010-08-13 14:07               ` Ken Werner
2010-08-13 14:14                 ` Phil Muldoon
2010-08-13 15:48                 ` Tom Tromey
2010-08-13 16:22                   ` Ken Werner
2010-08-18 23:55 ` Pedro Alves
2010-08-19 16:32   ` Tom Tromey
2010-08-19 17:04     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).