Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: fix PR python/13599
@ 2012-01-31 22:04 Tom Tromey
       [not found] ` <CADPb22RaFYaB0XGxCiftTAshX1S2PGVuYaAvB6Ky45MFz6cg6Q@mail.gmail.com>
  2012-02-07 18:05 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2012-01-31 22:04 UTC (permalink / raw)
  To: gdb-patches

This fixes PR python/13599.

The bug is that there is no way to get the line number in the source at
which a symbol was defined, even though gdb tracks this information.

This patch changes gdb.Symbol to add a new 'line' attribute.

This requires a doc review.

Built and regtested on x86-64 Fedora 15.

Tom

2012-01-31  Tom Tromey  <tromey@redhat.com>

	PR python/13599:
	* python/py-symbol.c (sympy_line): New function.
	(symbol_object_getset): Add "line".

2012-01-31  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (Symbols In Python): Document Symbol.line.

2012-01-31  Tom Tromey  <tromey@redhat.com>

	* gdb.python/py-symbol.c (qq): New global.
	* gdb.python/py-symbol.exp: Add test for frame-less
	lookup_symbol.
	* gdb.python/py-symtab.exp: Fix line number.

From bec0d20aa5b8e1e61de4c2d001d492c9d7b2bbd1 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Tue, 31 Jan 2012 14:02:20 -0700
Subject: [PATCH 2/3] fix PR 13599 - find line number of symbol

---
 gdb/ChangeLog                          |    6 ++++++
 gdb/NEWS                               |    5 +++++
 gdb/doc/ChangeLog                      |    4 ++++
 gdb/doc/gdb.texinfo                    |    5 +++++
 gdb/python/py-symbol.c                 |   15 +++++++++++++++
 gdb/testsuite/ChangeLog                |    2 ++
 gdb/testsuite/gdb.python/py-symbol.c   |    2 ++
 gdb/testsuite/gdb.python/py-symbol.exp |    4 ++++
 gdb/testsuite/gdb.python/py-symtab.exp |    5 +++--
 9 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 4798b7b..bb9429f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -10,6 +10,11 @@
   ** A new class, gdb.printing.FlagEnumerationPrinter, can be used to
      apply "flag enum"-style pretty-printing to any enum.
 
+  ** gdb.lookup_symbol can now work when there is no current frame.
+
+  ** gdb.Symbol now has a 'line' attribute, holding the line number in
+     the source at which the symbol was defined.
+
 * GDBserver now supports stdio connections.
   E.g. (gdb) target remote | ssh myhost gdbserver - hello
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 86fa88f..9fa4b4e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -23968,6 +23968,11 @@ represented as a @code{gdb.Symtab} object.  @xref{Symbol Tables In
 Python}.  This attribute is not writable.
 @end defvar
 
+@defvar Symbol.line
+The line number in the source code at which the symbol was defined.
+This is an integer.
+@end defvar
+
 @defvar Symbol.name
 The name of the symbol as a string.  This attribute is not writable.
 @end defvar
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index f93a35a..d9dae47 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -183,6 +183,19 @@ sympy_is_variable (PyObject *self, void *closure)
 			      || class == LOC_OPTIMIZED_OUT));
 }
 
+/* Implementation of gdb.Symbol.line -> int.
+   Returns the line number at which the symbol was defined.  */
+
+static PyObject *
+sympy_line (PyObject *self, void *closure)
+{
+  struct symbol *symbol = NULL;
+
+  SYMPY_REQUIRE_VALID (self, symbol);
+
+  return PyInt_FromLong (SYMBOL_LINE (symbol));
+}
+
 /* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
    Returns True if this Symbol still exists in GDB.  */
 
@@ -461,6 +474,8 @@ to display demangled or mangled names.", NULL },
     "True if the symbol is a function or method." },
   { "is_variable", sympy_is_variable, NULL,
     "True if the symbol is a variable." },
+  { "line", sympy_line, NULL,
+    "The source line number at which the symbol was defined." },
   { NULL }  /* Sentinel */
 };
 
diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c
index 72469be..d29849b 100644
--- a/gdb/testsuite/gdb.python/py-symbol.c
+++ b/gdb/testsuite/gdb.python/py-symbol.c
@@ -35,6 +35,8 @@ class SimpleClass
 };
 #endif
 
+int qq;				/* line of qq */
+
 int func (int arg)
 {
   int i = 2;
diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp
index 91bfd51..36d7bfd 100644
--- a/gdb/testsuite/gdb.python/py-symbol.exp
+++ b/gdb/testsuite/gdb.python/py-symbol.exp
@@ -45,6 +45,10 @@ gdb_test "python print gdb.lookup_global_symbol(\"junk\")" "None" "Test lookup_g
 gdb_test "python print gdb.lookup_symbol('main')\[0\].is_function" "True" \
     "Lookup main using lookup_symbol"
 
+set qq_line [gdb_get_line_number "line of qq"]
+gdb_test "python print gdb.lookup_symbol('qq')\[0\].line" "$qq_line" \
+    "print line number of qq"
+
 if ![runto_main] then {
     fail "Can't run to main"
     return 0
diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp
index f64cb57..490a891 100644
--- a/gdb/testsuite/gdb.python/py-symtab.exp
+++ b/gdb/testsuite/gdb.python/py-symtab.exp
@@ -43,7 +43,8 @@ if ![runto_main] then {
 global hex decimal
 
 # Setup and get the symbol table.
-gdb_breakpoint [gdb_get_line_number "Block break here."]
+set line_no [gdb_get_line_number "Block break here."]
+gdb_breakpoint $line_no
 gdb_continue_to_breakpoint "Block break here."
 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
 gdb_py_test_silent_cmd "python sal = frame.find_sal()" "Get block" 0
@@ -52,7 +53,7 @@ gdb_py_test_silent_cmd "python symtab = sal.symtab" "Get block" 0
 # Test sal.
 gdb_test "python print sal.symtab" ".*gdb.python/py-symbol.c.*" "Test symtab"
 gdb_test "python print sal.pc" "${decimal}" "Test sal.pc"
-gdb_test "python print sal.line" "42" "Test sal.line"
+gdb_test "python print sal.line" "$line_no" "Test sal.line"
 gdb_test "python print sal.is_valid()" "True" "Test sal.is_valid"
 
 # Test symbol table.
-- 
1.7.6.5


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

* Re: RFA: fix PR python/13599
       [not found] ` <CADPb22RaFYaB0XGxCiftTAshX1S2PGVuYaAvB6Ky45MFz6cg6Q@mail.gmail.com>
