[5/7] py-symbol: export section name
Commit Message
From: Jeff Mahoney <jeffm@suse.com>
Some consumers of the symbol API need to know in what section a symbol is
located. This exports the section name as a string.
---
gdb/python/py-symbol.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Comments
On 04/02/16 17:29, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
>
> Some consumers of the symbol API need to know in what section a symbol is
> located. This exports the section name as a string.
> ---
> gdb/python/py-symbol.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
> index c7f0ff8..aad2edc 100644
> --- a/gdb/python/py-symbol.c
> +++ b/gdb/python/py-symbol.c
> @@ -238,6 +238,27 @@ sympy_is_valid (PyObject *self, PyObject *args)
> Py_RETURN_TRUE;
> }
>
> +static PyObject *
> +sympy_section (PyObject *self, void *closure)
> +{
> + struct symbol *symbol = NULL;
> + PyObject *section_obj;
> + struct obj_section *section;
> + const char *name;
> +
> + SYMPY_REQUIRE_VALID (self, symbol);
> +
> + section = SYMBOL_OBJ_SECTION (symbol_objfile(symbol), symbol);
> + if (section) {
> + name = bfd_section_name (symbol_objfile(objfile)->obfd,
> + section->the_bfd_section);
> + if (name)
> + return PyString_FromString (name);
> + }
> +
> + Py_RETURN_NONE;
> +}
> +
> /* Implementation of gdb.Symbol.value (self[, frame]) -> gdb.Value. Returns
> the value of the symbol, or an error in various circumstances. */
>
> @@ -590,6 +611,8 @@ to display demangled or mangled names.", NULL },
> "True if the symbol requires a frame for evaluation." },
> { "line", sympy_line, NULL,
> "The source line number at which the symbol was defined." },
> + { "section", sympy_section, NULL,
> + "Section of executable where symbol resides." },
> { NULL } /* Sentinel */
> };
>
This looks fine, but it needs a documentation entry and tests.
Cheers
Phil
@@ -238,6 +238,27 @@ sympy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+static PyObject *
+sympy_section (PyObject *self, void *closure)
+{
+ struct symbol *symbol = NULL;
+ PyObject *section_obj;
+ struct obj_section *section;
+ const char *name;
+
+ SYMPY_REQUIRE_VALID (self, symbol);
+
+ section = SYMBOL_OBJ_SECTION (symbol_objfile(symbol), symbol);
+ if (section) {
+ name = bfd_section_name (symbol_objfile(objfile)->obfd,
+ section->the_bfd_section);
+ if (name)
+ return PyString_FromString (name);
+ }
+
+ Py_RETURN_NONE;
+}
+
/* Implementation of gdb.Symbol.value (self[, frame]) -> gdb.Value. Returns
the value of the symbol, or an error in various circumstances. */
@@ -590,6 +611,8 @@ to display demangled or mangled names.", NULL },
"True if the symbol requires a frame for evaluation." },
{ "line", sympy_line, NULL,
"The source line number at which the symbol was defined." },
+ { "section", sympy_section, NULL,
+ "Section of executable where symbol resides." },
{ NULL } /* Sentinel */
};