1 /* Generic code for supporting multiple C++ ABI's
2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
30 static struct cp_abi_ops
*find_cp_abi (const char *short_name
);
32 static struct cp_abi_ops current_cp_abi
= { "", NULL
};
33 static struct cp_abi_ops auto_cp_abi
= { "auto", NULL
};
36 static struct cp_abi_ops
*cp_abis
[CP_ABI_MAX
];
37 static int num_cp_abis
= 0;
40 is_constructor_name (const char *name
)
42 if ((current_cp_abi
.is_constructor_name
) == NULL
)
43 error ("ABI doesn't define required function is_constructor_name");
44 return (*current_cp_abi
.is_constructor_name
) (name
);
48 is_destructor_name (const char *name
)
50 if ((current_cp_abi
.is_destructor_name
) == NULL
)
51 error ("ABI doesn't define required function is_destructor_name");
52 return (*current_cp_abi
.is_destructor_name
) (name
);
56 is_vtable_name (const char *name
)
58 if ((current_cp_abi
.is_vtable_name
) == NULL
)
59 error ("ABI doesn't define required function is_vtable_name");
60 return (*current_cp_abi
.is_vtable_name
) (name
);
64 is_operator_name (const char *name
)
66 if ((current_cp_abi
.is_operator_name
) == NULL
)
67 error ("ABI doesn't define required function is_operator_name");
68 return (*current_cp_abi
.is_operator_name
) (name
);
72 baseclass_offset (struct type
*type
, int index
, char *valaddr
,
75 if (current_cp_abi
.baseclass_offset
== NULL
)
76 error ("ABI doesn't define required function baseclass_offset");
77 return (*current_cp_abi
.baseclass_offset
) (type
, index
, valaddr
, address
);
81 value_virtual_fn_field (struct value
**arg1p
, struct fn_field
*f
, int j
,
82 struct type
*type
, int offset
)
84 if ((current_cp_abi
.virtual_fn_field
) == NULL
)
86 return (*current_cp_abi
.virtual_fn_field
) (arg1p
, f
, j
, type
, offset
);
90 value_rtti_type (struct value
*v
, int *full
, int *top
, int *using_enc
)
92 if ((current_cp_abi
.rtti_type
) == NULL
)
94 return (*current_cp_abi
.rtti_type
) (v
, full
, top
, using_enc
);
97 /* Set the current C++ ABI to SHORT_NAME. */
100 switch_to_cp_abi (const char *short_name
)
102 struct cp_abi_ops
*abi
;
104 abi
= find_cp_abi (short_name
);
108 current_cp_abi
= *abi
;
112 /* Add ABI to the list of supported C++ ABI's. */
115 register_cp_abi (struct cp_abi_ops
*abi
)
117 if (num_cp_abis
== CP_ABI_MAX
)
118 internal_error (__FILE__
, __LINE__
,
119 "Too many C++ ABIs, please increase CP_ABI_MAX in cp-abi.c");
121 cp_abis
[num_cp_abis
++] = abi
;
126 /* Set the ABI to use in "auto" mode to SHORT_NAME. */
129 set_cp_abi_as_auto_default (const char *short_name
)
131 char *new_longname
, *new_doc
;
132 struct cp_abi_ops
*abi
= find_cp_abi (short_name
);
135 internal_error (__FILE__
, __LINE__
,
136 "Cannot find C++ ABI \"%s\" to set it as auto default.",
139 if (auto_cp_abi
.longname
!= NULL
)
140 xfree ((char *) auto_cp_abi
.longname
);
141 if (auto_cp_abi
.doc
!= NULL
)
142 xfree ((char *) auto_cp_abi
.doc
);
146 auto_cp_abi
.shortname
= "auto";
147 new_longname
= xmalloc (strlen ("currently ") + 1 + strlen (abi
->shortname
)
149 sprintf (new_longname
, "currently \"%s\"", abi
->shortname
);
150 auto_cp_abi
.longname
= new_longname
;
152 new_doc
= xmalloc (strlen ("Automatically selected; currently ")
153 + 1 + strlen (abi
->shortname
) + 1 + 1);
154 sprintf (new_doc
, "Automatically selected; currently \"%s\"", abi
->shortname
);
155 auto_cp_abi
.doc
= new_doc
;
157 /* Since we copy the current ABI into current_cp_abi instead of
158 using a pointer, if auto is currently the default, we need to
160 if (strcmp (current_cp_abi
.shortname
, "auto") == 0)
161 switch_to_cp_abi ("auto");
164 /* Return the ABI operations associated with SHORT_NAME. */
166 static struct cp_abi_ops
*
167 find_cp_abi (const char *short_name
)
171 for (i
= 0; i
< num_cp_abis
; i
++)
172 if (strcmp (cp_abis
[i
]->shortname
, short_name
) == 0)
178 /* Display the list of registered C++ ABIs. */
181 list_cp_abis (int from_tty
)
183 struct cleanup
*cleanup_chain
;
185 ui_out_text (uiout
, "The available C++ ABIs are:\n");
187 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "cp-abi-list");
188 for (i
= 0; i
< num_cp_abis
; i
++)
193 ui_out_text (uiout
, " ");
194 ui_out_field_string (uiout
, "cp-abi", cp_abis
[i
]->shortname
);
196 padcount
= 16 - 2 - strlen (cp_abis
[i
]->shortname
);
199 pad
[--padcount
] = ' ';
200 ui_out_text (uiout
, pad
);
202 ui_out_field_string (uiout
, "doc", cp_abis
[i
]->doc
);
203 ui_out_text (uiout
, "\n");
205 do_cleanups (cleanup_chain
);
208 /* Set the current C++ ABI, or display the list of options if no
209 argument is given. */
212 set_cp_abi_cmd (char *args
, int from_tty
)
216 list_cp_abis (from_tty
);
220 if (!switch_to_cp_abi (args
))
221 error ("Could not find \"%s\" in ABI list", args
);
224 /* Show the currently selected C++ ABI. */
227 show_cp_abi_cmd (char *args
, int from_tty
)
229 ui_out_text (uiout
, "The currently selected C++ ABI is \"");
231 ui_out_field_string (uiout
, "cp-abi", current_cp_abi
.shortname
);
232 ui_out_text (uiout
, "\" (");
233 ui_out_field_string (uiout
, "longname", current_cp_abi
.longname
);
234 ui_out_text (uiout
, ").\n");
237 extern initialize_file_ftype _initialize_cp_abi
; /* -Wmissing-prototypes */
240 _initialize_cp_abi (void)
242 register_cp_abi (&auto_cp_abi
);
243 switch_to_cp_abi ("auto");
245 add_cmd ("cp-abi", class_obscure
, set_cp_abi_cmd
,
246 "Set the ABI used for inspecting C++ objects.\n"
247 "\"set cp-abi\" with no arguments will list the available ABIs.",
250 add_cmd ("cp-abi", class_obscure
, show_cp_abi_cmd
,
251 "Show the ABI used for inspecting C++ objects.", &showlist
);