Re: [PATCH v2] gdb: add support for handling core dumps on arm-none-eabi

Simon Marchi
2020-10-06T14:29:07Z

On 2020-10-06 8:45 a.m., Luis Machado wrote:
> On 10/6/20 1:32 AM, Paul Mathieu via Gdb-patches wrote:
>> Seems to me like current_inferior()->gdbarch is returning the
>> arm-linux gdbarch. Maybe this is because the main .elf executable
>> itself is recognized as arm-linux? I have virtually no control over
>> the executable image, so I would not be able to insert the same kind
>> of note section as I would for a core file to differentiate it from
>> arm-linux executables.
>
> I think there may be enough hints here and there to be able to tell
> those apart via an heuristic. Isn't there a particular note section or
> flag that you can fetch and tell it is not a Linux executable but a
> bare-metal one?

Just so we are on the same page as to why this is happening, can you try
to step into function "gdbarch_info_fill" while you're executable is
loaded?

What I think is happening is that gdbarch_lookup_osabi returns
GDB_OSABI_UNKNOWN, because no sniffer identified it.

So the default osabi of your build gets used instead:

/* From the configured default. */
#ifdef GDB_OSABI_DEFAULT
if (info->osabi == GDB_OSABI_UNKNOWN)
info->osabi = GDB_OSABI_DEFAULT;
#endif

So indeed, if there was a sniffer identifying the binary as a "none"
osabi, it would probably work. The problem is, how do you write such a
sniffer? It's easy to check for a Linux binary, you check for the os
abi ELF note. But how do you identify a "none" binary? You would have
to check that's it's not a Linux binary, not FreeBSD binary, not a
Windows binary, etc.

I don't really like the idea of having a "default" osabi that we fall
back on, because it can just silently get it wrong, like in this case.
I think it would make more sense for the fall back to be "none".
Because it's hard to detect a "none" binary, as explained above.

In the mean time, for your testing, you can force the osabi to none by
using "set osabi none" prior to loading anything.

Simon