+2019-07-29 Christian Biesinger <cbiesinger@google.com>
+
+ * NEWS: Mention new functions Objfile.lookup_{global,static}_symbol.
+ * python/py-objfile.c (objfpy_lookup_global_symbol): New function.
+ (objfpy_lookup_static_symbol): New function.
+ (objfile_object_methods): Add new functions.
+
2019-07-29 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* NEWS: Mention 'set|show print frame-info'. Mention new
there are no filters, or when the 'backtrace' '-no-filters' option
is given.
+ ** gdb.Objfile has new methods 'lookup_global_symbol' and
+ 'lookup_static_symbol' to lookup a symbol from this objfile only.
+
* New commands
| [COMMAND] | SHELL_COMMAND
+2019-07-29 Christian Biesinger <cbiesinger@google.com>
+
+ * python.texi (Objfiles In Python): Document new functions
+ Objfile.lookup_{global,static}_symbol.
+
2019-07-29 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.texinfo (Backtrace): Document the new '-frame-info'
from a different place.
@end defun
+@defun Objfile.lookup_global_symbol (name @r{[}, domain@r{]})
+Search for a global symbol named @var{name} in this objfile. Optionally, the
+search scope can be restricted with the @var{domain} argument.
+The @var{domain} argument must be a domain constant defined in the @code{gdb}
+module and described in @ref{Symbols In Python}. This function is similar to
+@code{gdb.lookup_global_symbol}, except that the search is limited to this
+objfile.
+
+The result is a @code{gdb.Symbol} object or @code{None} if the symbol
+is not found.
+@end defun
+
+@defun Objfile.lookup_static_symbol (name @r{[}, domain@r{]})
+Like @code{Objfile.lookup_global_symbol}, but searches for a global
+symbol with static linkage named @var{name} in this objfile.
+@end defun
+
@node Frames In Python
@subsubsection Accessing inferior stack frames from Python
Py_RETURN_NONE;
}
+/* Implementation of
+ gdb.Objfile.lookup_global_symbol (self, string [, domain]) -> gdb.Symbol. */
+
+static PyObject *
+objfpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
+{
+ static const char *keywords[] = { "name", "domain", NULL };
+ objfile_object *obj = (objfile_object *) self;
+ const char *symbol_name;
+ int domain = VAR_DOMAIN;
+
+ OBJFPY_REQUIRE_VALID (obj);
+
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &symbol_name,
+ &domain))
+ return nullptr;
+
+ try
+ {
+ struct symbol *sym = lookup_global_symbol_from_objfile
+ (obj->objfile, GLOBAL_BLOCK, symbol_name, (domain_enum) domain).symbol;
+ if (sym == nullptr)
+ Py_RETURN_NONE;
+
+ return symbol_to_symbol_object (sym);
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+
+ Py_RETURN_NONE;
+}
+
+/* Implementation of
+ gdb.Objfile.lookup_static_symbol (self, string [, domain]) -> gdb.Symbol. */
+
+static PyObject *
+objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
+{
+ static const char *keywords[] = { "name", "domain", NULL };
+ objfile_object *obj = (objfile_object *) self;
+ const char *symbol_name;
+ int domain = VAR_DOMAIN;
+
+ OBJFPY_REQUIRE_VALID (obj);
+
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &symbol_name,
+ &domain))
+ return nullptr;
+
+ try
+ {
+ struct symbol *sym = lookup_global_symbol_from_objfile
+ (obj->objfile, STATIC_BLOCK, symbol_name, (domain_enum) domain).symbol;
+ if (sym == nullptr)
+ Py_RETURN_NONE;
+
+ return symbol_to_symbol_object (sym);
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+
+ Py_RETURN_NONE;
+}
+
/* Implement repr() for gdb.Objfile. */
static PyObject *
"add_separate_debug_file (file_name).\n\
Add FILE_NAME to the list of files containing debug info for the objfile." },
+ { "lookup_global_symbol", (PyCFunction) objfpy_lookup_global_symbol,
+ METH_VARARGS | METH_KEYWORDS,
+ "lookup_global_symbol (name [, domain]).\n\
+Look up a global symbol in this objfile and return it." },
+
+ { "lookup_static_symbol", (PyCFunction) objfpy_lookup_static_symbol,
+ METH_VARARGS | METH_KEYWORDS,
+ "lookup_static_symbol (name [, domain]).\n\
+Look up a static-linkage global symbol in this objfile and return it." },
+
{ NULL }
};
+2019-07-29 Christian Biesinger <cbiesinger@google.com>
+
+ * gdb.python/py-objfile.c: Add global and static vars.
+ * gdb.python/py-objfile.exp: Test new functions Objfile.
+ lookup_global_symbol and lookup_static_symbol.
+
2019-07-29 Tom Tromey <tom@tromey.com>
* lib/tuiterm.exp (Term::_csi_@): New proc.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+int global_var = 42;
+static int static_var = 50;
+
int
main ()
{
gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
"Objfile not found\\.\r\n${python_error_text}"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"global_var\").name)" \
+ "global_var" "lookup_global_symbol finds a valid symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"static_var\") is None)" \
+ "True" "lookup_global_symbol does not find static symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"stdout\"))" \
+ "None" "lookup_global_symbol doesn't find symbol in other objfile"
+
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"static_var\").name)" \
+ "static_var" "lookup_static_symbol finds a valid symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"global_var\") is None)" \
+ "True" "lookup_static_symbol does not find global symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"nonexistant\"))" \
+ "None" "lookup_static_symbol can handle nonexistant symbol"
+
set binfile_build_id [get_build_id $binfile]
if [string compare $binfile_build_id ""] {
verbose -log "binfile_build_id = $binfile_build_id"