From: Tom Tromey Date: Wed, 29 Jul 2026 18:40:03 +0000 (-0600) Subject: Always fetch Ada "main" name from the executable X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8eafbbc74748e499ec785f78858687bd7ea79005;p=thirdparty%2Fbinutils-gdb.git Always fetch Ada "main" name from the executable The gdb.ada/file-then-restart.exp test was failing with gnat-llvm. I tracked this down to the "main" name not being stored in a readonly section, meaning that the code in ada_main_name using trust_readonly did not work. However, it seems to me that gdb should always prefer the data from the executable in this particular case. So, rather than relying on trust_readonly, this patch changes gdb to do this directly. Approved-By: Pedro Alves --- diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3c6c9af488f..906c5cd3465 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -775,8 +775,6 @@ ada_get_decoded_type (struct type *type) const char * ada_main_name () { - static gdb::unique_xmalloc_ptr 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 @@ -786,21 +784,31 @@ ada_main_name () = 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. */