mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-29 02:20:51 +00:00
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:
@@ -21,6 +21,7 @@
|
||||
#define GDB_ARCH_UTILS_H
|
||||
|
||||
#include "gdbarch.h"
|
||||
#include "gdbsupport/environ.h"
|
||||
|
||||
class frame_info_ptr;
|
||||
struct minimal_symbol;
|
||||
@@ -88,9 +89,11 @@ struct core_file_exec_context
|
||||
found but not ARGV then use the no-argument constructor to create an
|
||||
empty context object. */
|
||||
core_file_exec_context (gdb::unique_xmalloc_ptr<char> exec_name,
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> argv)
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> argv,
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> envp)
|
||||
: m_exec_name (std::move (exec_name)),
|
||||
m_arguments (std::move (argv))
|
||||
m_arguments (std::move (argv)),
|
||||
m_environment (std::move (envp))
|
||||
{
|
||||
gdb_assert (m_exec_name != nullptr);
|
||||
}
|
||||
@@ -115,6 +118,9 @@ struct core_file_exec_context
|
||||
const std::vector<gdb::unique_xmalloc_ptr<char>> &args () const
|
||||
{ return m_arguments; }
|
||||
|
||||
/* Return the environment variables from this context. */
|
||||
gdb_environ environment () const;
|
||||
|
||||
private:
|
||||
|
||||
/* The executable filename as reported in the core file. Can be nullptr
|
||||
@@ -124,6 +130,9 @@ private:
|
||||
/* List of arguments. Doesn't include argv[0] which is the executable
|
||||
name, for this look at m_exec_name field. */
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> m_arguments;
|
||||
|
||||
/* List of environment strings. */
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> m_environment;
|
||||
};
|
||||
|
||||
/* Default implementation of gdbarch_displaced_hw_singlestep. */
|
||||
|
||||
Reference in New Issue
Block a user