@ 2012-02-01  8:32   ` Kevin Pouget
  2012-02-01 16:08     ` Tom Tromey
  2012-02-01 11:50   ` Phil Muldoon
  1 sibling, 1 reply; 6+ messages in thread
From: Kevin Pouget @ 2012-02-01  8:32 UTC (permalink / raw)
  To: Doug Evans, Tom Tromey; +Cc: gdb-patches

On Wed, Feb 1, 2012 at 12:22 AM, Doug Evans <dje@google.com> wrote:
> On Tue, Jan 31, 2012 at 2:01 PM, Tom Tromey <tromey@redhat.com> wrote:
>> This fixes PR python/13599.
>>
>> The bug is that there is no way to get the line number in the source at
>> which a symbol was defined, even though gdb tracks this information.
>>
>> This patch changes gdb.Symbol to add a new 'line' attribute.
>>
>> This requires a doc review.
>>
>> Built and regtested on x86-64 Fedora 15.
>>
>> Tom
>>
>> 2012-01-31  Tom Tromey  <tromey@redhat.com>
>>
>>        PR python/13599:
>>        * python/py-symbol.c (sympy_line): New function.
>>        (symbol_object_getset): Add "line".
>
> 'tis ok with me.
>
> One comment though.
> The first thing that come to mind, as a user, is "Well, if I can get
> the line number from the symbol, why do I have to look elsewhere to
> get the file name?"
> The reason is an internal gdb implementation detail that we expose in
> python. IWBN if symbol tables were more nebulous entities - we might
> want the freedom to change them a bit.  [Not that we necessarily can
> change things now, but I think it's something we should keep in mind.]

I was curious about the difference between your new method and this one:

> def whereis(arg):
>     symbols = gdb.decode_line(arg)
>     for sal in symbols:
>         if sal is not None and sal.symtab is not None:
>             print "'%s' is at %s%s, line %s" % (arg, sal.pc != 0 and "0x%x " % sal.pc or "", sal.symtab.filename, sal.line)

(I wrote this code before learning about `info line ...`)

Actually, the difference between Symbol, Symtab and Symtab_and_line is
still a bit obscure to me, I'm not sure that the documentation really
explains the meaning of these classes, but just what they do (or maybe
I missed something):

> A gdb.Symbol object has the following attributes: ...
> A gdb.Symtab_and_line object has the following attributes:  ...


Kevin


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

* Re: RFA: fix PR python/13599
       [not found] ` <CADPb22RaFYaB0XGxCiftTAshX1S2PGVuYaAvB6Ky45MFz6cg6Q@mail.gmail.com>
  2012-02-01  8:32   ` Kevin Pouget
@ 2012-02-01 11:50   ` Phil Muldoon
  1 sibling, 0 replies; 6+ messages in thread
