aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-corefile.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-10-08 11:18:07 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-10-08 13:29:06 +0100
commitc97e57bc9d2e081b7c842742933b7262f1d7ce39 (patch)
tree91c331a6bc008f52b46ab3bd60228a7cafe3c724 /gdb/python/py-corefile.c
parent94861aa1c05d18f9d870cf4ed6782877b796ec7c (diff)
downloadbinutils-c97e57bc9d2e081b7c842742933b7262f1d7ce39.zip
binutils-c97e57bc9d2e081b7c842742933b7262f1d7ce39.tar.gz
binutils-c97e57bc9d2e081b7c842742933b7262f1d7ce39.tar.bz2
gdb: move core file bfd from program_space into core_target
This commit moves the 'gdb_bfd_ref_ptr cbfd' out of program_space and into core_target, where it is now called m_core_bfd. I believe this change makes sense as the core_target instance holds additional information that is parsed from the core file BFD, and so storing the parsed information separately from the BFD doesn't make much sense to me. To minimise the churn in this commit, I have retained the program_space::core_bfd member function as a temporary hack. This function forwards the request to the new function get_inferior_core_bfd. This works fine for now as program_space::core_bfd is, after this commit, only called on the current_program_space. If this all seems like a total hack, then it is, but don't worry too much, the next commit will clean this all up. I was tempted to make the new function get_inferior_core_bfd, a member function of the inferior class, inferior::core_bfd. In fact, that would have been my preferred change. However, the new function needs visibility of the core_target class, which, right now is private within the corelow.c file. This shouldn't be a problem, we could just declare the member function in inferior.h, and implement the function in corelow.c. But this would mean the implementation of inferior::core_bfd, would not live in inferior.c. Previously when I've implemented member functions outside their natural home (e.g. an inferior function not in inferior.c) I've received review feedback that this is not desirable. So, for now, I've gone with a free function. I also needed to change get_current_core_target, renaming it to get_core_target, and taking an inferior as an argument. Existing call sites are updated to pass 'current_inferior ()', but get_inferior_core_bfd passes something that might not be the current inferior. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/py-corefile.c')
-rw-r--r--gdb/python/py-corefile.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c
index 7c9a447..97f4242 100644
--- a/gdb/python/py-corefile.c
+++ b/gdb/python/py-corefile.c
@@ -128,9 +128,7 @@ gdbpy_core_file_from_inferior (inferior *inf)
gdb_assert (inf != nullptr);
gdb_assert (inf->pspace != nullptr);
- program_space *pspace = inf->pspace;
-
- if (pspace->core_bfd () == nullptr)
+ if (get_inferior_core_bfd (inf) == nullptr)
return gdbpy_ref<>::new_reference (Py_None);
PyObject *result = (PyObject *) cfpy_inferior_corefile_data_key.get (inf);
@@ -171,9 +169,7 @@ cfpy_corefile_object_is_valid (const corefile_object *obj)
if (obj->inferior == nullptr)
return false;
- gdb_assert (obj->inferior->pspace != nullptr);
-
- return obj->inferior->pspace->core_bfd () != nullptr;
+ return get_inferior_core_bfd (obj->inferior) != nullptr;
}
/* Require that COREFILE_OBJ be a valid core file. A valid core file
@@ -200,7 +196,7 @@ cfpy_get_filename (PyObject *self, void *closure)
/* If the program space's core file had been cleared, then this Corefile
object would have been invalidated. */
- bfd *abfd = obj->inferior->pspace->core_bfd ();
+ bfd *abfd = get_inferior_core_bfd (obj->inferior);
gdb_assert (abfd != nullptr);
return host_string_to_python_string (bfd_get_filename (abfd)).release ();
@@ -247,7 +243,7 @@ cfpy_mapped_files (PyObject *self, PyObject *args)
{
mapped_files
= gdb_read_core_file_mappings (obj->inferior->arch (),
- current_program_space->core_bfd ());
+ get_inferior_core_bfd (obj->inferior));
}
catch (const gdb_exception &except)
{
@@ -376,12 +372,12 @@ cfpy_repr (PyObject *self)
if (!cfpy_corefile_object_is_valid (obj))
return gdb_py_invalid_object_repr (self);
- program_space *pspace = obj->inferior->pspace;
- gdb_assert (pspace != nullptr);
+ bfd *core_bfd = get_inferior_core_bfd (obj->inferior);
+ gdb_assert (core_bfd != nullptr);
return PyUnicode_FromFormat ("<%s inferior=%d filename='%s'>",
Py_TYPE (self)->tp_name,
obj->inferior->num,
- bfd_get_filename (pspace->core_bfd ()));
+ bfd_get_filename (core_bfd));
}