@@ -188,7 +188,8 @@ Specify the filename of the core file.")
class core_target final : public process_stratum_target
{
public :
core_target ( ) ;
/* CBFD is the open core file BFD object. */
explicit core_target ( gdb_bfd_ref_ptr cbfd ) ;
const target_info & info ( ) const override
{ return core_target_info ; }
@@ -280,6 +281,9 @@ public:
return m_expected_exec_filename ;
}
bfd * core_bfd ( ) const
{ return m_core_bfd . get ( ) ; }
private : /* per-core data */
/* Get rid of the core inferior. */
@@ -319,13 +323,46 @@ private: /* per-core data */
when processing the memory - mapped file information . This will only
be set if we find a mapped with a suitable build - id . */
std : : string m_expected_exec_filename ;
/* The core file BFD object. */
gdb_bfd_ref_ptr m_core_bfd ;
} ;
core_ target: : core_target ( )
/* If INF is connected to a core target, then return a pointer to the
core_target . If not connected to a core target , return NULL . */
static core_target *
get_core_target ( inferior * inf )
{
target_ops * proc_target = inf - > process_target ( ) ;
return dynamic_cast < core_target * > ( proc_target ) ;
}
/* See gdbcore.h. */
bfd *
get_inferior_core_bfd ( inferior * inf )
{
gdb_assert ( inf ! = nullptr ) ;
core_target * targ = get_core_target ( inf ) ;
if ( targ = = nullptr )
return nullptr ;
bfd * cbfd = targ - > core_bfd ( ) ;
gdb_assert ( cbfd ! = nullptr ) ;
return cbfd ;
}
/* See class declaration above. */
core_target : : core_target ( gdb_bfd_ref_ptr cbfd_ref )
: m_core_bfd ( std : : move ( cbfd_ref ) )
{
/* Find a first arch based on the BFD. We need the initial gdbarch so
we can setup the hooks to find a target description . */
m_core_gdbarch = gdbarch_from_bfd ( current_program_space - > core_bfd ( ) ) ;
m_core_gdbarch = gdbarch_from_bfd ( this - > core_bfd ( ) ) ;
/* If the arch is able to read a target description from the core, it
could yield a more specific gdbarch . */
@@ -334,7 +371,7 @@ core_target::core_target ()
if ( tdesc ! = nullptr )
{
struct gdbarch_info info ;
info . abfd = current_program_space - > core_bfd ( ) ;
info . abfd = this - > core_bfd ( ) ;
info . target_desc = tdesc ;
m_core_gdbarch = gdbarch_find_by_info ( info ) ;
}
@@ -342,10 +379,10 @@ core_target::core_target ()
if ( ! m_core_gdbarch
| | ! gdbarch_iterate_over_regset_sections_p ( m_core_gdbarch ) )
error ( _ ( " \" %s \" : Core file format not supported " ) ,
bfd_get_filename ( current_program_space - > core_bfd ( ) ) ) ;
bfd_get_filename ( this - > core_bfd ( ) ) ) ;
/* Find the data section */
m_core_section_table = build_section_table ( current_program_space - > core_bfd ( ) ) ;
m_core_section_table = build_section_table ( this - > core_bfd ( ) ) ;
build_file_mappings ( ) ;
}
@@ -371,8 +408,7 @@ core_target::build_file_mappings ()
/* All files mapped into the core file. The key is the filename. */
std : : vector < core_mapped_file > mapped_files
= gdb_read_core_file_mappings ( m_core_gdbarch ,
current_program_space - > core_bfd ( ) ) ;
= gdb_read_core_file_mappings ( m_core_gdbarch , this - > core_bfd ( ) ) ;
for ( const core_mapped_file & file_data : mapped_files )
{
@@ -532,8 +568,7 @@ core_target::build_file_mappings ()
/* Ensure that the bfd will be closed when core_bfd is closed.
This can be checked before / after a core file detach via " maint
info bfds " . */
gdb_bfd_record_inclusion ( current_program_space - > core_bfd ( ) ,
abfd . get ( ) ) ;
gdb_bfd_record_inclusion ( this - > core_bfd ( ) , abfd . get ( ) ) ;
/* Create sections for each mapped region. */
for ( const core_mapped_file : : region & region : file_data . regions )
@@ -587,7 +622,7 @@ core_target::build_file_mappings ()
void
core_target : : clear_core ( )
{
if ( current_program_space - > core_bfd ( ) ! = nullptr )
if ( this - > core_bfd ( ) ! = nullptr )
{
switch_to_no_thread ( ) ; /* Avoid confusion from thread
stuff . */
@@ -597,7 +632,7 @@ core_target::clear_core ()
comments in clear_solib in solib . c . */
clear_solib ( current_program_space ) ;
current_program_space - > c bfd. reset ( nullptr ) ;
m_core_ bfd. reset ( nullptr ) ;
/* Notify that the core file has changed. */
gdb : : observers : : core_file_changed . notify ( current_inferior ( ) ) ;
@@ -661,10 +696,10 @@ core_file_command (const char *filename, int from_tty)
if ( filename = = NULL )
{
if ( current_program_space - > core_bfd ( ) ! = nullptr )
if ( get_core_target ( current_inferior ( ) ) ! = nullptr )
{
target_detach ( current_inferior ( ) , from_tty ) ;
gdb_assert ( current_program_space - > core_bfd ( ) = = nullptr ) ;
gdb_assert ( get_core_target ( current_inferior ( ) ) = = nullptr ) ;
}
else
maybe_say_no_core_file_now ( from_tty ) ;
@@ -1015,9 +1050,7 @@ core_target_open (const char *arg, int from_tty)
filename . c_str ( ) , bfd_errmsg ( bfd_get_error ( ) ) ) ;
}
current_program_space - > cbfd = std : : move ( temp_bfd ) ;
core_target * target = new core_target ( ) ;
core_target * target = new core_target ( std : : move ( temp_bfd ) ) ;
/* Own the target until it is successfully pushed. */
target_ops_up target_holder ( target ) ;
@@ -1039,7 +1072,7 @@ core_target_open (const char *arg, int from_tty)
/* Find (or fake) the pid for the process in this core file, and
initialise the current inferior with that pid . */
bool fake_pid_p = false ;
int pid = bfd_core_file_pid ( current_program_space - > core_bfd ( ) ) ;
int pid = bfd_core_file_pid ( target - > core_bfd ( ) ) ;
if ( pid = = 0 )
{
fake_pid_p = true ;
@@ -1052,14 +1085,14 @@ core_target_open (const char *arg, int from_tty)
inf - > fake_pid_p = fake_pid_p ;
/* Rename any .reg/0 sections, giving them each a fake lwpid. */
rename_vmcore_idle_reg_sections ( current_program_space - > core_bfd ( ) , inf ) ;
rename_vmcore_idle_reg_sections ( target - > core_bfd ( ) , inf ) ;
/* Build up thread list from BFD sections, and possibly set the
current thread to the . reg / NN section matching the . reg
section . */
asection * reg_sect
= bfd_get_section_by_name ( current_program_space - > core_bfd ( ) , " .reg " ) ;
for ( asection * sect : gdb_bfd_sections ( current_program_space - > core_bfd ( ) ) )
= bfd_get_section_by_name ( target - > core_bfd ( ) , " .reg " ) ;
for ( asection * sect : gdb_bfd_sections ( target - > core_bfd ( ) ) )
add_to_thread_list ( sect , reg_sect , inf ) ;
if ( inferior_ptid = = null_ptid )
@@ -1089,20 +1122,20 @@ core_target_open (const char *arg, int from_tty)
the core file . */
core_file_exec_context ctx
= gdbarch_core_parse_exec_context ( target - > core_gdbarch ( ) ,
current_program_space - > core_bfd ( ) ) ;
target - > core_bfd ( ) ) ;
/* If we don't have an executable loaded then see if we can locate one
based on the core file . */
if ( current_program_space - > exec_bfd ( ) = = nullptr )
locate_exec_from_corefile_build_id ( current_program_space - > core_bfd ( ) ,
target , ctx , from_tty) ;
locate_exec_from_corefile_build_id ( target - > core_bfd ( ) , target , ctx ,
from_tty ) ;
/* If we have no exec file, try to set the architecture from the
core file . We don ' t do this unconditionally since an exec file
typically contains more information that helps us determine the
architecture than a core file . */
if ( current_program_space - > exec_bfd ( ) = = nullptr )
set_gdbarch_from_file ( current_program_space - > core_bfd ( ) ) ;
set_gdbarch_from_file ( target - > core_bfd ( ) ) ;
post_create_inferior ( from_tty , true ) ;
@@ -1142,7 +1175,7 @@ core_target_open (const char *arg, int from_tty)
else
{
const char * failing_command
= bfd_core_file_failing_command ( current_program_space - > core_bfd ( ) ) ;
= bfd_core_file_failing_command ( target - > core_bfd ( ) ) ;
if ( failing_command ! = nullptr )
gdb_printf ( _ ( " Core was generated by `%s'. \n " ) ,
failing_command ) ;
@@ -1151,7 +1184,7 @@ core_target_open (const char *arg, int from_tty)
/* Clearing any previous state of convenience variables. */
clear_exit_convenience_vars ( ) ;
siggy = bfd_core_file_failing_signal ( current_program_space - > core_bfd ( ) ) ;
siggy = bfd_core_file_failing_signal ( target - > core_bfd ( ) ) ;
if ( siggy > 0 )
{
gdbarch * core_gdbarch = target - > core_gdbarch ( ) ;
@@ -1257,8 +1290,7 @@ core_target::get_core_register_section (struct regcache *regcache,
thread_section_name section_name ( name , regcache - > ptid ( ) ) ;
section = bfd_get_section_by_name ( current_program_space - > core_bfd ( ) ,
section_name . c_str ( ) ) ;
section = bfd_get_section_by_name ( this - > core_bfd ( ) , section_name . c_str ( ) ) ;
if ( ! section )
{
if ( required )
@@ -1281,8 +1313,8 @@ core_target::get_core_register_section (struct regcache *regcache,
}
gdb : : byte_vector contents ( size ) ;
if ( ! bfd_get_section_contents ( current_program_space - > core_bfd ( ) , section ,
contents . data ( ) , ( file_ptr ) 0 , size ) )
if ( ! bfd_get_section_contents ( this - > core_bfd ( ) , section , contents . data ( ) ,
( file_ptr ) 0 , size ) )
{
warning ( _ ( " Couldn't read %s registers from `%s' section in core file. " ) ,
human_name , section_name . c_str ( ) ) ;
@@ -1365,7 +1397,7 @@ core_target::fetch_registers (struct regcache *regcache, int regno)
void
core_target : : files_info ( )
{
print_section_info ( & m_core_section_table , current_program_space - > core_bfd ( ) ) ;
print_section_info ( & m_core_section_table , this - > core_bfd ( ) ) ;
}
@@ -1485,8 +1517,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
struct bfd_section * section ;
bfd_size_type size ;
section = bfd_get_section_by_name ( current_program_space - > core_bfd ( ) ,
" .auxv " ) ;
section = bfd_get_section_by_name ( this - > core_bfd ( ) , " .auxv " ) ;
if ( section = = NULL )
return TARGET_XFER_E_IO ;
@@ -1499,9 +1530,8 @@ core_target::xfer_partial (enum target_object object, const char *annex,
if ( size = = 0 )
return TARGET_XFER_EOF ;
if ( ! bfd_get_section_contents ( current_program_space - > core_bfd ( ) ,
section , readbuf , ( file_ptr ) offset ,
size ) )
if ( ! bfd_get_section_contents ( this - > core_bfd ( ) , section , readbuf ,
( file_ptr ) offset , size ) )
{
warning ( _ ( " Couldn't read NT_AUXV note in core file. " ) ) ;
return TARGET_XFER_E_IO ;
@@ -1522,8 +1552,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
struct bfd_section * section ;
bfd_size_type size ;
section = bfd_get_section_by_name ( current_program_space - > core_bfd ( ) ,
" .wcookie " ) ;
section = bfd_get_section_by_name ( this - > core_bfd ( ) , " .wcookie " ) ;
if ( section = = NULL )
return TARGET_XFER_E_IO ;
@@ -1536,9 +1565,8 @@ core_target::xfer_partial (enum target_object object, const char *annex,
if ( size = = 0 )
return TARGET_XFER_EOF ;
if ( ! bfd_get_section_contents ( current_program_space - > core_bfd ( ) ,
section , readbuf , ( file_ptr ) offset ,
size ) )
if ( ! bfd_get_section_contents ( this - > core_bfd ( ) , section , readbuf ,
( file_ptr ) offset , size ) )
{
warning ( _ ( " Couldn't read StackGhost cookie in core file. " ) ) ;
return TARGET_XFER_E_IO ;
@@ -1559,8 +1587,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
else
{
* xfered_len = gdbarch_core_xfer_shared_libraries
( m_core_gdbarch , * current_program_space - > core_bfd ( ) ,
readbuf , offset , len ) ;
( m_core_gdbarch , * this - > core_bfd ( ) , readbuf , offset , len ) ;
if ( * xfered_len = = 0 )
return TARGET_XFER_EOF ;
@@ -1580,8 +1607,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
{
* xfered_len
= gdbarch_core_xfer_shared_libraries_aix
( m_core_gdbarch , * current_program_space - > core_bfd ( ) ,
readbuf , offset , len ) ;
( m_core_gdbarch , * this - > core_bfd ( ) , readbuf , offset , len ) ;
if ( * xfered_len = = 0 )
return TARGET_XFER_EOF ;
@@ -1597,7 +1623,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
if ( m_core_gdbarch ! = nullptr
& & gdbarch_core_xfer_siginfo_p ( m_core_gdbarch ) )
{
struct bfd * cbfd = current_program_space - > core_bfd ( ) ;
struct bfd * cbfd = this - > core_bfd ( ) ;
gdb_assert ( cbfd ! = nullptr ) ;
LONGEST l = gdbarch_core_xfer_siginfo ( m_core_gdbarch , * cbfd ,
readbuf , offset , len ) ;
@@ -1646,21 +1672,21 @@ core_target::read_description ()
/* First check whether the target wants us to use the corefile target
description notes . */
if ( gdbarch_use_target_description_from_corefile_notes
( m_core_gdbarch , current_program_space - > core_bfd ( ) ) )
( m_core_gdbarch , m_core_bfd . get ( ) ) )
{
/* If the core file contains a target description note then go ahead and
use that . */
bfd_size_type tdesc_note_size = 0 ;
struct bfd_section * tdesc_note_section
= bfd_get_section_by_name ( current_program_space - > core_bfd ( ) , " .gdb-tdesc " ) ;
= bfd_get_section_by_name ( m_core_bfd . get ( ) , " .gdb-tdesc " ) ;
if ( tdesc_note_section ! = nullptr )
tdesc_note_size = bfd_section_size ( tdesc_note_section ) ;
if ( tdesc_note_size > 0 )
{
gdb : : char_vector contents ( tdesc_note_size + 1 ) ;
if ( bfd_get_section_contents ( current_program_space - > core_bfd ( ) ,
tdesc_note_section , contents. data ( ) ,
( file_ptr ) 0 , tdesc_note_size ) )
if ( bfd_get_section_contents ( m_ core_bfd. get ( ) , tdesc_note_section ,
contents . data ( ) , ( file_ptr ) 0 ,
tdesc_note_size ) )
{
/* Ensure we have a null terminator. */
contents [ tdesc_note_size ] = ' \0 ' ;
@@ -1682,8 +1708,8 @@ core_target::read_description ()
{
const struct target_desc * result ;
result = gdbarch_core_read_description
( m_core_gdbarch , this , current_program_space - > core_bfd ( ) ) ;
result = gdbarch_core_read_description ( m_core_gdbarch , this ,
m_core_bfd . get ( ) ) ;
if ( result ! = nullptr )
return result ;
}
@@ -1727,7 +1753,7 @@ core_target::thread_name (struct thread_info *thr)
if ( m_core_gdbarch ! = nullptr
& & gdbarch_core_thread_name_p ( m_core_gdbarch ) )
{
bfd * cbfd = current_program_space - > core_bfd ( ) ;
bfd * cbfd = this - > core_bfd ( ) ;
gdb_assert ( cbfd ! = nullptr ) ;
return gdbarch_core_thread_name ( m_core_gdbarch , * cbfd , thr ) ;
}
@@ -1737,19 +1763,19 @@ core_target::thread_name (struct thread_info *thr)
bool
core_target : : has_memory ( )
{
return current_program_space - > core_bfd ( ) ! = nullptr ;
return this - > core_bfd ( ) ! = nullptr ;
}
bool
core_target : : has_stack ( )
{
return current_program_space - > core_bfd ( ) ! = nullptr ;
return this - > core_bfd ( ) ! = nullptr ;
}
bool
core_target : : has_registers ( )
{
return current_program_space - > core_bfd ( ) ! = nullptr ;
return this - > core_bfd ( ) ! = nullptr ;
}
/* Implement the to_info_proc method. */
@@ -1762,8 +1788,7 @@ core_target::info_proc (const char *args, enum info_proc_what request)
/* Since this is the core file target, call the 'core_info_proc'
method on gdbarch , not ' info_proc ' . */
if ( gdbarch_core_info_proc_p ( gdbarch ) )
gdbarch_core_info_proc ( gdbarch , current_program_space - > core_bfd ( ) ,
args , request ) ;
gdbarch_core_info_proc ( gdbarch , this - > core_bfd ( ) , args , request ) ;
return true ;
}
@@ -1776,8 +1801,7 @@ core_target::supports_memory_tagging ()
/* Look for memory tag sections. If they exist, that means this core file
supports memory tagging . */
return ( bfd_get_section_by_name ( current_program_space - > core_bfd ( ) , " memtag " )
! = nullptr ) ;
return bfd_get_section_by_name ( this - > core_bfd ( ) , " memtag " ) ! = nullptr ;
}
/* Implementation of the "fetch_memtags" target_ops method. */
@@ -1796,8 +1820,8 @@ core_target::fetch_memtags (CORE_ADDR address, size_t len,
memtag_section_info info ;
info . memtag_section = nullptr ;
while ( get_next_core_memtag_section ( current_program_space - > core_bfd ( ) ,
info . memtag_section , address, info ) )
while ( get_next_core_memtag_section ( this - > core_bfd ( ) , info . memtag_section ,
address , info ) )
{
size_t adjusted_length
= ( address + len < info . end_address ) ? len : ( info . end_address - address ) ;
@@ -1838,7 +1862,7 @@ core_target::fetch_x86_xsave_layout ()
gdbarch_core_read_x86_xsave_layout_p ( m_core_gdbarch ) )
{
x86_xsave_layout layout ;
bfd * cbfd = current_program_space - > core_bfd ( ) ;
bfd * cbfd = this - > core_bfd ( ) ;
gdb_assert ( cbfd ! = nullptr ) ;
if ( ! gdbarch_core_read_x86_xsave_layout ( m_core_gdbarch , * cbfd , layout ) )
return { } ;
@@ -1849,16 +1873,6 @@ core_target::fetch_x86_xsave_layout ()
return { } ;
}
/* Get a pointer to the current core target. If not connected to a
core target , return NULL . */
static core_target *
get_current_core_target ( )
{
target_ops * proc_target = current_inferior ( ) - > process_target ( ) ;
return dynamic_cast < core_target * > ( proc_target ) ;
}
/* Display file backed mappings from core file. */
void
@@ -1912,7 +1926,7 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
static void
maintenance_print_core_file_backed_mappings ( const char * args , int from_tty )
{
core_target * targ = get_current_ core_target ( ) ;
core_target * targ = get_core_target ( current_inferior ( ) ) ;
if ( targ ! = nullptr )
targ - > info_proc_mappings ( targ - > core_gdbarch ( ) ) ;
}
@@ -2183,10 +2197,12 @@ std::optional <core_target_mapped_file_info>
core_target_find_mapped_file ( const char * filename ,
std : : optional < CORE_ADDR > addr )
{
core_target * targ = get_current_ core_target ( ) ;
if ( targ = = nullptr | | current_program_space - > cbfd . get ( ) = = nullptr )
core_target * targ = get_core_target ( current_inferior ( ) ) ;
if ( targ = = nullptr )
return { } ;
gdb_assert ( targ - > core_bfd ( ) ! = nullptr ) ;
return targ - > lookup_mapped_file_info ( filename , addr ) ;
}