From: Phil Muldoon @ 2012-02-01 11:50 UTC (permalink / raw)
  To: Doug Evans; +Cc: Tom Tromey, gdb-patches

On 01/31/2012 11:22 PM, Doug Evans wrote:
> On Tue, Jan 31, 2012 at 2:01 PM, Tom Tromey<tromey@redhat.com>  wrote:
>> This fixes PR python/13599.
>>
>> The bug is that there is no way to get the line number in the source at
>> which a symbol was defined, even though gdb tracks this information.
>>
>> This patch changes gdb.Symbol to add a new 'line' attribute.
>>
>> This requires a doc review.
>>
>> Built and regtested on x86-64 Fedora 15.
>>
>> Tom
>>
>> 2012-01-31  Tom Tromey<tromey@redhat.com>
>>
>>         PR python/13599:
>>         * python/py-symbol.c (sympy_line): New function.
>>         (symbol_object_getset): Add "line".
> 'tis ok with me.
>
> One comment though.
> The first thing that come to mind, as a user, is "Well, if I can get
> the line number from the symbol, why do I have to look elsewhere to
> get the file name?"
> The reason is an internal gdb implementation detail that we expose in
> python. IWBN if symbol tables were more nebulous entities - we might
> want the freedom to change them a bit.  [Not that we necessarily can
> change things now, but I think it's something we should keep in mind.]

There is no reason why we cannot export the filename as an API in the 
py-symbol.  The 1:1 mapping of API to GDB modulefunctionality is not 
even a weak rule imo.  If it makes sense from an API point of view, no 
reason why we should not export it in py-symbol regardless of where the 
information comes from in GDB.

Cheers,

Phil


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

* Re: RFA: fix PR python/13599
  2012-02-01  8:32   ` Kevin Pouget
@ 2012-02-01 16:08     ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2012-02-01 16:08 UTC (permalink / raw)
  To: Kevin Pouget; +Cc: Doug Evans, gdb-patches

>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:

Kevin> I was curious about the difference between your new method and this one:

>> def whereis(arg):
>> symbols = gdb.decode_line(arg)

decode_line won't return, e.g., a local variable.
It is also much less efficient than just fetching the field from the
symbol.

Kevin> Actually, the difference between Symbol, Symtab and Symtab_and_line is
Kevin> still a bit obscure to me, I'm not sure that the documentation really
Kevin> explains the meaning of these classes, but just what they do (or maybe
Kevin> I missed something):

File bugs against the python component for any documentation oddities
you find, and we will fix them.

Phil has a long-term goal of getting more examples into the manual, that
would help too :)

Tom


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

* Re: RFA: fix PR python/13599
  2012-01-31 22:04 RFA: fix PR python/13599 Tom Tromey
       [not found] ` <CADPb22RaFYaB0XGxCiftTAshX1S2PGVuYaAvB6Ky45MFz6cg6Q@mail.gmail.com>
@ 2012-02-07 18:05 ` Tom Tromey
  2012-02-07 18:47   ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2012-02-07 18:05 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> This requires a doc review.

Ping.

Tom


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

* Re: RFA: fix PR python/13599
  2012-02-07 18:05 ` Tom Tromey
@ 2012-02-07 18:47   ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2012-02-07 18:47 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> From: Tom Tromey <tromey@redhat.com>
> Date: Tue, 07 Feb 2012 11:05:01 -0700
> 
> >>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
> 
> Tom> This requires a doc review.
> 
> Ping.

Sorry.  The documentation part is okay.


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

end of thread, other threads:[~2012-02-07 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 22:04 RFA: fix PR python/13599 Tom Tromey
     [not found] ` <CADPb22RaFYaB0XGxCiftTAshX1S2PGVuYaAvB6Ky45MFz6cg6Q@mail.gmail.com>
2012-02-01  8:32   ` Kevin Pouget
2012-02-01 16:08     ` Tom Tromey
2012-02-01 11:50   ` Phil Muldoon
2012-02-07 18:05 ` Tom Tromey
2012-02-07 18:47   ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox