const char *
ada_main_name ()
{
- static gdb::unique_xmalloc_ptr<char> main_program_name;
-
/* For Ada, the name of the main procedure is stored in a specific
string constant, generated by the binder. Look for that symbol,
extract its address, and then read that string. If we didn't find
= lookup_minimal_symbol (current_program_space,
ADA_MAIN_PROGRAM_SYMBOL_NAME);
- if (msym.minsym != NULL)
+ if (msym.minsym != nullptr)
{
+ static gdb_byte main_program_name[1024];
+
CORE_ADDR main_program_name_addr = msym.value_address ();
if (main_program_name_addr == 0)
error (_("Invalid address for Ada main program name."));
- /* Force trust_readonly, because we always want to fetch this
- string from the executable, not from inferior memory. If the
- user changes the exec-file and invokes "start", we want to
- pick the "main" from the new executable, not one that may
- come from the still-live inferior. */
- scoped_restore save_trust_readonly
- = make_scoped_restore (&trust_readonly, true);
- main_program_name = target_read_string (main_program_name_addr, 1024);
- return main_program_name.get ();
+ /* We always want to fetch this string from the executable, not
+ from inferior memory. If the user changes the exec-file and
+ invokes "start", we want to pick the "main" from the new
+ executable, not one that may come from the still-live
+ inferior. */
+ ULONGEST xferred = 0;
+ const auto §ions = current_program_space->target_sections ();
+ if ((section_table_xfer_memory_partial (main_program_name, nullptr,
+ main_program_name_addr,
+ sizeof (main_program_name),
+ &xferred,
+ sections)
+ == TARGET_XFER_OK)
+ && xferred > 0
+ && (strnlen ((char *) main_program_name, sizeof (main_program_name))
+ < sizeof (main_program_name)))
+ return (char *) main_program_name;
}
/* The main procedure doesn't seem to be in Ada. */