This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Multi-process + multi-arch: GDB

On Thu, Nov 8, 2012 at 5:51 PM, Pedro Alves <> wrote:
> This patch was part of a series I had posted back in
> <>.  I've
> been distracted from that work since then, but since questions similar
> or related to "how can we have more than one gdbarch" showed up on the
> python architecture thread, I remembered I could push this part in
> without the rest.  The rest of the series depends on this (and will
> need further porting work, since we have more gdbserver ports in the
> tree now, and at least a couple more pending...), but this can go in
> first and independently.  It fixes the issue for native targets.
> I had a chance of chatting with Ulrich at FOSDEM earlier in the year,
> and he also thought this was a good direction, so I'm putting it in.
> Although GDB currently supports debugging multiple inferiors
> simultaneously, GDB is not prepared to handle the case of debugging
> programs of different architectures (gdbarch's) simultaneously.  A
> simple example is debugging both a 32-bit and a 64-bit program
> simultaneously on x86_64 (think following forks, and 32-bit and/or
> 64-bit children being spawned), though more complicated examples could
> be multi-core setups with processors on the same target (e.g.,
> x86_64 + ARM isn't uncommon these days).
> E.g., loading both a 64-bit inferior and a 32-bit inferior into GDB
> shows (from the test in the patch):
>  (gdb) file test64
>  Reading symbols from test64...done.
>  (gdb) delete breakpoints
>  (gdb) break main
>  Breakpoint 1 at 0x40053a: file main.c, line 40.
>  (gdb) run
>  Starting program: test64
>  Breakpoint 1, main () at main.c:40
>  40        bar();
>  (gdb) add-inferior
>  Added inferior 2
>  inferior 2
>  [Switching to inferior 2 [<null>] (<noexec>)]
>  (gdb) file test32
>  warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  Architecture of file not recognized.
> The "Architecture of file not recognized" warning is misleading.  The
> real issue is that target_gdbarch and the target description are
> globals.  So instead of fetching the target description for the 32-bit
> process that was created for the `test32' program, the target
> description that was previously fetched for inferior 1 (64-bit) is
> assumed, and then things (rightfully) break, as it doesn't really
> match inferior 2.
> This patch makes target_gdbarch (and the associated description) be
> per-inferior instead.
> The new test fails without the rest of the patch.
> I've made the adjustment Yao pointed out in the old thread.
> (Re)tested on x86_64 Fedora 17, and checked in.
> gdb/
> 2012-11-09  Pedro Alves  <>
>         * (target_gdbarch) <gdbarch.h>: Reimplement as macro.
>         (get_target_gdbarch) <gdbarch.h>: New function.
>         (startup_gdbarch) <gdbarch.h>: Declare.
>         <gdbarch.c> (target_gdbarch): Delete.
>         <gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the
>         current inferior's gdbarch.
>         <gdbarch.c> (get_target_gdbarch): New function.
>         * inferior.c: Include target-descriptions.h.
>         (free_inferior): Free target description info.
>         (add_inferior_with_spaces): Set the inferior's initial
>         architecture.
>         (clone_inferior_command): Copy the original inferior's target
>         description if it was user specified.
>         (initialize_inferiors): Add comment.
>         * inferior.h (struct target_desc_info): Forward declare.
>         (struct inferior) <gdbarch>: New field.
>         * linux-nat.c: Include target-descriptions.h.
>         (linux_child_follow_fork): Copy the parent's architecture and
>         target description to the child.
>         * target-descriptions.c: Include inferior.h.
>         (struct target_desc_info): New structure, holding the equivalents
>         of ...
>         (target_desc_fetched, current_target_desc)
>         (target_description_filename): ... these removed globals.
>         (get_tdesc_info, target_desc_info_from_user_p)
>         (copy_inferior_target_desc_info, target_desc_info_free): New.
>         (target_desc_fetched, current_target_desc)
>         (target_description_filename): Reimplemented as convenience
>         macros.
>         (tdesc_filename_cmd_string): New global.
>         (set_tdesc_filename_cmd): Copy the string manipulated by the "set
>         tdescs filename ..." commands to the per-inferior equivalent.
>         (show_tdesc_filename_cmd): Get the value to show from the
>         per-inferior description filename.
>         (_initilize_target_descriptions): Change the "set/show tdesc
>         filename" commands' variable.
>         * target-descriptions.h (struct target_desc, struct target_desc_info)
>         (struct inferior): Forward declare.
>         (target_find_description, target_clear_description)
>         (target_current_description): Adjust comments.
>         (copy_inferior_target_desc_info, target_desc_info_free)
>         (target_desc_info_from_user_p). Declare.

Does it fix


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]