[PATCH v3 1/1] gdb: abort start command if there is no symbol for 'main_name ()'
Luis Machado
luis.machado@arm.com
Mon Dec 16 16:33:08 GMT 2024
On 12/13/24 07:39, Rohr, Stephan wrote:
> Hi Luis,
>
> thanks for the hint, the patch indeed causes a regression if symbols are stripped.
No worries.
>
> What about changing to:
>
> struct symbol *sym
> = lookup_symbol_search_name (main_name (), nullptr,
> SEARCH_FUNCTION_DOMAIN).symbol;
>
> if (sym == nullptr && !have_minimal_symbols (current_program_space))
> error (_("No symbol table loaded. Use the \"file\" command."));
>
> This fixes the Windows issue I originally observed. Also, Ada doesn't regress
> anymore.
I think it might work, though it skips the minimal symbols check whenever we return
a non-null sym. I'll defer to Tromey to confirm this is enough for Ada to work
correctly.
>
> Thanks
> Stephan
>
>> -----Original Message-----
>> From: Luis Machado <luis.machado@arm.com>
>> Sent: Wednesday, 11 December 2024 10:25
>> To: Rohr, Stephan <stephan.rohr@intel.com>; gdb-patches@sourceware.org
>> Cc: guinevere@redhat.com; eliz@gnu.org; Tom Tromey <tom@tromey.com>
>> Subject: Re: [PATCH v3 1/1] gdb: abort start command if there is no symbol for
>> 'main_name ()'
>>
>> On 12/11/24 08:41, Stephan Rohr wrote:
>>> From: "Rohr, Stephan" <stephan.rohr@intel.com>
>>>
>>> GDB aborts the 'start' command if the minimal symbols cannot be
>>> resolved. On Windows, GDB reads the minimal symbols from the COFF
>>> header of the PE file. The symbol table is deprecated and the
>>> number of symbols in the COFF header may be zero [1]. For example,
>>> the LLVM clang compiler for Windows MSVC can be instructed to generate
>>> DWARF:
>>>
>>> clang++ -g -O0 -gdwarf -fuse-ld=lld test.cpp -o test_clang
>>>
>>> The corresponding COFF file header shows:
>>>
>>> FILE HEADER VALUES
>>> 8664 machine (x64)
>>> E number of sections
>>> 66E889EC time date stamp Mon Sep 16 21:41:32 2024
>>> FB400 file pointer to symbol table
>>> 0 number of symbols
>>> F0 size of optional header
>>> 22 characteristics
>>>
>>> GDB is not able to read the minimal symbols; the `start' command fails
>>> with an error:
>>>
>>> (gdb) start
>>> No symbol table loaded. Use the "file" command.
>>>
>>> Manually inserting a breakpoint in main works fine:
>>>
>>> (gdb) tbreak main
>>> Temporary breakpoint 1 at 0x14000100c: file test.cpp, line 6.
>>> (gdb) run
>>> Starting program: C:\test-clang
>>>
>>> Temporary breakpoint 1, main () at test.cpp:6
>>> 6 std::cout << "Hello World.\n";
>>>
>>> Fix this by testing if a symbol for `main' is available instead of checking
>>> the minimal symbol table:
>>>
>>> (gdb) start
>>> Temporary breakpoint 1 at 0x14000100c: file test.cpp, line 6.
>>> Starting program: C:\test-clang
>>>
>>> Temporary breakpoint 1, main () at test.cpp:6
>>> 6 std::cout << "Hello World.\n";
>>> (gdb)
>>>
>>> [1]: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
>>>
>>> Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
>>> ---
>>> gdb/infcmd.c | 10 ++++++----
>>> 1 file changed, 6 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
>>> index 5c0e3f51162..3c9d6aff9a4 100644
>>> --- a/gdb/infcmd.c
>>> +++ b/gdb/infcmd.c
>>> @@ -516,10 +516,12 @@ run_command (const char *args, int from_tty)
>>> static void
>>> start_command (const char *args, int from_tty)
>>> {
>>> - /* Some languages such as Ada need to search inside the program
>>> - minimal symbols for the location where to put the temporary
>>> - breakpoint before starting. */
>>> - if (!have_minimal_symbols (current_program_space))
>>> + /* Abort the start command if 'main' cannot be resolved. */
>>> + struct symbol *sym
>>> + = lookup_symbol_search_name (main_name (), nullptr,
>>> + SEARCH_FUNCTION_DOMAIN).symbol;
>>> +
>>> + if (sym == nullptr)
>>> error (_("No symbol table loaded. Use the \"file\" command."));
>>>
>>> /* Run the program until reaching the main procedure... */
>>
>> Tom Tromey (cc-ed) could confirm this, but this may regress Ada
>> debugging for the case where we don't have debug info available. My
>> understanding is that minimal symbols come from the ELF file, and
>> lookup_symbol_search_name with those parameters may not dive into
>> minimal symbols and so won't find what it is looking for.
>>
>> A test for this is trying to start a Ada program with debug info and
>> then trying to start one without debug info ("strip -g" the binary).
>>
>> The latter may not work anymore.
>>
>
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de
> Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
More information about the Gdb-patches
mailing list