gdb: parse and set the inferior environment from core files

Extend the core file context parsing mechanism added in the previous
commit to also store the environment parsed from the core file.

This environment can then be injected into the inferior object.

The benefit of this is that when examining a core file in GDB, the
'show environment' command will now show the environment extracted
from a core file.

Consider this example:

  $ env -i GDB_TEST_VAR=FOO ./gen-core
  Segmentation fault (core dumped)
  $ gdb -c ./core.1669829
  ...
  [New LWP 1669829]
  Core was generated by `./gen-core'.
  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0x0000000000401111 in ?? ()
  (gdb) show environment
  GDB_TEST_VAR=foo
  (gdb)

There's a new test for this functionality.
This commit is contained in:
Andrew Burgess
2024-06-08 11:06:02 +01:00
parent d3d13bf876
commit 6004567165
5 changed files with 106 additions and 5 deletions

View File

@@ -1499,6 +1499,32 @@ gdbarch_initialized_p (gdbarch *arch)
return arch->initialized_p;
}
/* See arch-utils.h. */
gdb_environ
core_file_exec_context::environment () const
{
gdb_environ e;
for (const auto &entry : m_environment)
{
char *eq = strchr (entry.get (), '=');
/* If there's no '=' character, then skip this entry. */
if (eq == nullptr)
continue;
const char *value = eq + 1;
const char *var = entry.get ();
*eq = '\0';
e.set (var, value);
*eq = '=';
}
return e;
}
void _initialize_gdbarch_utils ();
void
_initialize_gdbarch_utils ()