This is the mail archive of the gdb-patches@sourceware.org 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 v2 6/8] Create xml from target descriptions


Philipp Rudo <prudo@linux.vnet.ibm.com> writes:

> Same for tdesc_type::make_gdb_type (patch #5).  But here i would prefer to not
> even declare the method for GDBserver, i.e.
>
> struct tdesc_type
> {
>
>   [...]
>
> #ifndef GDBSERVER
>   virtual type *make_gdb_type (struct gdbarch *gdbarch) const = 0;
> #endif
> };
>
> The problem i see with implementing stubs calling error is that you cannot find
> out you made a mistake until you call the function during run-time.  This gives
> room to nasty bugs which could easily be prevented when there is a compile bug.


make_gdb_type and gdbarch shouldn't be put into arch/tdesc.h at all, if
possible.  You can create an sub-class of tdesc_element_visitor in gdb
side, and create the gdb type by visiting these elements, like this,

class gdb_type_creator : public tdesc_element_visitor
{
public:
  gdb_type_createor (struct gdbarch *gdbarch)
    : m_gdbarch (gdbarch)
  {}

  void visit (const tdesc_type_builtin *e) override
  {
     switch (e->kind)
     {
        case TDESC_TYPE_BOOL:
          m_type = builtin_type (m_gdbarch)->builtin_bool;
          break;
        ....
     };
  }

  void visit (const tdesc_type_vector *e) override
  {
     // do what tdesc_type_vector::make_gdb_type does.
  }

  void visit (const tdesc_type_with_fields *e) override
  {
     // likewise.
  }
  
private:
  // input
  struct * const m_gdbarch;
  // output
  type *m_type;
};

gdb_type_creator gdb_type (gdbarch);

tdesc_type->accept (gdb_type);

gdb_type.m_type is the type we need.

-- 
Yao (齐尧)


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