From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yZf4AdIoLGpxZQMAWB0awg (envelope-from ) for ; Fri, 12 Jun 2026 11:42:10 -0400 Received: by simark.ca (Postfix, from userid 112) id 03C401E070; Fri, 12 Jun 2026 11:42:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 439AC1E070 for ; Fri, 12 Jun 2026 11:42:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E9B04B99F40 for ; Fri, 12 Jun 2026 15:42:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E9B04B99F40 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id 955774BA9011 for ; Fri, 12 Jun 2026 15:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 955774BA9011 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 955774BA9011 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781278902; cv=none; b=wKoS7Wle6naXb1ZytIGA+LhAeU13NzbL9Oq3qKSIEzisIiR3tteX5ZNVU9LiYglTfx5AwIc2FdQn5Q27fPLsfW9xB9jOxLRlJ6GJ/vgXbJyX3f0PwnoRxyEOPc00LhyuXrkE86qLbqI3inLCJolTV8Ksk/tfFTRQ8r9zIqOlJsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781278902; c=relaxed/simple; bh=GM34oyFQp11up0wMUxo54fgTAPzx+J0f0nGDmKKey2c=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=uMhWhDKrzC1e82un7RDNKp7CMOdg545D06ZycPhsXnWukOhA6Fmq1NLBWqvuh1qtSC7s8eo0dbcRL/UasGGAinAN8ovahXRbac2N4S/BKW2y7h64rrINnokg1yDPGXUpyXRWU8lOCGJcTREPJa7XVYHbHZS+dk30Y1R+mkYBx9Y= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 955774BA9011 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-490a76757e5so8758025e9.2 for ; Fri, 12 Jun 2026 08:41:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781278901; x=1781883701; h=content-transfer-encoding:in-reply-to:content-language:from :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g1IB6Hj3Q9pnyoVX8IP+sIqBc1yOyYdiTy9v4tH1psY=; b=HkcGYsrG+DIU168exOhoDymdaLrcfAwRgeT89MsRdXZffnx9zbAPYxgAqPbRci2nEi YEvU5b0Y427laXc8TfinzvOi+EO1PwpeWiRrsKzLUQqrdrKNWjA/Xhu2jySqxOyXPwyr Zy9QwV3Gru4wGfkAfcjfq/JDcRAA2WzFzOt7lYYEc/aseLftLfEA6JEf9obd/FXq48lS ZGuA9ksfaOEx9sbltFgeaTrofrXiqCzgMByAdyfXuhmOXEsxpfwNa2DspS3BkQxer8PG RIeSA6n3KXngEdBBmF9uaVPHwpk2REl1cfBTTMXp0bOYeItvA12f2V3pzJt1cD+TlT9w N4nA== X-Forwarded-Encrypted: i=1; AFNElJ8Jr0RGwV+S2rQMT7ouEHl3Bcf/10RfYcjXK+Uc9Htw6huVYLL1zm5bIl3kItVnPdfutFiKnt6AN+xlvA==@sourceware.org X-Gm-Message-State: AOJu0Yz+TzJo0KEnJB2Mabx//2DVgkagb8NtNbpy7ATU+dazYlQEjB8E 8TfMbbfSrRuBLHsgMBl0iSAymMaaeHJ+XrejL3g8HQdTOd9YYdiiRNTQ X-Gm-Gg: Acq92OEyD0oRYswRfag5gQN1NgHllYf07Yp1Y7erPa6V3P2AiGzwJvdftfptEgwX93w M/g48Ue4laOw0rXnfZyM5boLknvmjt9fFEC0M8iQw7CE5q3cJBQCue7YM35i901r8sihebHQU/U 16lGktwhyLz6vJlE3VITZ5KKcmsI0kohutdNyMpTjqIGNsZocIMMn9itDNrf8/mjE4vLlHJGC3G 78SXm1s03WhncCjt6m2guMRk2VVFtTWf7KNhgviMaEQD6jMWQwTcqlQmRFmuthPvTViaBoyeGWb XIg7Axl/rh/G8q6nZ/G5WGzmXWOEAuPNmTBrJBIf7moCAQJ4NURCQUmr7Mbp8W5k4uNpE57CPNd 8/Q6UDsgiisWdpu6aHqzhHSMqbLLX9TgG6TuaCU6VQWciK4d0a6KNGpO15hfjWhQkExLNJ2tlUR q8yie7dV1G8w/MGxcoKoeeaXaKtqcbE8vIBHAU3ISypWedInbjfVACAPnGvtCgI9EnZw== X-Received: by 2002:a05:600c:83c9:b0:490:e1e6:cb69 with SMTP id 5b1f17b1804b1-4922005167bmr131025e9.7.1781278901020; Fri, 12 Jun 2026 08:41:41 -0700 (PDT) Received: from ?IPV6:2001:8a0:fae3:2600:bf49:e032:9c8d:efc8? ([2001:8a0:fae3:2600:bf49:e032:9c8d:efc8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ea843d6fsm79090105e9.14.2026.06.12.08.41.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jun 2026 08:41:40 -0700 (PDT) Message-ID: Date: Fri, 12 Jun 2026 16:41:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv2 2/3] gdb: introduce program_space::get_entry_point_info function To: Andrew Burgess , gdb-patches@sourceware.org References: <41fe591d58ba010fa771e80ca674b61e30feef2f.1780942441.git.aburgess@redhat.com> <864cefb52d208dd8aac6b1b5f452cadad7546af8.1781214731.git.aburgess@redhat.com> From: Pedro Alves Content-Language: en-US In-Reply-To: <864cefb52d208dd8aac6b1b5f452cadad7546af8.1781214731.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 2026-06-11 22:59, Andrew Burgess wrote: > > +/* See solib.h. */ > + > +std::optional > +svr4_solib_ops::inferior_entry_point_address () const > +{ > + std::optional interp_name_holder > + = svr4_find_program_interpreter (); > + > + /* No interpreter means this is a static executable. Ask the > + program_space for the entry address within the main executable. */ > + if (!interp_name_holder.has_value ()) > + return m_pspace->exec_entry_point_address_if_available (); > + > + /* If we can find a solib that matches the interpreter name then we can > + use that to find the actual entry address of the inferior. */ > + const solib *interp_solib = nullptr; > + const char *interp_name = (const char *) interp_name_holder->data (); > + for (const solib &so : m_pspace->solibs ()) > + { > + if (svr4_same_name (interp_name, so.original_name.c_str ())) > + { > + interp_solib = &so; > + > + const objfile *objfile = so.objfile; > + if (objfile != nullptr && objfile->per_bfd->ei.entry_point_p) > + { > + const entry_info &ei = objfile->per_bfd->ei; > + return (ei.entry_point > + + objfile->section_offsets[ei.the_bfd_section_index]); > + } > + } > + } > + > + gdb_bfd_ref_ptr tmp_bfd; > + target_ops_up tmp_bfd_target; > + try > + { > + tmp_bfd = solib_bfd_open (interp_name); > + > + /* Failed to open the interpreter BFD. */ > + if (tmp_bfd == nullptr) > + return {}; > + > + tmp_bfd_target = target_bfd_reopen (tmp_bfd); > + } > + catch (const gdb_exception &ex) > + { Swallows Ctrl-C. (I see you're just copying this from elsewhere.) > + return {}; > + } > + > + CORE_ADDR entry_addr > + = exec_entry_point (tmp_bfd.get (), tmp_bfd_target.get ()); > + > + /* We found the solib for the interpreter, but we don't have a > + corresponding objfile, or the objfile doesn't have entry point > + information. Maybe symbols haven't been loaded yet? */ > + if (interp_solib != nullptr) > + { > + gdb_assert (interp_solib->objfile == nullptr > + || !interp_solib->objfile->per_bfd->ei.entry_point_p); > + > + CORE_ADDR load_addr > + = this->lm_addr_check (*interp_solib, tmp_bfd.get ()); > + > + return load_addr + entry_addr; > + } > + > + /* We could not find a solib corresponding to the interpreter, this might > + mean that the name didn't match for some reason, or maybe GDB has > + failed to create a solib due to some other issue reading the solib > + list from the inferior. > + > + If we got here we have managed to open the expected interpreter on > + disk though, so we can try using the AT_BASE value. */ > + CORE_ADDR load_addr; > + if (target_auxv_search (AT_BASE, &load_addr) > 0) > + { > + int addr_bit = gdbarch_addr_bit (current_inferior ()->arch ()); > + > + /* Ensure LOAD_ADDR has proper sign in its possible upper bits so > + that `+ load_addr' will overflow CORE_ADDR width not creating > + invalid addresses like 0x101234567 for 32bit inferiors on 64bit > + GDB. */ > + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) > + { > + CORE_ADDR space_size = (CORE_ADDR) 1 << addr_bit; > + > + gdb_assert (load_addr < space_size); > + > + /* ENTRY_ADDR exceeding SPACE_SIZE would be for prelinked > + 64bit ld.so with 32bit executable, it should not happen. */ > + if (entry_addr < space_size > + && entry_addr + load_addr >= space_size) > + load_addr -= space_size; > + } > + > + return load_addr + entry_addr; > + } I wonder whether just looking at AT_BASE, which points at an ELF, and then adding elf_header->e_entr, wouldn't be simpler than all of this. We already use Elf32_External/Elf64_External structs in the file, so maybe the manual ELF peeking is OK. Alternatively, of lot of that code looks similar to enable_break. Maybe it could be refactored to be shared. Or enable_break could cache the entry address. > +# Use 'readelf' to extract the entry point address from TESTFILE. > +proc get_exec_entry_address { testfile } { > + set readelf_program [gdb_find_readelf] > + set command "exec $readelf_program -Wh [standard_output_file $testfile]" If you use "objdump -f" instead, this has a better chance of working on Windows PE/COFF too (eventually): $ objdump.exe -f ./foo.exe ./foo.exe: file format pei-x86-64 architecture: i386:x86-64, flags 0x0000013b: HAS_RELOC, EXEC_P, HAS_DEBUG, HAS_SYMS, HAS_LOCALS, D_PAGED start address 0x00000001400013f0 > +# Start TESTFILE using 'starti'. Check if the 'backtrace' command > +# prints any additional frames; we don't expect any. > +# > +# When IS_DYNAMIC is true then TESTFILE is a dynamically linked > +# executable, otherwise TESTFILE is statically linked. > +proc run_test { testfile is_dynamic } { > + clean_restart $testfile > + > + set exe_entry_addr [get_exec_entry_address $testfile] > + > + # The inferior entry address is always unknown before starting the > + # inferior as at the point GDB has no solib_ops, and it is only > + # through that that we figure out the inferior entry address. > + check_maint_info_entry_addr "" $exe_entry_addr \ > + "check 'maint info entry-address' before inferior starts" > + > + # Start inferior with 'starti' and then wait for a prompt. > + gdb_starti_cmd > + gdb_test "" ".*" "prompt after starti" > + > + # Only svr4 targets currently support querying the inferior entry > + # address. > + if {[istarget *-linux*]} { There are more svr4 targets than linux. I think this style of allow-list has a good chance of never getting updated. Deny-lists are better, IMHO. If the test fails on some port, that might trigger someone to add the feature there. > + set pc [get_hexadecimal_valueof "\$pc" "UNKNOWN" \ > + "get current program counter"] > + > + if { !$is_dynamic } { > + # In static binaries, the first address should be the first > + # address in the executable. > + gdb_assert { $pc == $exe_entry_addr } \ > + "stopped at executable entry address" > + } > + > + set inf_entry_addr $pc > + } else { > + set inf_entry_addr "" > + } > + > + check_maint_info_entry_addr $inf_entry_addr $exe_entry_addr \ > + "check 'maint info entry-address' after starti" > + > + # Allow backtrace past the entry frame, count how many frames GDB > + # finds. If on this target there are no additional frames then > + # the following test isn't going to tell us much, so skip it. > + gdb_test_no_output "set backtrace past-entry on" > + set frame_count 0 > + gdb_test_multiple "bt" "count possible frames" { > + -re "^#($::decimal)\\s+\[^\r\n\]+\r\n" { > + incr frame_count > + exp_continue > + } > + -re "^$::gdb_prompt $" { > + if { $frame_count > 1 } { > + pass $gdb_test_name > + } else { > + unsupported "$gdb_test_name (insufficient frames)" > + return > + } > + } > + -re "^\[^\r\n\]*\r\n" { > + exp_continue > + } This looks like could use -lbl.