event is triggered once GDB decides it is going to exit, but
before GDB starts to clean up its internal state.
+ ** New function gdb.architecture_names(), which returns a list
+ containing all of the possible Architecture.name() values. Each
+ entry is a string.
+
*** Changes in GDB 11
* The 'set disassembler-options' command now supports specifying options
related prompts are prohibited from being changed.
@end defun
+@defun gdb.architecture_names ()
+Return a list containing all of the architecture names that the
+current build of @value{GDBN} supports. Each architecture name is a
+string. The names returned in this list are the same names as are
+returned from @code{gdb.Architecture.name}
+(@pxref{gdbpy_architecture_name,,Architecture.name}).
+@end defun
+
@node Exception Handling
@subsubsection Exception Handling
@cindex python exceptions
A @code{gdb.Architecture} class has the following methods:
+@anchor{gdbpy_architecture_name}
@defun Architecture.name ()
Return the name (string value) of the architecture.
@end defun
return gdbpy_new_reggroup_iterator (gdbarch);
}
+/* Implementation of gdb.architecture_names(). Return a list of all the
+ BFD architecture names that GDB understands. */
+
+PyObject *
+gdbpy_all_architecture_names (PyObject *self, PyObject *args)
+{
+ gdbpy_ref<> list (PyList_New (0));
+ if (list == nullptr)
+ return nullptr;
+
+ std::vector<const char *> name_list = gdbarch_printable_names ();
+ for (const char *name : name_list)
+ {
+ gdbpy_ref <> py_name (PyString_FromString (name));
+ if (py_name == nullptr)
+ return nullptr;
+ if (PyList_Append (list.get (), py_name.get ()) < 0)
+ return nullptr;
+ }
+
+ return list.release ();
+}
+
void _initialize_py_arch ();
void
_initialize_py_arch ()
PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw);
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
+PyObject *gdbpy_all_architecture_names (PyObject *self, PyObject *args);
PyObject *gdbpy_new_register_descriptor_iterator (struct gdbarch *gdbarch,
const char *group_name);
Register a TUI window constructor." },
#endif /* TUI */
+ { "architecture_names", gdbpy_all_architecture_names, METH_NOARGS,
+ "architecture_names () -> List.\n\
+Return a list of all the architecture names GDB understands." },
+
{NULL, NULL, 0, NULL}
};
gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
"test bad memory access"
}
+
+# Test for gdb.architecture_names(). First we're going to grab the
+# complete list of architecture names using the 'complete' command.
+set arch_names []
+gdb_test_no_output "set max-completions unlimited"
+gdb_test_multiple "complete set architecture " "" {
+ -re "complete set architecture\[^\r\n\]+\r\n" {
+ exp_continue
+ }
+ -re "^set architecture \(\[^\r\n\]+\)\r\n" {
+ set arch $expect_out(1,string)
+ if { "$arch" != "auto" } {
+ set arch_names [lappend arch_names $arch]
+ }
+ exp_continue
+ }
+ -re "^$gdb_prompt $" {
+ gdb_assert { [llength $arch_names] > 0 }
+ }
+}
+
+# Now find all of the architecture names using Python.
+set py_arch_names []
+gdb_test_no_output "python all_arch = gdb.architecture_names()"
+gdb_test_no_output "python all_arch.sort()"
+gdb_test_multiple "python print(\"\\n\".join((\"Arch: %s\" % a) for a in all_arch))" "" {
+ -re "python \[^\r\n\]+\r\n" {
+ exp_continue
+ }
+ -re "^Arch: \(\[^\r\n\]+\)\r\n" {
+ set arch $expect_out(1,string)
+ set py_arch_names [lappend py_arch_names $arch]
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ gdb_assert { [llength $py_arch_names] > 0 }
+ }
+}
+
+# Check the two lists of architecture names are the same length, and
+# that the list contents all match.
+gdb_assert { [llength $arch_names] == [llength $py_arch_names] }
+set lists_match true
+foreach a $arch_names b $py_arch_names {
+ if { $a != $b } {
+ set lists_match false
+ verbose -log "Mismatch is architecture list '$a' != '$b'"
+ break
+ }
+}
+gdb_assert { $lists_match }